:root {
  color-scheme: light dark;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #172033;
  --muted: #64748b;
  --border: #dbe3ec;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --danger: #b42318;
  --danger-soft: #fff1f2;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
  --radius: 16px;
  --radius-small: 10px;
  --max: 1040px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #111827;
    --surface-2: #182235;
    --text: #f8fafc;
    --muted: #a7b3c5;
    --border: #293548;
    --border-strong: #3a4658;
    --accent: #60a5fa;
    --accent-strong: #93c5fd;
    --accent-soft: #172b4d;
    --success: #4ade80;
    --success-soft: #153322;
    --warning: #fbbf24;
    --warning-soft: #352812;
    --danger: #f87171;
    --danger-soft: #3b1c22;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
.startup-notice { position: fixed; z-index: 10; inset: 0; display: grid; place-content: center; gap: 10px; padding: 28px; background: var(--bg); color: var(--text); text-align: center; }
.startup-notice h2 { max-width: 560px; margin: 0; }
.startup-notice p { max-width: 560px; margin: 0; color: var(--muted); }
.startup-notice code { padding: 1px 4px; border-radius: 4px; background: var(--surface-2); color: var(--text); }
body.app-ready .startup-notice { display: none; }
body:not(.app-ready) .app-shell { pointer-events: none; user-select: none; }
.pin-gate { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 22px; background: var(--bg); }
.pin-gate[hidden] { display: none; }
.pin-card { width: min(100%, 390px); padding: 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.pin-card h2 { margin-bottom: 8px; }
.pin-card .button { width: 100%; margin-top: 8px; }
.pin-error { margin: 8px 0 0; color: var(--danger); font-weight: 700; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 34%, transparent); outline-offset: 2px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1,h2,h3,p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(20px, 4vw, 26px); line-height: 1.2; letter-spacing: -.025em; }
h2 { margin-bottom: 4px; font-size: clamp(24px, 5vw, 32px); line-height: 1.15; letter-spacing: -.03em; }
h3 { margin-bottom: 4px; font-size: 18px; line-height: 1.25; }
small { color: var(--muted); font-size: 12px; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.app-shell { min-height: 100vh; padding-bottom: 88px; }
.topbar { max-width: var(--max); margin: 0 auto; padding: 18px 18px 10px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar-subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.status-text { color: var(--muted); font-size: 13px; }
.main-content { max-width: var(--max); margin: 0 auto; padding: 16px 18px 36px; }
.view { animation: view-in .16s ease-out; }
@keyframes view-in { from { opacity: .65; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 10px 0 20px; }
.compact-heading { align-items: center; margin: 0 0 12px; }
.eyebrow { color: var(--muted); font-size: 13px; margin-bottom: 4px; text-transform: capitalize; }
.muted { color: var(--muted); margin-bottom: 0; }
.small-note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--border); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.badge.success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, var(--border)); }
.panel { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.metric { padding-top: 11px; border-top: 1px solid var(--border); }
.metric strong { display: block; font-size: 17px; }
.metric span { color: var(--muted); font-size: 12px; }
.quick-section, .timeline-section { margin-top: 28px; }
.quick-grid { display: grid; gap: 10px; }
.quick-action { min-height: 74px; width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; transition: border-color .15s, transform .15s, background .15s; }
.quick-action:hover { border-color: var(--accent); }
.quick-action:active { transform: scale(.99); }
.quick-action strong, .quick-action small { display: block; }
.quick-action strong { margin-bottom: 2px; }
.quick-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: var(--accent-soft); color: var(--accent-strong); font-weight: 800; }
.quick-plus { width: 38px; height: 38px; padding: 9px; border-radius: 11px; background: var(--surface-2); color: var(--text); }
.button { min-height: 42px; border-radius: 10px; border: 1px solid transparent; padding: 9px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 700; font-size: 14px; background: var(--surface); }
.button.compact { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.button.secondary:hover, .button.ghost:hover { background: var(--surface-2); }
.button.ghost { background: transparent; border-color: transparent; color: var(--text); }
.button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.timeline { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.timeline-item { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; padding: 14px 2px; border-bottom: 1px solid var(--border); align-items: start; }
.timeline-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; padding-top: 2px; }
.timeline-title { font-weight: 750; margin-bottom: 3px; }
.timeline-detail { color: var(--muted); font-size: 13px; }
.timeline-open { display: inline-flex; color: var(--warning); font-size: 12px; font-weight: 700; margin-top: 4px; }
.timeline-button { background: transparent; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); }
.open-callout { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--warning-soft); border: 1px solid color-mix(in srgb, var(--warning) 30%, var(--border)); color: var(--text); border-radius: 12px; padding: 12px; margin: 0 0 12px; }
.open-callout p { margin: 0; }
.empty-state { padding: 28px 14px; text-align: center; color: var(--muted); border-bottom: 1px solid var(--border); }
.bottom-nav { position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; height: 72px; display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: transparent; border: 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.nav-item.active { color: var(--accent); }
.nav-item .icon { width: 21px; height: 21px; }
.filter-bar { display: grid; grid-template-columns: 1.4fr 1fr .65fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 20px; }
.field { display: grid; gap: 6px; }
.field > span, .fieldset-inline legend, .contexts-fieldset legend { font-size: 12px; font-weight: 750; color: var(--muted); }
.field.grow { min-width: 180px; }
input, select, textarea { width: 100%; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 11px; min-height: 42px; }
textarea { resize: vertical; }
.history-list { display: grid; gap: 18px; }
.history-day { border-top: 1px solid var(--border); padding-top: 14px; }
.history-date { color: var(--muted); font-size: 13px; font-weight: 800; margin-bottom: 7px; text-transform: uppercase; letter-spacing: .03em; }
.history-row { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 13px 4px; text-align: left; display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; color: var(--text); }
.history-row:hover { background: var(--surface-2); }
.history-row .type { font-weight: 750; }
.history-row .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.summary-grid { display: grid; gap: 12px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.summary-card h3 { margin-bottom: 14px; }
.summary-card .big-number { font-size: 30px; line-height: 1; letter-spacing: -.04em; font-weight: 800; }
.summary-card .summary-lines { margin-top: 14px; display: grid; gap: 8px; }
.summary-line { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.summary-line strong { color: var(--text); }
.summary-link { width: 100%; border: 0; background: transparent; color: inherit; padding: 0; text-align: left; }
.data-block { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; padding: 22px 0; border-top: 1px solid var(--border); }
.data-block:first-of-type { border-top: 0; }
.data-block h3 { margin-bottom: 5px; }
.button-stack { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.about-block { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 20px; }
.about-list { margin: 0 0 16px; }
.about-list div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 8px 0; }
.about-list dt { color: var(--muted); }
.about-list dd { margin: 0; }
.update-banner { max-width: calc(var(--max) - 36px); margin: 0 auto 8px; padding: 12px 14px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border)); border-radius: 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.update-banner span { display: block; color: var(--muted); font-size: 13px; }
.inline-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-actions.right { justify-content: flex-end; }
.modal { width: min(680px, calc(100vw - 24px)); max-height: min(90vh, 820px); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.small-modal { width: min(470px, calc(100vw - 24px)); }
.modal-form { padding: 20px; overflow: auto; max-height: min(90vh, 820px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.modal-header h2 { font-size: 22px; }
.icon-button { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px; color: var(--muted); font-size: 26px; line-height: 1; }
.icon-button:hover { background: var(--surface-2); }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.split-actions { justify-content: space-between; }
.choice-stack { display: grid; gap: 10px; }
.choice-stack .button { width: 100%; }
.fieldset-inline, .contexts-fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin: 16px 0; }
.fieldset-inline { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.fieldset-inline legend, .contexts-fieldset legend { padding: 0 4px; }
.fieldset-inline label, .checkbox-grid label { display: flex; align-items: center; gap: 7px; }
.fieldset-inline input, .checkbox-grid input { width: auto; min-height: 0; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.details-block { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.details-block summary { cursor: pointer; padding: 12px; font-weight: 750; }
.details-content { padding: 4px 12px 12px; }
.subsection-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 10px; }
.stack { display: grid; gap: 8px; padding: 0 12px 12px; }
.nap-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.awakening-row { display: grid; grid-template-columns: .7fr .7fr 1.4fr auto; gap: 8px; align-items: end; }
.contexts-fieldset { margin-top: 18px; }
.warning-box { display: flex; gap: 10px; align-items: flex-start; background: var(--warning-soft); border: 1px solid color-mix(in srgb, var(--warning) 30%, var(--border)); border-radius: 12px; padding: 12px; margin-top: 14px; }
.warning-box p { margin: 0; }
.preview-list { margin: 0; }
.preview-list div { display: grid; grid-template-columns: 1fr 1.2fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.preview-list dt { color: var(--muted); }
.preview-list dd { margin: 0; }
.toast-region { position: fixed; z-index: 100; left: 50%; bottom: 84px; transform: translateX(-50%); width: min(520px, calc(100vw - 24px)); display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--text); color: var(--surface); padding: 11px 13px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; }
.toast button { color: inherit; background: transparent; border: 0; text-decoration: underline; font-weight: 800; }
.type-fields { display: grid; gap: 14px; margin: 16px 0; padding: 14px; background: var(--surface-2); border-radius: 12px; }

@media (min-width: 760px) {
  .app-shell { padding-bottom: 26px; display: flex; flex-direction: column; }
  .topbar { padding-top: 24px; order: 1; width: 100%; }
  .bottom-nav { order: 2; }
  .update-banner { order: 3; }
  .main-content { padding-top: 22px; order: 4; width: 100%; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-nav { position: sticky; top: 0; bottom: auto; z-index: 20; max-width: var(--max); margin: 0 auto; width: calc(100% - 36px); height: 56px; grid-template-columns: repeat(4, auto); justify-content: start; gap: 6px; border: 1px solid var(--border); border-radius: 12px; padding: 5px; background: color-mix(in srgb, var(--surface) 95%, transparent); box-shadow: var(--shadow); }
  .nav-item { flex-direction: row; min-width: 120px; padding: 0 14px; border-radius: 8px; font-size: 13px; }
  .nav-item.active { background: var(--accent-soft); }
  .toast-region { bottom: 24px; }
}

@media (max-width: 760px) {
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar .grow { grid-column: 1 / -1; }
  .filter-reset { align-self: stretch; }
  .data-block { grid-template-columns: 1fr; gap: 12px; }
  .button-stack { justify-content: flex-start; }
  .update-banner { margin-left: 12px; margin-right: 12px; max-width: none; align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .form-grid.two { grid-template-columns: 1fr; }
  .checkbox-grid { grid-template-columns: 1fr; }
  .metric-row { grid-template-columns: 1fr 1fr; }
  .timeline-item { grid-template-columns: 50px 1fr auto; }
  .section-heading { align-items: flex-start; }
  .compact-field { max-width: 120px; }
  .about-list div { grid-template-columns: 1fr; gap: 2px; }
  .nap-row, .awakening-row { grid-template-columns: 1fr 1fr; }
  .nap-row button, .awakening-row button { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
