:root {
  color-scheme: light;
  --bg: #f3f5f4;
  --surface: #fbfcfb;
  --surface-2: #eaefee;
  --ink: #0e1f24;
  --ink-2: #4a5a5e;
  --muted: #6f7e81;
  --line: #dde4e3;
  --accent: #16838c;
  --accent-strong: #0b646d;
  --accent-soft: #dcefef;
  --on-accent: #ffffff;
  --critical: #d03b3b;
  --heat-0: #e4eaea;
  --heat-1: #72bec4;
  --heat-2: #3aa1a9;
  --heat-3: #16838c;
  --heat-4: #0b646d;
  --heat-5: #06434a;
  --shadow: 0 1px 2px rgba(14, 31, 36, 0.05), 0 8px 24px rgba(14, 31, 36, 0.06);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 16px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0c1416;
    --surface: #121d20;
    --surface-2: #19282c;
    --ink: #e9f1f0;
    --ink-2: #a9b9ba;
    --muted: #7f9295;
    --line: #22323a;
    --accent: #55c4cb;
    --accent-strong: #9be3e7;
    --accent-soft: #173f44;
    --on-accent: #06262a;
    --critical: #e66767;
    --heat-0: #1b282b;
    --heat-1: #1c555b;
    --heat-2: #1f7a82;
    --heat-3: #2aa0a8;
    --heat-4: #55c4cb;
    --heat-5: #9be3e7;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-family: var(--font-round); text-wrap: balance; }
h2 { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
ol { list-style: none; margin: 0; padding: 0; }
button { font: inherit; color: inherit; }
a { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); font-weight: 400; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--gutter) 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font: 650 17px/1.2 var(--font-round); letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath d='M9 0h10a9 9 0 0 1 9 9v10a9 9 0 0 1-9 9H9a9 9 0 0 1-9-9V9a9 9 0 0 1 9-9zm-1.5 11a1.5 1.5 0 0 0-1.5 1.5v3a1.5 1.5 0 0 0 3 0v-3A1.5 1.5 0 0 0 7.5 11zm5-4A1.5 1.5 0 0 0 11 8.5v11a1.5 1.5 0 0 0 3 0v-11A1.5 1.5 0 0 0 12.5 7zm5 2A1.5 1.5 0 0 0 16 10.5v7a1.5 1.5 0 0 0 3 0v-7A1.5 1.5 0 0 0 17.5 9zm5 3a1.5 1.5 0 0 0-1.5 1.5v1a1.5 1.5 0 0 0 3 0v-1a1.5 1.5 0 0 0-1.5-1.5z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath d='M9 0h10a9 9 0 0 1 9 9v10a9 9 0 0 1-9 9H9a9 9 0 0 1-9-9V9a9 9 0 0 1 9-9zm-1.5 11a1.5 1.5 0 0 0-1.5 1.5v3a1.5 1.5 0 0 0 3 0v-3A1.5 1.5 0 0 0 7.5 11zm5-4A1.5 1.5 0 0 0 11 8.5v11a1.5 1.5 0 0 0 3 0v-11A1.5 1.5 0 0 0 12.5 7zm5 2A1.5 1.5 0 0 0 16 10.5v7a1.5 1.5 0 0 0 3 0v-7A1.5 1.5 0 0 0 17.5 9zm5 3a1.5 1.5 0 0 0-1.5 1.5v1a1.5 1.5 0 0 0 3 0v-1a1.5 1.5 0 0 0-1.5-1.5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.brand-mark-lg { width: 56px; height: 56px; border-radius: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sync-status { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent-strong); }
.icon-btn.is-busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 1180px;
  margin: 12px auto 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
}
@media (max-width: 1212px) { .banner { margin-inline: var(--gutter); } }
.banner-icon { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--critical); }
.banner.is-info .banner-icon { color: var(--accent); }

/* Page layout */
.page {
  display: grid;
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px var(--gutter) 24px;
  transition: opacity 0.2s;
}
.page.is-refetching { opacity: 0.6; }
@media (min-width: 960px) {
  .page {
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    grid-template-areas:
      "hero hero"
      "rhythm hours"
      "recent people"
      "otd order";
    gap: 18px;
    padding-top: 24px;
  }
  .hero { grid-area: hero; }
  .block-rhythm { grid-area: rhythm; }
  .block-hours { grid-area: hours; }
  .block-recent { grid-area: recent; }
  .block-people { grid-area: people; }
  .block-otd { grid-area: otd; }
  .block-order { grid-area: order; }
}

.block {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-sub { color: var(--ink-2); font-size: 13.5px; margin-top: 4px; }
.mini-title { margin: 20px 0 10px; font: 600 14px/1.3 var(--font-round); color: var(--ink-2); }
.link-btn { padding: 4px 0; border: 0; background: none; color: var(--accent-strong); font-size: 13.5px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-strong); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent-strong); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--accent-soft); }

/* Hero */
.hero { display: grid; gap: 18px; padding: 6px 2px 4px; }
@media (min-width: 720px) { .hero { grid-template-columns: auto 1fr; align-items: end; gap: 32px; } }
.hero-main { display: grid; gap: 2px; }
.hero-num { font: 650 72px/0.95 var(--font-round); letter-spacing: -0.035em; }
.hero-label { font-size: 16px; color: var(--ink-2); }
.hero-delta { font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.hero-delta strong { color: var(--ink); font-weight: 600; }
.hero-empty { font: 600 20px/1.35 var(--font-round); color: var(--ink-2); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); min-width: 0; }
.tile-label { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.tile-value { font: 650 26px/1.15 var(--font-round); letter-spacing: -0.02em; margin-top: 4px; }
.tile-sub { font-size: 13px; color: var(--ink-2); }

/* Heatmap */
.heat-wrap { display: flex; margin-top: 14px; }
.heat-days { flex: none; }
.heat-days svg, .heat-scroll svg { display: block; }
.heat-scroll { flex: 1; min-width: 0; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.l0 { fill: var(--heat-0); background: var(--heat-0); }
.l1 { fill: var(--heat-1); background: var(--heat-1); }
.l2 { fill: var(--heat-2); background: var(--heat-2); }
.l3 { fill: var(--heat-3); background: var(--heat-3); }
.l4 { fill: var(--heat-4); background: var(--heat-4); }
.l5 { fill: var(--heat-5); background: var(--heat-5); }
.heat-cell { cursor: default; }
.heat-cell:hover { stroke: var(--ink); stroke-width: 1.5px; }
.axis-label { fill: var(--muted); font: 10.5px var(--font-ui); }
.heat-legend { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.heat-legend span { margin: 0 4px; }

/* Column charts */
.bars { margin-top: 14px; }
.bars svg { display: block; width: 100%; height: auto; overflow: visible; }
.bar { fill: var(--accent); }
.bar-hit { fill: transparent; cursor: default; }
.bar-hit:hover + .bar, .bar.is-hover { fill: var(--accent-strong); }
.bar-label { fill: var(--ink); font: 600 11.5px var(--font-ui); }
.baseline { stroke: var(--line); stroke-width: 1; }

.table-view { margin-top: 14px; overflow-x: auto; }
.table-view table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.table-view td.num, .table-view th.num { text-align: right; }

/* Search */
.search { display: flex; gap: 8px; margin-top: 12px; }
.search input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search-reset { flex: none; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; color: var(--ink-2); }
#recent-caption { margin-top: 10px; }

/* Notes */
.notes { display: grid; margin-top: 8px; }
.note { border-top: 1px solid var(--line); }
.note:first-child { border-top: 0; }
.note-main {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 11px 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.note-title { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.note-kind { display: inline-flex; align-items: center; gap: 4px; }
.note-kind svg { width: 13px; height: 13px; }
.note-summary { font-size: 13.5px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-body { padding: 0 0 14px; font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.note-body .note-actions { display: flex; gap: 14px; margin-top: 10px; }
.note-body.is-clamped .note-text {
  max-height: 24em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
}
.notes-compact .note-main { padding: 8px 0; }
.empty { padding: 12px 0; color: var(--muted); font-size: 14px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: 13px; }
.chip b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.folder-tag { color: var(--ink-2); }

/* On this day */
.otd { display: grid; gap: 16px; margin-top: 12px; }
@media (min-width: 600px) { .otd { grid-template-columns: 1fr 1fr; } }
.otd-col h3 { font: 600 14px/1.3 var(--font-round); color: var(--ink-2); margin-bottom: 4px; }

/* People */
.people { display: grid; gap: 2px; margin-top: 10px; }
.person {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.person:hover { background: var(--surface-2); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); font: 650 14px var(--font-round); }
.person-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-meta { font-size: 13px; color: var(--muted); }
.person-bar { height: 4px; margin-top: 6px; border-radius: 0 2px 2px 0; background: var(--accent); }
.person-count { font: 650 17px var(--font-round); font-variant-numeric: tabular-nums; }

/* Order */
.meter-row { margin-top: 12px; }
.meter-head { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.meter-head b { font: 650 17px var(--font-round); }
.meter { height: 8px; margin-top: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.barlist { display: grid; gap: 10px; }
.barlist li { display: grid; gap: 5px; }
.barlist-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.barlist-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.barlist-bar { height: 6px; border-radius: 0 3px 3px 0; background: var(--accent); min-width: 3px; }

/* Person sheet */
.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 90dvh;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(6, 18, 21, 0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet-inner { padding: 18px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px)); }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.sheet-head h2 { font-size: 22px; }
@media (min-width: 720px) {
  .sheet { width: 520px; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border-radius: 20px 0 0 20px; }
  .sheet-inner { padding: 24px; }
}

.dossier { margin-top: 16px; padding: 16px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.dossier-text { display: grid; gap: 8px; font-size: 14.5px; }
.dossier-text h3, .dossier-text h4 { font: 650 15px/1.3 var(--font-round); margin-top: 8px; }
.dossier-text ul, .dossier-text ol { margin: 0; padding-left: 20px; list-style: disc; display: grid; gap: 4px; }
.dossier-text ol { list-style: decimal; }
.dossier-meta { margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.dossier-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; }
.dossier-status { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.dossier-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dossier-error { color: var(--critical); font-size: 14px; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12.5px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.tooltip strong { display: block; font-size: 14px; font-weight: 650; }

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px));
  font-size: 12.5px;
  color: var(--muted);
}
.footer form { margin: 0; }

/* Login */
.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login { width: min(360px, 100%); display: grid; justify-items: center; gap: 6px; text-align: center; }
.login h1 { font-size: 26px; margin-top: 12px; }
.login-form { width: 100%; display: grid; gap: 10px; margin-top: 22px; text-align: left; }
.login-form label { font-size: 13.5px; color: var(--ink-2); }
.login-form input { height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; }
.login-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-error { color: var(--critical); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
