/* Docket — a work board that keeps the receipts.
   Palette follows the CKGSB 2026 identity: navy ink, signal blue for
   interaction, aqua for finished work, orange strictly for lateness. */

:root {
  color-scheme: light;

  --ink:        #00174B;
  --ink-2:      #3B4C74;
  --ink-3:      #6E7D9C;
  --page:       #FFFFFF;
  --surface:    #FFFFFF;
  --sunken:     #EFF3F8;
  --sunken-2:   #E4EBF3;
  --line:       #D8E0EB;
  --line-soft:  #E8EDF4;

  --accent:     #009BE4;
  --accent-ink: #0077B3;
  --accent-wash:#E5F4FD;
  --done:       #00ACA3;
  --done-ink:   #007D77;
  --done-wash:  #E2F5F3;
  --late:       #FF8400;
  --late-ink:   #C25E00;
  --late-wash:  #FFF0DF;

  --shadow-sheet: 0 24px 60px -20px rgb(0 23 75 / 0.30);
  --shadow-lift:  0 12px 26px -10px rgb(0 23 75 / 0.35);

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "IBM Plex Serif", ui-serif, Georgia, "Times New Roman", serif;

  --rail-w: 312px;
  --bar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --ink:        #E8EEF9;
    --ink-2:      #B2C2DC;
    --ink-3:      #7F92B4;
    --page:       #070E1E;
    --surface:    #101B33;
    --sunken:     #0B1428;
    --sunken-2:   #16223D;
    --line:       #1F2D4C;
    --line-soft:  #17233D;

    --accent:     #35B4F0;
    --accent-ink: #6BC9F6;
    --accent-wash:#0D2740;
    --done:       #17C0B5;
    --done-ink:   #3AD6CB;
    --done-wash:  #0A2E2C;
    --late:       #FF9A33;
    --late-ink:   #FFB264;
    --late-wash:  #33210C;

    --shadow-sheet: 0 24px 60px -20px rgb(0 0 0 / 0.7);
    --shadow-lift:  0 12px 26px -10px rgb(0 0 0 / 0.75);
  }
}

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

/* Every panel below sets its own `display`, which outranks the UA's
   [hidden] rule — so state the intent once, loudly. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }

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

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- gate */

.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--accent-wash), transparent 60%),
    var(--page);
}

.gate-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 34px 30px 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sheet);
}

.gate-mark { color: var(--done); line-height: 0; }

.gate-card h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gate-sub {
  margin: -10px 0 6px;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
}

.gate-error {
  margin: 0;
  color: var(--late-ink);
  font-size: 13px;
}

/* --------------------------------------------------------------- shell */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: var(--bar-h);
  flex: 0 0 auto;
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--done);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-mark { background: var(--sunken-2); }
}

.brand-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.views { display: flex; gap: 2px; }

.view-tab {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--ink-3);
  font-weight: 500;
  cursor: pointer;
}
.view-tab:hover { color: var(--ink); background: var(--sunken); }
.view-tab.is-active { color: var(--ink); background: var(--sunken-2); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.period { display: flex; align-items: center; gap: 2px; }

.period-label {
  min-width: 132px;
  padding: 5px 8px;
  border: 0;
  background: none;
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
}
.period-label:hover { background: var(--sunken); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--ink-2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-danger:hover { background: var(--late-wash); color: var(--late-ink); }

.seg {
  display: flex;
  padding: 2px;
  gap: 2px;
  background: var(--sunken);
  border-radius: 8px;
}

.seg-btn {
  border: 0;
  background: none;
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-3);
  cursor: pointer;
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.10);
}

.seg-wide { width: max-content; margin-bottom: 18px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-block { width: 100%; padding: 9px; }

.select {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

/* --------------------------------------------------------------- board */

.board {
  flex: 1;
  min-height: 0;
  display: flex;
}

.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--sunken);
}

.quick-add {
  display: flex;
  gap: 7px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.quick-add input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 11px;
}
.quick-add input::placeholder { color: var(--ink-3); }

.rail-block {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 12px 0;
}
.rail-grow { flex: 1; padding-bottom: 12px; }

.rail-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.rail-count {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot-late { background: var(--late); }

.stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 44px;
}
.stack-grow { flex: 1; overflow-y: auto; }

.empty-hint {
  margin: 6px 2px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-3);
}

.rail-tally {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 13px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.tally-num {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  color: var(--done-ink);
  font-variant-numeric: tabular-nums;
}

.tally-label {
  font-size: 12px;
  color: var(--ink-3);
}

/* ------------------------------------------------------------ calendar */

/* The calendar, not the grid, is the scroll container: the grid has to stay
   free to size its rows from their content (see .grid below). */
.calendar {
  flex: 1;
  background: var(--page);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.weekday-row {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.weekday-row span {
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* `flex: 1 0 auto` is deliberate. With `flex: 1` (basis 0) the grid gets a
   fixed height from the flex line, and `auto` rows are then squeezed to fit
   it — which is how twelve tasks on one day ended up spilling over the week
   below. Sized from content instead, a busy row grows and the calendar
   scrolls, while align-content still stretches quiet rows to fill the window. */
.grid {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  overflow: visible;
  background: var(--line-soft);
  gap: 1px;
  border-top: 1px solid var(--line-soft);
}

/* Week view is the exception: full-height day columns that scroll on their own. */
.grid.is-week {
  flex: 1 1 0%;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
  overflow: hidden;
}
/* `auto` rows, with the 122px floor on the cell rather than the track: in
   minmax(122px, auto) the base size comes from the 122px minimum, so a busy
   row could only grow into whatever space was left over and 12 tasks spilled
   over the week below. As a plain `auto` track the row takes its size from
   the cell's content, and align-content still stretches quiet rows to fill. */
.grid.is-month { grid-auto-rows: auto; }
.grid.is-month .day { min-height: 122px; }

.day {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 6px 7px 8px;
  background: var(--surface);
}

.day.is-outside { background: var(--sunken); }
.day.is-outside .day-num { color: var(--ink-3); opacity: 0.7; }
.day.is-weekend:not(.is-outside) { background: color-mix(in srgb, var(--sunken) 80%, var(--surface)); }

.day.is-today { box-shadow: inset 0 2px 0 0 var(--accent); }
.day.is-drop-target { background: var(--accent-wash); }

.day-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  flex: 0 0 auto;
}

.day-num {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.day.is-today .day-num { color: var(--accent-ink); font-weight: 600; }

.day-dow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.day-add {
  margin-left: auto;
  width: 20px; height: 20px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--ink-3);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}
.day:hover .day-add, .day-add:focus-visible { opacity: 1; }
.day-add:hover { background: var(--sunken-2); color: var(--ink); }

.day-tally {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--done-ink);
  font-variant-numeric: tabular-nums;
}

/* In month view the row grows to fit, so nothing needs to scroll inside a
   cell; week view keeps full-height columns that scroll on their own.
   `flex: 0 0 auto` is load-bearing: with `flex: 1` the list contributes no
   height to the cell, so past ~4 cards the row stayed short and the tasks
   spilled over the day below. */
.grid.is-month .day-list {
  flex: 0 0 auto;
  overflow: visible;
}

.day-list {
  flex: 1;
  min-height: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
}

/* ---------------------------------------------------------------- card */

.card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 6px 8px 6px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.card:hover { border-color: var(--ink-3); border-left-color: var(--accent); }

.card.is-done {
  background: var(--done-wash);
  border-color: transparent;
  border-left-color: var(--done);
}
.card.is-done .card-title {
  text-decoration: line-through;
  text-decoration-color: var(--done);
  text-decoration-thickness: 1.5px;
  color: var(--ink-3);
}

.card.is-late { border-left-color: var(--late); }

.card.is-dragging { opacity: 0.32; }

.card-ghost {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  box-shadow: var(--shadow-lift);
  transform: rotate(-1.2deg);
  border-color: var(--accent);
}

.card-slot {
  height: 30px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  background: var(--accent-wash);
}

.tick {
  flex: 0 0 auto;
  margin-top: 1px;
  width: 15px; height: 15px;
  padding: 0;
  border: 1.5px solid var(--ink-3);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
}
.tick:hover { border-color: var(--done); }
.card.is-done .tick {
  background: var(--done);
  border-color: var(--done);
  color: #fff;
}

.card-body { min-width: 0; flex: 1; }

.card-title {
  font-size: 12.8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.card-strand { color: var(--accent-ink); }
.card.is-done .card-strand { color: var(--done-ink); }

.card-note-flag { color: var(--ink-3); }

.card-late-stamp { color: var(--late-ink); }

/* -------------------------------------------------------------- record */

.record {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--page);
}

.record-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 28px 90px;
}

.record-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.record-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.record-actions { display: flex; gap: 7px; align-items: center; }

.tallies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0;
  margin: 0 0 30px;
  border-bottom: 1px solid var(--line);
}

.tally {
  padding: 18px 20px 18px 0;
}
.tally + .tally {
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.tally-value {
  display: block;
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tally-value.is-done { color: var(--done-ink); }
.tally-value.is-open { color: var(--late-ink); }

.tally-cap {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-3);
}

.group {
  margin-bottom: 32px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.group-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.group-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.entry {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.entry:last-child { border-bottom: 0; }

.entry-date {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}

.entry-title {
  font-weight: 500;
  font-size: 14.5px;
  overflow-wrap: anywhere;
}

.entry-notes {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 62ch;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry-strand {
  display: inline-block;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.record-open .entry-title { color: var(--ink-2); font-weight: 400; }

.record-empty {
  padding: 48px 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  color: var(--ink-3);
}

/* --------------------------------------------------------------- sheet */

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgb(0 12 34 / 0.34);
}

.sheet {
  position: fixed;
  z-index: 50;
  top: 0; right: 0; bottom: 0;
  width: min(430px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-sheet);
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.sheet-stamp {
  flex: 1;
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field > span {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.field > span em { font-style: normal; text-transform: none; letter-spacing: 0.02em; }

.field input, .field textarea {
  border: 1px solid var(--line);
  background: var(--page);
  border-radius: 8px;
  padding: 9px 11px;
  resize: vertical;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea::placeholder { color: var(--ink-3); }

.sheet-title-input {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 156px;
  gap: 12px;
}

.tick-big {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--page);
  cursor: pointer;
  text-align: left;
}
.tick-big:hover { border-color: var(--done); }

.tick-box {
  width: 19px; height: 19px;
  border: 1.5px solid var(--ink-3);
  border-radius: 5px;
  flex: 0 0 auto;
}

.tick-big.is-done { background: var(--done-wash); border-color: var(--done); }
.tick-big.is-done .tick-box {
  background: var(--done);
  border-color: var(--done);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='5 13 10 18 19 6'/%3E%3C/svg%3E");
  background-size: 14px;
  background-position: center;
  background-repeat: no-repeat;
}
.tick-big.is-done .tick-text { color: var(--done-ink); font-weight: 500; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font-size: 13px;
  box-shadow: var(--shadow-lift);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .toast { background: var(--sunken-2); color: var(--ink); }
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 8px 10px;
  }
  .topbar-right { width: 100%; margin-left: 0; justify-content: space-between; }
  .period-label { min-width: 0; white-space: nowrap; }

  .board { flex-direction: column; overflow-y: auto; }

  .rail {
    width: 100%;
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .rail-grow { flex: 0 0 auto; }
  .stack-grow { flex: 0 0 auto; max-height: 40vh; overflow-y: auto; }

  /* No definite heights below here — the page itself does the scrolling. */
  .calendar { flex: 0 0 auto; min-height: 0; overflow: visible; }
  .weekday-row { display: none; }

  .grid,
  .grid.is-week,
  .grid.is-month {
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: auto;
    overflow: visible;
  }

  .day,
  .grid.is-month .day { min-height: 0; padding: 10px 12px 12px; }
  .day.is-outside { display: none; }
  .day-list,
  .grid.is-week .day-list { flex: 0 0 auto; overflow: visible; }
  .day-add { opacity: 1; }

  .record-inner { padding: 26px 18px 80px; }
  .record-title { font-size: 27px; }
  .record-head { align-items: flex-start; flex-direction: column; }
  .entry { grid-template-columns: 74px 1fr; gap: 10px; }
  .field-row { grid-template-columns: 1fr; }
  .sheet { width: 100%; top: auto; height: 88dvh; border-radius: 16px 16px 0 0; }
}

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