/* ---------- tokens ---------- */
:root {
  --ground: #F1F4F4;
  --surface: #FFFFFF;
  --surface-2: #E9EEEE;
  --ink: #101819;
  --ink-soft: #3B4A4D;
  --muted: #61747A;
  --line: #D5DDDE;
  --line-strong: #B6C3C5;
  --accent: #0B6B63;
  --accent-ink: #FFFFFF;
  --accent-soft: #D8EAE7;
  --signal: #97600F;
  --signal-soft: #F3E6CE;
  --ok: #2C6E4E;
  --ok-soft: #D9E9DF;
  --risk: #953428;
  --risk-soft: #F4DEDA;
  --shadow-sm: 0 1px 2px rgba(16, 24, 25, .06);
  --shadow-lg: 0 1px 2px rgba(16, 24, 25, .05), 0 18px 44px -22px rgba(16, 24, 25, .35);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --r: 9px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0A1113;
    --surface: #101A1D;
    --surface-2: #17252A;
    --ink: #E4EDEE;
    --ink-soft: #C0CFD1;
    --muted: #8CA1A6;
    --line: #22343A;
    --line-strong: #33494F;
    --accent: #5AC4B4;
    --accent-ink: #06211E;
    --accent-soft: #10322F;
    --signal: #DCA748;
    --signal-soft: #33280F;
    --ok: #63B98A;
    --ok-soft: #14301F;
    --risk: #E08072;
    --risk-soft: #381914;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-lg: 0 1px 2px rgba(0, 0, 0, .5), 0 20px 50px -24px rgba(0, 0, 0, .9);
  }
}

:root[data-theme="dark"] {
  --ground: #0A1113;
  --surface: #101A1D;
  --surface-2: #17252A;
  --ink: #E4EDEE;
  --ink-soft: #C0CFD1;
  --muted: #8CA1A6;
  --line: #22343A;
  --line-strong: #33494F;
  --accent: #5AC4B4;
  --accent-ink: #06211E;
  --accent-soft: #10322F;
  --signal: #DCA748;
  --signal-soft: #33280F;
  --ok: #63B98A;
  --ok-soft: #14301F;
  --risk: #E08072;
  --risk-soft: #381914;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, .5), 0 20px 50px -24px rgba(0, 0, 0, .9);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

/*
 * The UA rule behind the `hidden` attribute is `[hidden] { display: none }` at
 * zero specificity, so any class that sets `display` silently defeats it — which
 * is exactly what .app, .login-screen and .modal-root did, leaving an
 * undismissable empty modal over the login form. Toggling `hidden` from JS is the
 * app's only show/hide mechanism, so this rule has to outrank every layout class.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.22; margin: 0; text-wrap: balance; }
h1 { font-size: 1.85rem; letter-spacing: -.018em; }
h2 { font-size: 1.3rem; letter-spacing: -.012em; }
h3 { font-size: 1.02rem; }
p { margin: 0; }

a { color: var(--accent); text-underline-offset: 3px; }

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

.eyebrow {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

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

/* ---------- topbar ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .7rem clamp(.9rem, 3vw, 1.8rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-family: var(--serif);
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -.01em;
}
.brand-mark {
  width: 11px; height: 11px; border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.nav { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
.nav a {
  font-size: .88rem;
  padding: .34rem .68rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 550; }

.topbar-end { display: flex; align-items: center; gap: .6rem; }
.whoami { font-size: .82rem; color: var(--muted); font-family: var(--mono); }

.main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(1.2rem, 3vw, 2.2rem) clamp(.9rem, 3vw, 1.8rem) 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* ---------- view header ---------- */
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.view-head .titles { display: flex; flex-direction: column; gap: .25rem; }
.view-head p { color: var(--muted); font-size: .9rem; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: .88rem;
  font-weight: 550;
  padding: .48rem .95rem;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--risk); border-color: color-mix(in srgb, var(--risk) 35%, transparent); }
.btn-icon { padding: .35rem .5rem; }
.btn-sm { font-size: .8rem; padding: .32rem .68rem; }

/* ---------- pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .03em;
  padding: .26em .62em;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill .dot { width: .48em; height: .48em; border-radius: 999px; background: currentColor; flex: none; }
.pill-new     { background: var(--surface-2);   color: var(--muted);  border-color: var(--line); }
.pill-progress{ background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.pill-review  { background: var(--signal-soft); color: var(--signal); border-color: color-mix(in srgb, var(--signal) 30%, transparent); }
.pill-done    { background: var(--ok-soft);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.pill-failed  { background: var(--risk-soft);   color: var(--risk);   border-color: color-mix(in srgb, var(--risk) 32%, transparent); }
.pill-cancelled { background: var(--surface-2); color: var(--muted);  border-color: var(--line); text-decoration: line-through; }

/* ---------- cards / tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.15rem 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-end { margin-left: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .89rem; min-width: 540px; }
th, td { text-align: left; padding: .62rem .85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  background: var(--surface-2);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.shrink { width: 1%; white-space: nowrap; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: .92rem;
}

/* ---------- dashboard tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .8rem;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .15rem;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--line-strong);
}
.tile.accent::before { background: var(--accent); }
.tile.ok::before { background: var(--ok); }
.tile.risk::before { background: var(--risk); }
.tile.muted-tile { background: var(--surface-2); }
.tile-value { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.tile-label { font-size: .82rem; color: var(--ink-soft); font-weight: 550; margin-top: .35rem; }
.tile-sub { font-size: .74rem; color: var(--muted); font-family: var(--mono); }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-top: .4rem;
}
.section-head h2 { font-size: 1.15rem; }
.section-head a { font-size: .85rem; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: flex; gap: .7rem; padding: .3rem 0; position: relative; }
.timeline li:not(:last-child)::before {
  content: ""; position: absolute; left: 4px; top: 1.1rem; bottom: -.3rem;
  width: 1px; background: var(--line);
}
.tl-dot {
  width: 9px; height: 9px; border-radius: 999px; background: var(--accent);
  margin-top: .35rem; flex: none; box-shadow: 0 0 0 3px var(--accent-soft);
}
.tl-label { font-size: .88rem; }
.tl-time { font-size: .74rem; color: var(--muted); font-family: var(--mono); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; }
.field > span { color: var(--muted); font-weight: 550; }
input, select, textarea {
  font: inherit;
  font-size: .92rem;
  padding: .5rem .65rem;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 76px; resize: vertical; }
.field-grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-error {
  color: var(--risk);
  background: var(--risk-soft);
  border-radius: 6px;
  padding: .5rem .7rem;
  font-size: .85rem;
}
.hint { font-size: .8rem; color: var(--muted); }

/* ---------- task detail ---------- */
.detail-grid { display: grid; gap: 1.1rem; grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr); align-items: start; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.handoff-cta {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  padding: 1.15rem 1.25rem;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  background: var(--accent-soft);
  border-radius: var(--r);
}
.handoff-cta .btn-primary { justify-content: center; }
.blocked { font-size: .85rem; color: var(--signal); }

/* ---------- QR ---------- */
.qr-plate {
  /* Always light: inverted codes scan unreliably on some phones. */
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  width: min(280px, 70vw);
  align-self: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}
.qr-plate svg { display: block; width: 100%; height: auto; }

.countdown {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--accent);
}
.countdown.warn { color: var(--signal); }
.countdown.dead { color: var(--risk); }

.code-display {
  font-family: var(--mono);
  font-size: 1.7rem;
  letter-spacing: .22em;
  text-align: center;
  padding: .6rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--line);
  word-break: break-all;
}

.linkbox {
  font-family: var(--mono);
  font-size: .72rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .5rem .6rem;
  word-break: break-all;
  color: var(--muted);
  max-height: 5.5rem;
  overflow-y: auto;
}

/* ---------- login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.login-card h1 { margin-bottom: .3rem; }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1.2rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6, 12, 14, .55); backdrop-filter: blur(2px); }
.modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }

/* ---------- toaster ---------- */
.toaster {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: var(--ground);
  font-size: .87rem;
  padding: .55rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
}
.toast.bad { background: var(--risk); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav a, tbody tr.clickable { transition: background-color .13s ease, color .13s ease; }
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } }
}
