/* ==========================================================================
   base.css — reset, typography primitives, app shell, navigation
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--ink);
  background: var(--plane);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

/* A 32px hairline grid, barely there — the "engineered paper" plane. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right,  var(--hairline) 1px, transparent 1px),
    linear-gradient(to bottom, var(--hairline) 1px, transparent 1px);
  background-size: 64px 64px;
  opacity: .5;
  mask-image: radial-gradient(ellipse 100% 70% at 50% 0%, #000 0%, transparent 78%);
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; padding: 0; }
summary { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent); color: var(--accent-ink); }

/* thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--r-pill); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- type primitives ----------------------------------------------------- */
.eyebrow {
  font: 500 var(--fs-micro)/1.2 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-sm); }
.dim { color: var(--ink-2); }
.dimmer { color: var(--ink-3); }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Shell
   ========================================================================== */
.app { position: relative; z-index: 1; display: flex; min-height: 100vh; }

/* ---- rail ---------------------------------------------------------------- */
.rail {
  position: sticky; top: 0; align-self: flex-start;
  width: var(--rail-w); height: 100vh; flex: 0 0 var(--rail-w);
  display: flex; flex-direction: column; gap: var(--sp-5);
  padding: var(--sp-5) var(--sp-4);
  border-right: 1px solid var(--hairline);
  background: color-mix(in oklab, var(--plane) 86%, var(--surface-1));
  backdrop-filter: blur(8px);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--sp-2); }
.brand-mark {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
}
.brand-mark svg { width: 15px; height: 15px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font: 600 var(--fs-sm)/1.1 var(--sans);
  letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font: 400 var(--fs-micro)/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: var(--sp-4); }
.nav-label { padding: 0 var(--sp-2) var(--sp-2); }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px var(--sp-2) 8px 10px;
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 500;
  text-align: left;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.nav-item svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -17px; top: 50%; translate: 0 -50%;
  width: 2px; height: 18px; border-radius: 2px; background: var(--accent);
}
.nav-item[aria-current="page"] svg { color: var(--accent); opacity: 1; }
.nav-key {
  margin-left: auto;
  font: 500 var(--fs-micro)/1 var(--mono);
  color: var(--ink-4);
  border: 1px solid var(--hairline);
  border-radius: 3px; padding: 3px 4px;
}

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
.rail-progress { padding: 0 var(--sp-2); display: flex; flex-direction: column; gap: 6px; }
.rail-progress-top { display: flex; justify-content: space-between; align-items: baseline; }
.rail-progress-val { font: 600 var(--fs-sm)/1 var(--mono); font-variant-numeric: tabular-nums; }

/* ---- main --------------------------------------------------------------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in oklab, var(--plane) 78%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  min-height: 57px;
}
.topbar-title { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar-title h1 { font-size: var(--fs-md); font-weight: 600; white-space: nowrap; }
.topbar-meta { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

.view-wrap { flex: 1 1 auto; padding: var(--sp-5) var(--sp-5) var(--sp-8); }
.view { max-width: var(--maxw); margin: 0 auto; }
.view[hidden] { display: none; }
.view-anim { animation: viewIn var(--med) var(--ease) both; }
@keyframes viewIn { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } }

.section { margin-top: var(--sp-6); }
.section:first-child { margin-top: 0; }
.section-head {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-3); flex-wrap: wrap;
}
.section-head .eyebrow { white-space: nowrap; }
.section-head hr {
  flex: 1 1 auto; height: 1px; border: 0; min-width: 20px;
  background: linear-gradient(to right, var(--hairline), transparent);
}
.section-head-actions { display: flex; gap: var(--sp-2); align-items: center; }

/* ---- responsive --------------------------------------------------------- */
@media (max-width: 900px) {
  body::before { background-size: 48px 48px; }
  .app { flex-direction: column; }
  .rail {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0;
    width: 100%; height: auto; flex: none;
    flex-direction: row; align-items: center; gap: 0;
    padding: 6px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--hairline);
    background: color-mix(in oklab, var(--plane) 94%, var(--surface-1));
  }
  .brand, .rail-foot, .nav-label, .nav-key, .nav-group + .nav-group { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-between; gap: 0; }
  .nav-group { display: contents; }
  .nav-item {
    flex-direction: column; gap: 3px; padding: 6px 2px;
    font-size: 9px; letter-spacing: .02em; text-align: center;
    border-radius: var(--r-sm);
  }
  .nav-item svg { width: 19px; height: 19px; }
  .nav-item[aria-current="page"]::before { left: 50%; top: -6px; translate: -50% 0; width: 16px; height: 2px; }
  .main { padding-bottom: 66px; }
  .view-wrap { padding: var(--sp-4) var(--sp-4) var(--sp-6); }
  .topbar { padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; gap: var(--sp-2); row-gap: var(--sp-2); }
  .topbar-title { flex: 1 1 auto; }
  .topbar-title h1 { font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { margin-left: auto; }
  .day-nav { flex: 1 1 100%; order: 3; }
  .day-nav input[type="date"] { flex: 1 1 auto; width: auto !important; }
}

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