:root {
  --paper: #fafaf7;        /* work surface */
  --panel: #ffffff;
  --ink: #1a1f1d;
  --mut: #6b7370;
  --rule: #e3e5e0;
  --drab: #2f3b2c;         /* sidebar — olive drab */
  --drab-ink: #e8ecdf;     /* text on drab */
  --drab-mut: #a7b39b;
  --signal: #cc3d2e;       /* segment locator red — the signature */
  --ok: #2e7d4f;
  --ok-soft: #e6f2ea;
  --edit: #2b6cb0;
  --edit-soft: #e8f0f9;
  --warn: #b45309;
  --warn-soft: #fdf1e2;
  --gray-soft: #eef0ec;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.5 var(--sans); background: var(--paper); color: var(--ink); }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--rule);
  background: var(--panel); color: var(--ink); padding: .42rem .85rem; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--signal); outline-offset: 1px; }
button.primary { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
button.primary:hover { background: #256a42; }
button.ghost { background: transparent; color: var(--mut); border-color: transparent; }
button.ghost:hover { color: var(--ink); border-color: var(--rule); background: var(--panel); }
input, textarea, select { font: inherit; padding: .5rem .65rem;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); color: var(--ink); }
.err { color: var(--signal); min-height: 1.2em; margin: 0; }
.kbd { color: var(--mut); font-size: .78rem; font-family: var(--mono); }

/* ---------- login ---------- */
#login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
#login form { background: var(--panel); padding: 2.2rem 2rem 1.8rem; border-radius: 10px;
  border: 1px solid var(--rule); border-top: 3px solid var(--signal);
  width: 350px; display: flex; flex-direction: column; gap: .75rem;
  box-shadow: 0 12px 32px rgba(26,31,29,.08); }
#login h1 { margin: 0 0 .6rem; font-family: var(--mono); font-size: 1.02rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }
#login h1::after { content: "Flyer 72 · Ops manual"; display: block; margin-top: .35rem;
  font-size: .72rem; letter-spacing: .12em; color: var(--mut); }
#login button[type=submit] { background: var(--drab); border-color: var(--drab); color: #fff; }
#code-row { display: flex; gap: .5rem; }
#code-row input { flex: 1; font-family: var(--mono); letter-spacing: .25em; }

/* ---------- shell ---------- */
#app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
#nav { background: var(--drab); color: var(--drab-ink); padding: 1.1rem .9rem;
  position: sticky; top: 0; height: 100vh; overflow: auto; }
#nav h2 { margin: 0 0 1.1rem; font-family: var(--mono); font-size: .82rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase; color: #fff;
  border-bottom: 2px solid var(--signal); padding-bottom: .55rem; }
#nav .navbtn { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
  width: 100%; text-align: left; margin: .1rem 0; background: transparent; color: var(--drab-ink);
  border: 0; border-radius: 6px; padding: .48rem .6rem; font-size: .92rem; }
#nav .navbtn .count { font-family: var(--mono); font-size: .72rem; color: var(--drab-mut); }
#nav .navbtn:hover { background: rgba(255,255,255,.08); }
#nav .navbtn.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
#nav .navbtn.active .count { color: var(--drab-ink); }
#nav .bar { height: 7px; background: rgba(0,0,0,.28); border-radius: 4px;
  overflow: hidden; margin: .15rem .6rem .6rem; }
#nav .bar > div { height: 100%; background: var(--drab-mut); border-radius: 4px;
  transition: width 200ms ease; }
#nav .flags { margin: .8rem .6rem 0; color: #f0b269; font-size: .8rem;
  font-family: var(--mono); }
#nav .cheat { margin: 1.2rem .6rem 0; padding-top: .8rem;
  border-top: 1px solid rgba(255,255,255,.12);
  font-family: var(--mono); font-size: .72rem; line-height: 2; color: var(--drab-mut); }
#nav .cheat b { color: var(--drab-ink); font-weight: 600; }

main { padding: 1.1rem 1.6rem 4rem; max-width: 1180px; }

/* ---------- mode header (what am I looking at + what do I do) ---------- */
.modehead { margin: .2rem 0 1rem; }
.modehead h1 { margin: 0; font-size: 1.25rem; letter-spacing: -.01em; }
.modehead p { margin: .3rem 0 0; color: var(--mut); max-width: 62ch; }
.modehead p b { color: var(--ink); }

/* ---------- column header ---------- */
.colhead { position: sticky; top: 0; z-index: 5; display: grid;
  grid-template-columns: 1fr 1fr; gap: 1.6rem; padding: .55rem 1.1rem;
  margin: 0 0 .7rem; background: var(--paper); border-bottom: 2px solid var(--ink);
  font-family: var(--mono); font-size: .72rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--mut); }
.colhead .it-side { color: var(--ink); font-weight: 600; }

/* ---------- segment cards ---------- */
.card { background: var(--panel); border: 1px solid var(--rule); border-left: 3px solid transparent;
  border-radius: 8px; padding: .75rem 1.1rem .7rem; margin-bottom: .55rem;
  transition: border-color 120ms ease, box-shadow 120ms ease; }
.card.selected { border-left-color: var(--signal); box-shadow: 0 4px 16px rgba(26,31,29,.09); }
.cardhead { display: flex; align-items: baseline; gap: .7rem; margin-bottom: .45rem; }
.cardhead .id { font-family: var(--mono); font-size: .76rem; color: var(--mut);
  min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.cardhead .uses { font-size: .78rem; color: var(--mut); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; flex: 1; min-width: 0; }
.chip { margin-left: auto; font-family: var(--mono); font-size: .68rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; padding: .18rem .55rem;
  border-radius: 99px; white-space: nowrap; min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; }
.chip.untouched { background: var(--gray-soft); color: var(--mut); }
.chip.confirmed { background: var(--ok-soft); color: var(--ok); }
.chip.edited { background: var(--edit-soft); color: var(--edit); }
.chip.flagged { background: var(--warn-soft); color: var(--warn); }
.chip.linked { background: var(--gray-soft); color: var(--mut); font-weight: 400;
  text-transform: none; letter-spacing: 0; }
.cardbody { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: .2rem 1.6rem;
  align-items: start; }
.cardbody > .cell.en { border-right: 1px solid var(--rule); margin-right: -.8rem;
  padding-right: .8rem; }
.cell { white-space: pre-wrap; min-width: 0; overflow-wrap: anywhere; }
.cell::before { display: block; font-family: var(--mono); font-size: .62rem;
  letter-spacing: .14em; text-transform: uppercase; margin-bottom: .3rem; }
.cell.en { color: #474f4b; background: #f2f3ee; border-radius: 6px; padding: .5rem .65rem; }
.cell.en::before { content: "English · source"; color: #8a9188; }
.cell.it { color: var(--ink); padding: .5rem .65rem .5rem .2rem; }
.cell.it::before { content: "Italiano · your review"; color: var(--edit); }
.actions { display: flex; gap: .4rem; margin-top: .6rem; align-items: center;
  flex-wrap: wrap; min-width: 0; }
.card .actions button { padding: .28rem .7rem; font-size: .84rem; }
.action-err { flex-basis: 100%; width: 100%; font-size: .8rem; }

/* diff + terms + warnings */
ins { background: #d9efe2; color: #1d5c3a; text-decoration: none; border-radius: 2px; }
del { background: #f7dcd7; color: #9c2b1d; border-radius: 2px; }
.diff, .term, ins, del { overflow-wrap: anywhere; }
.term { border-bottom: 1px dotted var(--edit); cursor: help; max-width: 100%; }
.warnings { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; grid-column: 1 / -1; }
.warnings span { background: var(--warn-soft); color: var(--warn);
  border: 1px solid #f3ddc0; border-radius: 5px; padding: .12rem .5rem; font-size: .8rem;
  min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.warnings .more { color: var(--warn); border-color: #f3ddc0; background: transparent;
  padding: .12rem .5rem; font-size: .8rem; }
textarea.editbox { width: 100%; min-height: 9em; max-height: 55vh;
  overflow-y: auto; resize: vertical; }

/* ---------- variant picker ---------- */
.rowbtn { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .7rem;
  border: 1px solid var(--rule); border-radius: 7px; margin: .3rem 0; cursor: pointer;
  background: var(--panel); transition: border-color 120ms ease; width: 100%;
  min-width: 0; max-width: 100%; text-align: left; color: inherit; font: inherit; }
.rowbtn:hover { border-color: var(--mut); }
.rowbtn.chosen { border-color: var(--ok); background: var(--ok-soft); }
.rowbtn > div, .rowbtn > details { flex: 1; min-width: 0; max-width: 100%;
  overflow-wrap: anywhere; }
.rowbtn .kbd { background: var(--gray-soft); border-radius: 4px; padding: .05rem .45rem;
  margin-top: .1rem; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.rowbtn.chosen .kbd { background: #fff; color: var(--ok); }
.group-status { width: fit-content; max-width: 100%; }
.history-row { cursor: default; }
.history-row summary { cursor: pointer; color: var(--mut); font: .78rem var(--mono); }

/* ---------- modal / dual page viewer ---------- */
#modal-root { position: fixed; inset: 0; background: rgba(26,31,29,.6);
  display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal { background: var(--paper); border-radius: 10px; padding: 1rem 1.2rem 1.2rem;
  max-width: 96vw; max-height: 94vh; overflow: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.3); }
.modal h3 { margin: .1rem 0 .7rem; font-family: var(--mono); font-size: .9rem;
  letter-spacing: .06em; text-transform: none; color: var(--ink); }
.pages { display: flex; gap: .9rem; }
.pages > div { flex: 1; min-width: 0; }
.page-wrap { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; }
.page-wrap img { max-height: 80vh; max-width: 100%; width: auto; display: block;
  margin: 0; border: 1px solid var(--rule); background: #fff;
  box-shadow: 0 2px 10px rgba(26,31,29,.08); }
.page-error { margin: 1rem auto; padding: 1rem; width: fit-content; max-width: 100%;
  border: 1px solid var(--rule); border-radius: 6px; color: var(--mut); }
.hl { position: absolute; background: rgba(255,214,0,.45);
  mix-blend-mode: multiply; border-radius: 2px; pointer-events: none; }

/* ---------- tables / progress / admin ---------- */
table.plain { border-collapse: collapse; min-width: 340px; }
table.plain td, table.plain th { border-bottom: 1px solid var(--rule);
  padding: .4rem .6rem; text-align: left; }
table.plain th { font-family: var(--mono); font-size: .72rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--mut); }
h3 { font-family: var(--mono); font-size: .82rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--mut); margin: 1.4rem 0 .6rem; }
