:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-light: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --success: #22c55e;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
  /* Red de seguridad: pase lo que pase en algún flex-row suelto, la página
     nunca debe poder desplazarse horizontalmente (varias pantallas han
     tenido nombres largos empujando contenido fuera del ancho del móvil). */
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

header {
  padding: 12px 16px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--surface-light);
  flex-shrink: 0;
}
header h1 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
}
header button {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  padding: 4px 8px;
  cursor: pointer;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 88px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  transition: transform .05s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface-light); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #000; }
.btn-sm { padding: 6px 8px; font-size: .85rem; min-height: 36px; width: auto; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--surface-light);
}
.card h3 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0; color: var(--text-muted); font-size: .9rem; }
.card .actions {
  display: flex; gap: 8px; margin-top: 10px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-size: .9rem;
  color: var(--text-muted);
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  background: var(--surface-light);
  border: 1px solid #475569;
  border-radius: 10px;
  padding: 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  box-sizing: border-box;
}
input[type="time"] {
  width: auto;
  min-width: 120px;
  max-width: 100%;
  padding: 10px 12px;
}
input[type="file"] {
  padding: 8px;
  font-size: .9rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }

input.input-fecha { font-variant-numeric: tabular-nums; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.tab {
  flex: 1;
  background: var(--surface-light);
  border: none;
  color: var(--text-muted);
  padding: 10px 6px;
  border-radius: 10px;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab.active { background: var(--accent); color: #fff; }

.item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--surface-light);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.item .icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; margin: 0 0 2px; font-size: .95rem; }
.item .meta { color: var(--text-muted); font-size: .8rem; margin: 0; }
.item .right {
  flex-shrink: 0;
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.check-item {
  align-items: flex-start;
}
.check-item input[type="checkbox"] {
  width: 28px; height: 28px;
  accent-color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}
.check-item.completed .title { text-decoration: line-through; color: var(--text-muted); }

/* Agenda / Día */
.day-card {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid var(--surface-light);
  overflow: hidden;
}
.day-header {
  background: var(--surface-light);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.day-header h4 { margin: 0; font-size: 1rem; }
.day-body { padding: 12px 14px; }

.timeline {
  border-left: 2px solid var(--surface-light);
  margin-left: 8px;
  padding-left: 14px;
}
.timeline-item {
  position: relative;
  margin-bottom: 10px;
  padding-bottom: 6px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline-item .hora { font-size: .8rem; color: var(--text-muted); font-weight: 700; }
.timeline-item .txt { font-size: .95rem; }

.poi-chip {
  display: inline-block;
  background: var(--surface-light);
  border: 1px solid #475569;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .8rem;
  margin: 4px 4px 0 0;
}

.resumen-ia {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .9rem;
  margin-top: 8px;
  color: #e0f2fe;
}

#fab {
  position: fixed;
  bottom: 78px;
  right: 20px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1.8rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(0,0,0,.4);
  cursor: pointer;
  z-index: 10;
}
#fab:active { transform: scale(.95); }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--surface-light);
  display: flex;
  justify-content: space-around;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px);
  z-index: 20;
}
.bottom-nav button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: .7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  cursor: pointer;
}
.bottom-nav button .emoji { font-size: 1.3rem; }
.bottom-nav button.active { color: var(--accent); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal-overlay .modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  animation: slideUp .2s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.qr-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.qr-overlay h2 { color: #fff; margin: 0 0 20px; text-align: center; }
.qr-overlay canvas { max-width: 80vw; height: auto !important; }
.qr-overlay p { color: #aaa; margin-top: 20px; text-align: center; }
.qr-overlay .close-qr {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  background: var(--surface-light);
  color: var(--text-muted);
}
.badge.accent { background: var(--accent); color: #fff; }

.hidden { display: none !important; }

.toolbar {
  display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--surface-light); border-radius: 3px; }
/* Append calendar styles */
.cal-nav { margin-bottom: 4px; }

#tab-content { width: 100%; max-width: 100%; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
}
.cal-header {
  text-align: center;
  font-size: .6rem;
  color: var(--text-muted);
  padding: 4px 0;
  font-weight: 700;
  text-transform: uppercase;
  overflow: hidden;
  white-space: nowrap;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .05s;
  min-width: 0;
  overflow: hidden;
  width: 100%;
  padding: 0;
}
.cal-cell:active { transform: scale(.96); }
.cal-cell.empty { background: transparent; cursor: default; border: none; }
.cal-cell.today { background: var(--accent); color: #fff; }
.cal-cell.has-events { border-color: var(--accent); }
.cal-cell.out-range { opacity: .35; }
.cal-num { font-size: .75rem; font-weight: 600; line-height: 1; }
.cal-dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  bottom: 4px;
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-week-day {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 6px;
  min-height: 90px;
  cursor: pointer;
  border: 1px solid transparent;
}
.cal-week-day:active { transform: scale(.98); }
.cal-week-day.has-events { border-color: var(--accent); }
.cal-week-day .wd-name { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; text-align: center; }
.cal-week-day .wd-num { font-size: 1.1rem; font-weight: 700; text-align: center; margin: 4px 0; }
.cal-week-day .wd-dots { display: flex; justify-content: center; gap: 3px; margin-top: 4px; }
.cal-week-day .wd-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

.cal-year {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cal-year-month {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  border: 1px solid transparent;
}
.cal-year-month:active { transform: scale(.96); }
.cal-year-month.has-events { border-color: var(--accent); }
.cal-year-month .ym-name { font-size: .85rem; font-weight: 700; }
.cal-year-month .ym-count { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }

@media (max-width: 360px) {
  .cal-year { grid-template-columns: repeat(2, 1fr); }
}

/* Fotos */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.foto-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-light);
}
.foto-thumb:active { transform: scale(.97); }
.foto-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.foto-thumb .foto-badge {
  position: absolute;
  bottom: 3px;
  left: 3px;
  right: 3px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: .65rem;
  padding: 2px 5px;
  border-radius: 6px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.foto-empty-day {
  font-size: .8rem;
  color: var(--text-muted);
  padding: 4px 0;
  margin: 4px 0 0;
}

#foto-modal {
  overflow-y: auto;
  padding: 20px 16px;
}
.foto-viewer {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--surface-light);
  border-radius: 16px;
  padding: 16px;
  box-sizing: border-box;
}
.foto-viewer img {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #000;
  display: block;
  margin-bottom: 8px;
}
.foto-viewer-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.foto-viewer-actions .btn { width: auto; flex: 1 1 auto; min-width: 44%; }
