/* ===========================================================================
   Re:Agent — shared design tokens & component system
   Single source of truth extracted verbatim from the DEMO prototype
   (prototype.html / offer-sheet.html / walk-report.html). Every screen in the
   live app pulls from this file so the design never drifts from the prototype.

   The prototype is a LIGHT, neo-brutalist system: a bone paper background, a
   dark sidebar, ink hairline borders, hard offset shadows (4px 4px 0), square
   corners, Fraunces serif headings, JetBrains Mono labels, Inter Tight body.
   =========================================================================== */

:root {
  /* Bone / paper scale */
  --bone: #F2EFE8;
  --bone-2: #E8E4D8;
  --bone-3: #DCD7C7;
  /* Ink scale */
  --ink: #171513;
  --ink-2: #3A352F;
  --ink-3: #5C544A;
  /* Accents */
  --rust: #D94A1F;
  --rust-2: #B23A14;
  --acid: #E8F03A;
  --sodium: #FFB347;
  --asphalt: #1F2630;
  --slate: #2C3440;
  --green: #2A7A3B;
  --green-light: rgba(42, 122, 59, 0.08);

  /* Semantic shadows / borders */
  --shadow-hard: 4px 4px 0 var(--ink);
  --shadow-hard-lg: 6px 6px 0 var(--ink);
  --line-soft: #DCD7C7;

  /* Field background — swapped per theme so inputs invert cleanly in dark mode */
  --field-bg: #ffffff;

  /* Type */
  --font-serif: "Fraunces", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-sans: "Inter Tight", system-ui, sans-serif;

  /* Status hues (kanban / shows) */
  --st-confirmed: var(--rust);
  --st-hold: var(--acid);
  --st-offer: var(--bone-2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bone);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.mono { font-family: var(--font-mono); }

/* --- Wordmark ----------------------------------------------------------- */
.wordmark { font-family: var(--font-serif); font-weight: 300; letter-spacing: -0.02em; }
.wordmark .colon { color: var(--rust); font-weight: 700; }
.wordmark .ag { font-style: italic; font-weight: 600; }

/* --- Buttons (neo-brutalist, hard offset shadow) ------------------------ */
.btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 10px 16px;
  cursor: pointer;
  border: 2px solid var(--ink);
  background: var(--rust);
  color: var(--bone);
  border-color: var(--rust);
  box-shadow: 4px 4px 0 var(--rust-2);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { background: var(--rust-2); transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--rust-2); }
.btn:active { transform: translate(0, 0); box-shadow: 2px 2px 0 var(--rust-2); }

.btn.ghost { background: var(--bone); color: var(--ink); border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--bone); box-shadow: 6px 6px 0 var(--ink); }

.btn.sm { padding: 6px 12px; font-size: 10px; box-shadow: 3px 3px 0 var(--rust-2); }
.btn.ghost.sm { box-shadow: 3px 3px 0 var(--ink); }

.btn.danger { background: var(--bone); color: var(--rust); border-color: var(--rust); box-shadow: 4px 4px 0 var(--rust); }
.btn.danger:hover { background: var(--rust); color: var(--bone); }

/* --- Status pills / dots ------------------------------------------------ */
.statusdot {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1.5px solid var(--ink);
  flex-shrink: 0;
}
.statusdot.confirmed, .statusdot.done { background: var(--rust); color: var(--bone); border-color: var(--rust); }
.statusdot.hold, .statusdot.in_progress { background: var(--acid); color: var(--ink); border-color: var(--ink); }
.statusdot.offer, .statusdot.todo { background: var(--bone-2); color: var(--ink-2); border-color: var(--ink-3); }

.rolepill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 3px 8px;
  border: 1.5px solid;
}
.rolepill.manager { color: var(--ink); background: var(--sodium); border-color: var(--ink); }
.rolepill.member { color: var(--ink); background: var(--bone-2); border-color: var(--ink-3); }

/* --- Cards -------------------------------------------------------------- */
.card {
  background: var(--bone);
  border: 1.5px solid var(--ink);
  box-shadow: var(--shadow-hard);
  padding: 16px 18px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card.lift:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-hard-lg); }
.card.dark { background: var(--ink); color: var(--bone); border-color: var(--ink); }

/* --- Section heads ------------------------------------------------------ */
.section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--rust);
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-label::before, .section-label::after { content: "—"; color: var(--rust); font-weight: 400; }

/* --- Form fields -------------------------------------------------------- */
.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 5px;
  font-weight: 700;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--ink);
  background: var(--field-bg);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.form-textarea { font-family: var(--font-sans); font-size: 13px; resize: vertical; min-height: 70px; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--rust); }

/* --- Modal -------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(23, 21, 19, 0.7);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.overlay.show { display: flex; animation: bgIn 0.2s ease both; }
@keyframes bgIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bone);
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 rgba(217, 74, 31, 0.3);
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  animation: modalIn 0.25s ease both;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { padding: 18px 20px 14px; border-bottom: 2px solid var(--ink); }
.modal-head h3 { font-family: var(--font-serif); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.modal-head .ms { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); margin-top: 3px; }
.modal-body { padding: 20px; }
.modal-actions { padding: 14px 20px; border-top: 2px solid var(--ink); display: flex; gap: 8px; justify-content: flex-end; }

/* --- Toast (bottom-right stack, prototype-style) ------------------------ */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--ink);
  color: var(--bone);
  border: 1.5px solid #2a2520;
  border-left: 3px solid var(--green);
  padding: 12px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.2);
  min-width: 220px;
  max-width: 380px;
  z-index: 9999;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: var(--rust); }

/* --- Empty state -------------------------------------------------------- */
.empty {
  border: 1.5px dashed var(--ink-3);
  padding: 50px 30px;
  text-align: center;
  color: var(--ink-3);
  background: var(--bone-2);
}
.empty .et { font-family: var(--font-serif); font-size: 22px; font-weight: 400; font-style: italic; color: var(--ink-2); margin-bottom: 8px; }
.empty p { font-size: 14px; max-width: 380px; margin: 0 auto 18px; }

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

/* ===========================================================================
   THEMING — light / dark / auto, accent palettes, density
   ---------------------------------------------------------------------------
   The whole UI is driven by the tokens above, so a theme is just a token
   re-map. `data-theme="dark"` is applied to <html> by an inline no-FOUC
   script (see dashboard.html) and toggled live by assets/enhance.js. The
   neo-brutalist character is preserved: warm dark "paper", light ink, hard
   offset shadows that now read as light edges against the dark ground.
   =========================================================================== */
:root[data-theme="dark"] {
  /* Warm charcoal "paper" scale (was the bone scale) */
  --bone:   #1B1A16;
  --bone-2: #24221C;
  --bone-3: #322F27;
  /* Light "ink" — text, borders, hard shadows */
  --ink:   #F1ECE1;
  --ink-2: #D9D3C6;
  /* Muted/secondary text reads as the accent in dark mode (was a flat taupe
     grey) so labels, counts, metadata and timestamps pick up the warm orange
     instead of fading into the dark ground. Borders that used this token are
     re-pinned to a neutral grey just below so only the *text* turns orange. */
  --ink-3: var(--rust);
  --ink-line: #4A463D;
  --line-soft: #322F27;
  --field-bg: #26241D;
  /* Accents keep their identity; greens nudged brighter for the dark ground */
  --green: #4CA85F;
  --green-light: rgba(76, 168, 95, 0.14);
}

/* Keep the printable Toolbox documents on "paper" even in dark mode — they are
   WYSIWYG sheets meant to match what prints/exports, so they stay light. */
:root[data-theme="dark"] .tool-doc {
  --bone:   #F2EFE8;
  --bone-2: #E8E4D8;
  --bone-3: #DCD7C7;
  --ink:    #171513;
  --ink-2:  #3A352F;
  --ink-3:  #5C544A;
  --field-bg: #ffffff;
  color: var(--ink);
}

/* Components that deliberately paint a DARK background with LIGHT text in light
   mode would otherwise invert to a glaring light block in dark mode. Re-pin
   them to elevated dark surfaces so the hierarchy survives the flip. */
:root[data-theme="dark"] .side        { background: #100E0B; }
:root[data-theme="dark"] .stat.dark,
:root[data-theme="dark"] .card.dark   { background: var(--bone-2); color: var(--ink); border-color: var(--ink); }
:root[data-theme="dark"] .toast       { background: #26241D; color: var(--ink); border-color: #3a352c; }
:root[data-theme="dark"] .msg.mine .mb { background: var(--rust); color: #F6F1E8; border-color: var(--rust); }
:root[data-theme="dark"] .backfab     { background: var(--bone-2); color: var(--ink); }

/* Solid buttons & accent pills: force readable text on the bright accent. */
:root[data-theme="dark"] .btn               { color: #F6F1E8; }
:root[data-theme="dark"] .btn.ghost         { color: var(--ink); }
:root[data-theme="dark"] .btn.danger        { color: var(--rust); }
:root[data-theme="dark"] .statusdot.confirmed,
:root[data-theme="dark"] .statusdot.done    { color: #F6F1E8; }
:root[data-theme="dark"] .statusdot.hold,
:root[data-theme="dark"] .statusdot.in_progress,
:root[data-theme="dark"] .tc-due.today,
:root[data-theme="dark"] .rolepill.manager  { color: #171513; }

/* --ink-3 now carries the accent for text (see token block above). Re-pin the
   handful of element borders that used it back to a neutral grey so frames,
   dashed dropzones and pill outlines don't all turn orange. */
:root[data-theme="dark"] .statusdot.offer,
:root[data-theme="dark"] .rolepill.member,
:root[data-theme="dark"] .empty,
:root[data-theme="dark"] .qf-noresults,
:root[data-theme="dark"] .readonly-note,
:root[data-theme="dark"] .kb-add,
:root[data-theme="dark"] .media-preview { border-color: var(--ink-line); }

/* Smoothly cross-fade the big surfaces when the theme flips (respects the
   reduced-motion rule above, which kills all transitions). */
body, .side, .topbar, .card, .row, .stat, .modal, .kb-col, .task-card {
  transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

/* --- Accent palettes (data-accent on <html>) ---------------------------- */
:root[data-accent="ember"]  { --rust:#D94A1F; --rust-2:#B23A14; }   /* default */
:root[data-accent="indigo"] { --rust:#4F5BD5; --rust-2:#3B45A8; }
:root[data-accent="teal"]   { --rust:#0E8C8C; --rust-2:#0A6E6E; }
:root[data-accent="violet"] { --rust:#7C3AED; --rust-2:#5E27C0; }
:root[data-accent="pink"]   { --rust:#D6336C; --rust-2:#AC2455; }

/* --- Density (data-density on <html>) ----------------------------------- */
:root[data-density="compact"] .content      { padding-top: 18px; padding-bottom: 56px; }
:root[data-density="compact"] .card,
:root[data-density="compact"] .row          { padding-top: 9px; padding-bottom: 9px; }
:root[data-density="compact"] .stat         { padding: 12px 14px; }
:root[data-density="compact"] .stat .sv     { font-size: 30px; }
:root[data-density="compact"] .list         { gap: 8px; }
:root[data-density="compact"] .stats        { gap: 11px; margin-bottom: 20px; }
:root[data-density="compact"] .section-head { margin-bottom: 12px; }

/* ===========================================================================
   QUALITY-OF-LIFE UI — theme control, segmented settings, shortcut sheet,
   quick filter, scroll-to-top, offline banner, live clock
   =========================================================================== */

/* --- Sidebar theme control (cycles light · dark · auto) ------------------ */
.theme-toggle {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.12em;
  text-transform: uppercase; font-weight: 700;
  color: rgba(242,239,232,0.6);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(242,239,232,0.16);
  padding: 9px 11px; margin-bottom: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.theme-toggle:hover { color: var(--bone); background: rgba(255,255,255,0.08); border-color: rgba(242,239,232,0.32); }
.theme-toggle svg { width: 15px; height: 15px; flex-shrink: 0; }
.theme-toggle .tt-mode { margin-left: auto; color: var(--sodium); }

/* --- Segmented control (Appearance settings) ---------------------------- */
.seg { display: inline-flex; border: 1.5px solid var(--ink); background: var(--bone); flex-wrap: wrap; }
.seg button {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  padding: 9px 14px; background: none; border: none; cursor: pointer;
  color: var(--ink-3); border-right: 1.5px solid var(--ink);
  transition: background .12s, color .12s; display: inline-flex; align-items: center; gap: 6px;
}
.seg button:last-child { border-right: none; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--ink); color: var(--bone); }
.seg button .sw { width: 12px; height: 12px; border: 1px solid currentColor; display: inline-block; }
.seg.accents button.on { background: var(--bone-2); color: var(--ink); }

/* --- Keyboard shortcut cheat-sheet -------------------------------------- */
.shortcuts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
.shortcuts-grid .grp { grid-column: 1 / -1; font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rust); font-weight: 700; margin-top: 6px; }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.sc-row .lbl { font-size: 13px; color: var(--ink-2); }
.kbd {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  color: var(--ink); background: var(--bone-2);
  border: 1.5px solid var(--ink); border-bottom-width: 2.5px;
  padding: 2px 7px; min-width: 18px; text-align: center; display: inline-block;
}
.kbd + .kbd { margin-left: 4px; }

/* --- Quick filter (Shows / Tasks) --------------------------------------- */
.quickfilter { position: relative; margin-bottom: 16px; max-width: 360px; }
.quickfilter input {
  width: 100%; font-family: var(--font-mono); font-size: 12px; color: var(--ink);
  background: var(--field-bg); border: 1.5px solid var(--ink); box-shadow: var(--shadow-hard);
  padding: 10px 32px 10px 32px; outline: none;
}
.quickfilter input:focus { border-color: var(--rust); }
.quickfilter .qf-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--ink-3); pointer-events: none; }
.quickfilter .qf-clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--ink-3); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 5px; display: none; }
.quickfilter .qf-clear:hover { color: var(--rust); }
.quickfilter.has-val .qf-clear { display: block; }
.qf-noresults { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; color: var(--ink-3); border: 1.5px dashed var(--ink-3); background: var(--bone-2); padding: 16px; text-align: center; }

/* --- Scroll-to-top floating button -------------------------------------- */
.scrolltop {
  position: fixed; right: 18px; bottom: 18px; z-index: 125;
  width: 44px; height: 44px; display: none; align-items: center; justify-content: center;
  border: 2px solid var(--ink); background: var(--bone); color: var(--ink);
  box-shadow: 4px 4px 0 var(--rust); cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease, opacity .2s ease;
}
.scrolltop.show { display: flex; }
.scrolltop:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--rust); }
.scrolltop:active { transform: translate(0,0); box-shadow: 2px 2px 0 var(--rust); }
.scrolltop svg { width: 20px; height: 20px; }
@media (max-width: 900px) { .scrolltop { bottom: 74px; } }

/* --- Offline banner ----------------------------------------------------- */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 400;
  background: var(--ink); color: var(--bone);
  border-bottom: 2px solid var(--sodium);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700;
  text-align: center; padding: 8px 14px;
  transform: translateY(-100%); transition: transform .25s ease;
}
.offline-banner.show { transform: none; }
.offline-banner b { color: var(--sodium); }

/* --- Live clock in the topbar ------------------------------------------- */
.topclock {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-3); text-align: right; line-height: 1.5; white-space: nowrap;
}
.topclock .tc-time { color: var(--ink); font-weight: 700; font-size: 13px; letter-spacing: 0.04em; }
@media (max-width: 560px) { .topclock { display: none; } }
