/* FHE Work Orders.
   No inline styles anywhere, because the Content Security Policy in _headers
   forbids them outright. Light and dark both come from tokens; there is no
   theme toggle yet and the browser's own setting decides. */

:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --line: #d8dce2;
  --ink: #14171c;
  --muted: #5b636e;
  --accent: #0b5cad;
  --accent-ink: #ffffff;
  --err: #a3211a;
  --ok: #1c6b3a;
  --warn: #8a5a00;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --line: #333a44;
    --ink: #e8eaee;
    --muted: #a2abb7;
    --accent: #6aa9e9;
    --accent-ink: #0b1220;
    --err: #ef8078;
    --ok: #78c99a;
    --warn: #d9a441;
  }
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule loses to any class that sets display, and
   the gate sets display:flex. Without this, hiding the gate after sign in does
   nothing and the app renders underneath it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Focus has to stay visible. A review of the dashboard found a keyboard
   accessibility failure that hid most of the app, so this is deliberate. */
:where(a, button, input, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.gate {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .5rem; padding: 2rem; text-align: center;
}
.gate h1 { font-size: 1.5rem; margin: 0; }
.gate p { margin: 0; color: var(--muted); }
.gate button { margin-top: 1rem; }

/* ---------- header ---------- */

header {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
header h1 { font-size: 1.05rem; margin: 0; font-weight: 600; }
.brand {
  font-weight: 700; letter-spacing: .04em;
  background: var(--accent); color: var(--accent-ink);
  padding: .15rem .4rem; border-radius: 4px; font-size: .8rem;
}
.spacer { flex: 1 1 auto; }
.who { color: var(--muted); font-size: .85rem; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: .2rem; margin-left: .5rem; }
.tab {
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius);
  color: var(--muted);
  padding: .35rem .8rem;
}
.tab:hover { color: var(--ink); border-color: var(--line); }
.tab.on {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 600;
}

/* ---------- buttons ---------- */

button {
  font: inherit;
  padding: .4rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); padding: .5rem 1.1rem;
}
button.danger { color: var(--err); }

/* ---------- reach panel ---------- */

.reach {
  margin: .75rem 1rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.reach summary {
  cursor: pointer; padding: .5rem .75rem;
  font-size: .9rem; color: var(--muted);
}
.reach-body { padding: 0 .75rem .5rem; }
.reach-row {
  display: grid;
  grid-template-columns: 1.5rem 9rem 1fr;
  gap: .5rem; align-items: baseline;
  padding: .25rem 0; font-size: .85rem;
  border-top: 1px solid var(--line);
}
.reach-row .mark { font-weight: 700; }
.reach-row .label { color: var(--muted); }
.reach-row .detail { word-break: break-word; }
.reach-row.ok .mark { color: var(--ok); }
.reach-row.bad .mark { color: var(--err); }
.reach-row.warn .mark { color: var(--warn); }
.reach-note { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }

/* ---------- controls ---------- */

.controls {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; flex-wrap: wrap;
}
.chips { display: flex; gap: .25rem; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: .3rem .75rem; font-size: .9rem; }
.chip.on {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.check { display: flex; align-items: center; gap: .35rem; font-size: .9rem; color: var(--muted); }
.search input {
  font: inherit; padding: .4rem .6rem; min-width: 16rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink);
}
.count { color: var(--muted); font-size: .85rem; }

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

.tablewrap { overflow-x: auto; padding: 0 1rem 2rem; }
table { border-collapse: collapse; width: 100%; min-width: 60rem; }
caption { text-align: left; }
th, td {
  text-align: left; vertical-align: top;
  padding: .45rem .6rem;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600;
  position: sticky; top: 0; background: var(--bg);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.key { font-weight: 600; white-space: nowrap; }
td.date { white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--panel); }
.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; max-width: 24rem;
}
.done td { color: var(--muted); }
.stale { color: var(--warn); font-weight: 600; }

.empty { color: var(--muted); padding: 2rem 0; text-align: center; }
.err { color: var(--err); padding: 0 1rem; }
.ok { color: var(--ok); padding: .5rem 1rem; margin: 0; }

/* ---------- create dialog ---------- */

.dlg {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  padding: 1.25rem;
  width: min(34rem, calc(100vw - 2rem));
}
.dlg::backdrop { background: rgb(0 0 0 / .5); }
.dlg h2 { margin: 0 0 .75rem; font-size: 1.1rem; }

.streams {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  margin: 0 0 .5rem;
  display: flex; gap: 1rem; flex-wrap: wrap;
}
.streams legend { padding: 0 .35rem; font-size: .8rem; color: var(--muted); }
.streams label { display: flex; align-items: center; gap: .35rem; }

.alloc {
  margin: 0 0 .75rem;
  font-size: .88rem;
  color: var(--muted);
}
.alloc.warn { color: var(--warn); }
.alloc.bad { color: var(--err); }

.f { display: block; margin: 0 0 .6rem; }
.f > span {
  display: block; font-size: .8rem; color: var(--muted); margin-bottom: .15rem;
}
.f input, .f select, .f textarea {
  font: inherit; width: 100%;
  padding: .4rem .6rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink);
}
.f textarea { resize: vertical; }

/* Two fields on a line where they belong together, stacking on a phone. */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
@media (max-width: 34rem) { .two { grid-template-columns: 1fr; } }

.hint { margin: -.3rem 0 .6rem; font-size: .82rem; color: var(--muted); min-height: 1.2em; }
.hint.warn { color: var(--warn); }

/* Permit rows open an editor, so they have to look and behave like controls. */
tr.clickable { cursor: pointer; }
tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
td.bad { color: var(--err); font-weight: 600; }

.dlg menu {
  display: flex; justify-content: flex-end; gap: .5rem;
  margin: 1rem 0 0; padding: 0;
}
.dlg button[disabled] { opacity: .55; cursor: not-allowed; }
