:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-alt: #fdfcf9;
  --text: #23211c;
  --muted: #78736a;
  --label: #a39c8f;
  --border: #e7e2d8;
  --accent: #34694b;
  --accent-soft: #eef3ec;
  --on-accent: #f6f4ee;
  --danger: #b3402f;
  --radius: 12px;
  --nav-h: 60px;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --surface: #201d19;
    --surface-alt: #1b1916;
    --text: #ece8e0;
    --muted: #a39c8f;
    --label: #857e70;
    --border: #2e2a24;
    --accent: #7db894;
    --accent-soft: #23312a;
    --on-accent: #14211a;
    --danger: #e07a68;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 {
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.15;
  margin: 0 0 .75rem;
}
h2 {
  font-size: .8rem; color: var(--label); font-weight: 600;
  margin: 1.5rem 0 .6rem; text-transform: uppercase; letter-spacing: .09em;
}
.date-line {
  font-size: .8rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px;
}

/* Cabecera de sección con la píldora de hora fija a la derecha */
.h2-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 1.5rem 0 .6rem; }
.h2-row h2 { margin: 0; }
.time-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: .8rem; font-weight: 600; color: var(--muted);
}
.time-pill .icon { width: 14px; height: 14px; }
.time-pill.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.time-pill.active .icon { color: inherit; }

/* Iconos SVG */
svg.icon { width: 20px; height: 20px; flex: none; }
svg.icon.sm { width: 16px; height: 16px; }
svg.icon.lg { width: 26px; height: 26px; }
.icotxt { display: inline-flex; align-items: center; gap: 7px; }
.icotxt .icon { width: 17px; height: 17px; color: var(--accent); }
h1 .icotxt { gap: 10px; }
h1 .icotxt .icon { width: 24px; height: 24px; }
.btn.primary .icon, .big.wide .icon, .chip.selected .icon, .chips > button.selected .icon, .segmented .selected .icon { color: inherit; }
.btn.danger .icon { color: var(--danger); }

#view {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 18px calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

/* Barra inferior */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface-alt);
  border-top: 1px solid var(--border);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--label); font-size: .72rem; font-weight: 500;
}
#nav a svg { width: 22px; height: 22px; }
#nav a.active { color: var(--accent); font-weight: 600; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 48px; padding: 0 1.2rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* Rejilla de registro rápido */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.big {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 90px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 500; font-size: .95rem;
}
.big .ico { display: flex; color: var(--accent); }
.big .ico .icon { width: 26px; height: 26px; }
.big:active { background: var(--accent-soft); }
.big.wide {
  grid-column: 1 / -1; flex-direction: row; min-height: 60px;
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  font-size: 1.02rem; font-weight: 600;
}
.big.wide .ico { color: inherit; }
.big.wide:active { filter: brightness(1.1); }

.today {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 13px 16px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); font-size: .93rem;
}
.today .hoy { font-family: var(--serif); font-style: italic; font-size: 1.05rem; color: var(--accent); }
.today .icotxt { gap: 5px; }
.today .icotxt .icon { width: 16px; height: 16px; }
.today .empty { color: var(--muted); }

/* Chips (complementos recientes, sugerencias) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .chips > button {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 42px; padding: 0 15px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 500;
}
.chip .icon, .chips > button .icon { width: 16px; height: 16px; color: var(--accent); }
.chip.selected, .chips > button.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chip.ghost { border-style: dashed; background: transparent; color: var(--muted); }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .8rem; color: var(--label); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
}
textarea { min-height: 70px; resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1; min-height: 46px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600;
}
.segmented button.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.scale { display: flex; justify-content: space-between; gap: 6px; }
.scale button {
  flex: 1; min-height: 52px; border-radius: 10px; font-size: 1.1rem; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface);
}
.scale button.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.slider-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.slider-row output { min-width: 1.5em; text-align: right; font-weight: 700; }

/* Selector Bristol */
.bristol { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bristol button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); font-size: .8rem; font-weight: 600;
}
.bristol button svg { width: 48px; height: 36px; }
.bristol button.selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.bristol button.selected svg { filter: brightness(1.6); }
.bristol-hint { font-size: .85rem; color: var(--muted); min-height: 1.2em; margin-top: 6px; }

/* Hoja inferior (bottom sheet) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(30, 26, 18, .45);
  display: flex; align-items: flex-end; z-index: 20;
}
.sheet {
  width: 100%; max-width: 520px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }
.sheet-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-title h1 { margin: 0; font-size: 1.5rem; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

/* Historial */
.day { margin-top: 18px; }
.day h2 { margin: 0 0 6px; }
.event {
  display: grid; grid-template-columns: 2.2rem 1fr auto; align-items: center; gap: 10px;
  padding: 11px 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.event .ico { display: flex; justify-content: center; color: var(--accent); }
.event .ico .icon { width: 22px; height: 22px; }
.event .title { font-weight: 600; }
.event .sub { font-size: .85rem; color: var(--muted); }
.event .time { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.event .time .icon { width: 14px; height: 14px; }

.event .thumb-link { grid-column: 1 / -1; justify-self: start; font-size: .9rem; color: var(--accent); }
.event .thumb { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: 8px; }
.photo-preview { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; margin-top: 10px; }

/* Gráficas */
.chart-card { margin: 14px 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.chart-card h3 { font-family: var(--serif); font-size: 1.05rem; font-weight: 500; margin: 0 0 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .tick { font-size: 10px; fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

/* Estado de conexión / sincronización */
.status { margin-top: 10px; font-size: .85rem; color: var(--muted); }
.status div { padding: 6px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 4px; }

/* Lista compacta (check-in) */
.compact { display: flex; gap: 10px; align-items: center; padding: 4px 0; font-size: .95rem; }
.compact .time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3em; }
.compact .icotxt .icon { width: 15px; height: 15px; }

/* Recordatorios */
.reminder {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.reminder .title { font-weight: 600; }
.reminder .title .icon { width: 16px; height: 16px; }
.reminder .sub { font-size: .85rem; color: var(--muted); }
.reminder .btn { min-height: 40px; padding: 0 .8rem; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); }
input[type=time] {
  min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); width: 100%;
}

/* Login */
.login { display: flex; flex-direction: column; justify-content: center; min-height: 70vh; }
.login h1 { font-size: 2.2rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: .95rem;
  z-index: 30; pointer-events: none;
}
