/* ===========================================================================
   Alfredo — a quiet writing surface.

   Two type systems on purpose: the interface is system sans, the writing
   surface is a reading serif. Colour tokens follow a validated data-viz
   palette so the charts and the interface stay one system in both themes.
   =========================================================================== */

:root {
  color-scheme: light;

  --surface-1:      #fcfcfb;   /* cards, editor */
  --surface-2:      #f9f9f7;   /* page plane */
  --surface-sunk:   #f2f1ed;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --border:         rgba(11, 11, 11, 0.10);
  --border-strong:  rgba(11, 11, 11, 0.18);
  --chart-grid:     #e1e0d9;
  --chart-axis:     #c3c2b7;

  /* Data series. Added and removed are identities, not good and bad. */
  --series-added:   #2a78d6;
  --series-removed: #eb6834;
  --series-avg:     #184f95;
  --meter-track:    #cde2fb;

  --good:           #006300;
  --warning:        #fab219;
  --critical:       #d03b3b;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-read: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 4px 16px rgba(11,11,11,.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-2:      #0d0d0d;
    --surface-sunk:   #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.20);
    --chart-grid:     #2c2c2a;
    --chart-axis:     #383835;
    --series-added:   #3987e5;
    --series-removed: #d95926;
    --series-avg:     #86b6ef;
    --meter-track:    #184f95;
    --good:           #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-2:      #0d0d0d;
  --surface-sunk:   #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.20);
  --chart-grid:     #2c2c2a;
  --chart-axis:     #383835;
  --series-added:   #3987e5;
  --series-removed: #d95926;
  --series-avg:     #86b6ef;
  --meter-track:    #184f95;
  --good:           #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: var(--font-ui);
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

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

a { color: inherit; }

.boot {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--text-muted);
}

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

.app { min-height: 100dvh; }

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 20px calc(48px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 640;
  letter-spacing: -0.01em;
  font-size: 17px;
  margin-right: auto;
}
.topbar .brand small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-sunk); color: var(--text-primary); }

/* ----------------------------------------------------------------- pieces */

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 9px 15px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-sunk); }
.btn-primary {
  background: var(--text-primary);
  color: var(--surface-1);
  border-color: var(--text-primary);
}
.btn-primary:hover { opacity: .9; background: var(--text-primary); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-quiet:hover { background: var(--surface-sunk); }
.btn-danger { color: var(--critical); border-color: var(--border-strong); background: var(--surface-1); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 32px 0 12px;
}

/* -------------------------------------------------------------- dashboard */

.today {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 24px;
  margin-top: 20px;
}

.ring-wrap { position: relative; flex: none; }
.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}
/* Hero figure: proportional digits, UI sans, one per view. */
.hero-num {
  font-size: 40px;
  font-weight: 620;
  letter-spacing: -0.03em;
  line-height: 1;
}
.hero-sub { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.today-facts { display: grid; gap: 14px; flex: 1 1 auto; min-width: 0; }
.today-head { font-size: 15px; color: var(--text-secondary); line-height: 1.45; }
.today-head strong { color: var(--text-primary); font-weight: 600; }

.factrow { display: flex; flex-wrap: wrap; gap: 10px 26px; }
.fact { min-width: 84px; }
.fact-v { font-size: 19px; font-weight: 600; letter-spacing: -0.015em; }
.fact-l { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ------------------------------------------------------------- proj cards */

.projects { display: grid; gap: 12px; }

.proj {
  display: block;
  padding: 16px 18px;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color .12s ease, transform .12s ease;
}
.proj:hover { border-color: var(--border-strong); }

.proj-top { display: flex; align-items: baseline; gap: 12px; }
.proj-title { font-size: 16.5px; font-weight: 600; letter-spacing: -0.01em; flex: 1 1 auto; min-width: 0; }
.proj-venue { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.proj-stale { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.proj-stale.warn { color: var(--warning); font-weight: 600; }

/* The next action is the reason this screen exists: give it room. */
.proj-next {
  display: flex;
  gap: 8px;
  margin: 11px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
}
.proj-next .lbl { color: var(--text-muted); flex: none; font-size: 12.5px; padding-top: 1.5px; }
.proj-next.empty { color: var(--text-muted); font-style: italic; }

.proj-foot {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.proj-nums { display: flex; gap: 18px; flex: 1 1 auto; flex-wrap: wrap; }
.proj-num { font-size: 12.5px; color: var(--text-muted); }
.proj-num b { display: block; font-size: 15px; color: var(--text-primary); font-weight: 600; }
.spark { display: block; }

/* ----------------------------------------------------------------- charts */

.chart-wrap { position: relative; padding: 16px 4px 4px; }
.chart-svg { display: block; width: 100%; height: auto; }
.chart-tick { font-size: 10.5px; font-family: var(--font-ui); font-variant-numeric: tabular-nums; }
.chart-annot { font-size: 10.5px; font-family: var(--font-ui); }
.chart-hit { cursor: default; outline: none; }
.chart-hit:hover, .chart-hit:focus-visible { fill: color-mix(in srgb, var(--text-primary) 4%, transparent); }

.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 9px 11px;
  min-width: 132px;
  font-size: 12.5px;
}
.chart-tip-title { font-weight: 600; margin-bottom: 5px; }
.chart-tip-row { display: flex; justify-content: space-between; gap: 14px; line-height: 1.7; }
.chart-tip-key { color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.chart-tip-val { font-variant-numeric: tabular-nums; }
.chart-tip-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; padding: 4px 16px 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; }
.legend-line { width: 14px; height: 2px; border-radius: 2px; }

/* ------------------------------------------------------------ table twin */

.table-toggle { margin: 10px 0 0; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th, .dtable td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.dtable td { font-variant-numeric: tabular-nums; }
.tscroll { overflow-x: auto; max-height: 380px; overflow-y: auto; }

/* ----------------------------------------------------------------- editor */

/* Fixed-height column with the text as the only scroller. A page-length
   textarea plus a mobile keyboard is a jumping mess; this stays put. */
.editor-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface-1);
}

.ed-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: opacity .25s ease;
}
/* Chrome fades while you type and returns the moment you stop. */
.editor-screen.typing .ed-bar { opacity: .18; }
.editor-screen.typing .ed-bar:hover, .editor-screen.typing .ed-bar:focus-within { opacity: 1; }

.ed-title { font-size: 14px; font-weight: 600; flex: 1 1 auto; min-width: 0;
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-kind {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.ed-kind button {
  border: 0; background: transparent; padding: 6px 11px; font-size: 12.5px;
  cursor: pointer; color: var(--text-secondary);
}
.ed-kind button[aria-pressed="true"] { background: var(--surface-sunk); color: var(--text-primary); font-weight: 600; }

.ed-status { font-size: 11.5px; color: var(--text-muted); flex: none; font-variant-numeric: tabular-nums; }
.ed-status.warn { color: var(--warning); }
.ed-status.bad  { color: var(--critical); }

.ed-paper { flex: 1 1 auto; min-height: 0; display: flex; justify-content: center; }

/* The measure is the point: ~65 characters, generous leading, nothing else. */
.ed-text {
  width: 100%;
  max-width: 34em;
  height: 100%;
  overflow-y: auto;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-read);
  font-size: 19px;
  line-height: 1.72;
  padding: 40px 22px calc(45vh + env(safe-area-inset-bottom));
  caret-color: var(--series-added);
}
.ed-text::placeholder { color: var(--text-muted); opacity: .65; }

.ed-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  transition: opacity .25s ease;
}
/* While the words are flowing, the numbers get out of the way. */
.editor-screen.typing .ed-foot { opacity: .12; }
.editor-screen.typing .ed-foot:hover, .editor-screen.typing .ed-foot:focus-within { opacity: 1; }

.ed-count { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-right: auto; }
.ed-count .hidden-count { color: var(--text-muted); cursor: pointer; }
.ed-live { font-variant-numeric: tabular-nums; }
.ed-live .up { color: var(--text-primary); font-weight: 600; }

.conflict {
  margin: 0;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--warning) 16%, var(--surface-1));
  border-bottom: 1px solid var(--border-strong);
  font-size: 13.5px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------- modals */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(11,11,11,.34);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal-card {
  background: var(--surface-1);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 18px 60px rgba(0,0,0,.28);
  padding: 22px;
  width: min(460px, 100%);
  max-height: 86dvh;
  overflow: auto;
}
.modal-title { margin: 0 0 6px; font-size: 18px; font-weight: 620; letter-spacing: -0.015em; }
.modal-body { margin: 0 0 14px; color: var(--text-secondary); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 5px; font-weight: 500; }
.field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-2);
  font-family: var(--font-ui);
  font-size: 15px;   /* 16px-ish keeps iOS from zooming on focus */
  resize: vertical;
}
.field textarea { font-family: var(--font-read); line-height: 1.55; }
.field input:focus, .field textarea:focus {
  outline: 2px solid var(--series-added);
  outline-offset: -1px;
  border-color: transparent;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 200;
  max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------- misc */

.empty {
  text-align: center;
  padding: 52px 20px;
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.6;
}

.login {
  max-width: 340px;
  margin: 18vh auto 0;
  padding: 26px;
  text-align: center;
}
.login h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.02em; }
.login p { color: var(--text-muted); font-size: 13.5px; margin: 0 0 20px; }

.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 12px; border-radius: 8px; font-size: 13.5px; color: var(--text-secondary);
}
.tabs button[aria-current="page"] { background: var(--surface-sunk); color: var(--text-primary); font-weight: 600; }

@media (max-width: 620px) {
  .today { flex-direction: column; align-items: stretch; gap: 20px; text-align: center; padding: 20px 16px; }
  .ring-wrap { align-self: center; }
  .factrow { justify-content: space-between; gap: 10px; }
  .fact { min-width: 0; flex: 1 1 auto; }
  .wrap { padding: 0 14px 40px; }
  .ed-text { font-size: 18px; padding: 26px 18px calc(45vh + env(safe-area-inset-bottom)); }
  .proj-foot { flex-wrap: wrap; }
}

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