:root {
  --bg: #0B1420;
  --surface: #121F30;
  --surface-2: #17263A;
  --border: #223247;
  --text: #EDEFF2;
  --text-muted: #8B99AC;
  --amber: #E8A33D;
  --amber-dim: rgba(232, 163, 61, 0.16);
  --green: #4CAF7D;
  --green-dim: rgba(76, 175, 125, 0.16);
  --red: #E5584D;
  --red-dim: rgba(229, 88, 77, 0.16);
  --radius: 14px;
  --radius-sm: 9px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(64px + var(--safe-bottom));
}

/* ---------- Header ---------- */
header.top {
  padding: 18px 18px 10px;
}

header.top h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

header.top .sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

/* ---------- Notification banner ---------- */
.notif-banner {
  margin: 10px 18px 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
}

.notif-banner.on { border-color: rgba(76,175,125,0.35); }
.notif-banner.warn { border-color: rgba(229,88,77,0.4); background: var(--red-dim); }
.notif-banner.warn .dot { background: var(--red); }
.notif-banner.warn .msg { color: var(--text); }
.notif-banner .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}
.notif-banner.on .dot { background: var(--green); }
.notif-banner .msg { flex: 1; color: var(--text-muted); }
.notif-banner button {
  background: var(--amber-dim);
  color: var(--amber);
  border: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Views ---------- */
main {
  flex: 1;
  padding: 14px 18px 30px;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- Slot status card ---------- */
.slot-card {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
}

.slot-card .row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.slot-card .label {
  font-weight: 700;
  font-size: 1.02rem;
}

.slot-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: none;
  white-space: nowrap;
}

.slot-pill.wait { background: var(--surface-2); color: var(--text-muted); }
.slot-pill.due { background: var(--amber-dim); color: var(--amber); }
.slot-pill.done { background: var(--green-dim); color: var(--green); }
.slot-pill.missed { background: var(--red-dim); color: var(--red); }

.slot-card .meta {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.slot-switch {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.slot-switch button {
  flex: 1;
  padding: 9px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
}

.slot-switch button.active {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-dim);
}

/* ---------- Form ---------- */
.card {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field input, .field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.field textarea { resize: vertical; min-height: 44px; }

.field input:focus, .field textarea:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.bp-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}
.bp-sep {
  padding-bottom: 12px;
  color: var(--text-muted);
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary { background: var(--amber); color: #1A1200; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-danger { background: var(--red-dim); color: var(--red); }

/* ---------- Reading list within a slot ---------- */
.reading-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.reading-item:first-child { border-top: none; }

.reading-item .bp {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 78px;
}

.reading-item .time {
  color: var(--text-muted);
  font-size: 0.82rem;
  min-width: 44px;
}

.reading-item .extra {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex: 1;
}

.reading-item .cat-dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex: none;
}

.reading-item button.del {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 2px 4px;
}

/* ---------- Overview page ---------- */
.day-group {
  margin-bottom: 18px;
}
.day-group .day-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0 2px 6px;
  text-transform: capitalize;
}

.slot-block {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.slot-block .slot-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--amber);
  margin-bottom: 2px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.92rem;
}

/* ---------- Chart ---------- */
.chart-wrap {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 10px 6px;
  margin-bottom: 16px;
}
.chart-wrap h2 { padding: 0 6px; }
canvas#trendChart { width: 100%; height: 160px; display: block; }
.legend {
  display: flex; gap: 16px; padding: 8px 10px 2px;
  font-size: 0.78rem; color: var(--text-muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

/* ---------- Periods page ---------- */
.period-card {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 14px;
}
.period-card .range {
  font-weight: 700;
  margin-bottom: 8px;
}
.period-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}
.period-stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.period-stat .k { font-size: 0.74rem; color: var(--text-muted); }
.period-stat .v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.period-note {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ---------- Bottom nav ---------- */
nav.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  max-width: 480px;
  margin: 0 auto;
}

nav.tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

nav.tabbar button svg { width: 22px; height: 22px; }
nav.tabbar button.active { color: var(--amber); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
