/* PO Results - dark ledger look: warm ink background, amber for "look here". */
:root {
  --bg: #15130f;
  --surface: #1e1b15;
  --surface-2: #28241b;
  --line: #3a3427;
  --text: #ece6d6;
  --muted: #9b937f;
  --amber: #f2b441;
  --amber-bg: rgba(242, 180, 65, 0.22);
  --blue: #5aa9ff;
  --blue-bg: rgba(90, 169, 255, 0.22);
  --green: #6fcf8e;
  --red: #ff6b61;
  --radius: 10px;
  --touch: 46px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 var(--sans); overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2.sub { font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.4em; margin: 8px 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, select, input { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible, .table-wrap:focus-visible, td.cell:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 2px;
}

/* buttons */
.btn {
  min-height: var(--touch); padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  transition: background 120ms, transform 80ms, border-color 120ms;
}
.btn:hover:not(:disabled) { border-color: var(--amber); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--amber); color: #1b1405; border-color: var(--amber); font-weight: 600; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 0.9rem; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-card label, #modal label { display: block; margin: 16px 0 6px; font-size: 0.85rem; color: var(--muted); }
.login-card .btn { width: 100%; margin-top: 16px; }
input[type="password"], input[type="text"] {
  width: 100%; min-height: var(--touch); padding: 0 12px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--line); font-size: 16px; /* 16px stops iOS zoom */
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto;
  gap: 8px 10px; align-items: center; padding: 10px 12px;
  background: rgba(21, 19, 15, 0.96); border-bottom: 1px solid var(--line);
}
.workers { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg { min-height: 42px; padding: 0 12px; border: 0; background: var(--surface); cursor: pointer; font-size: 0.9rem; }
.seg[aria-pressed="true"] { background: var(--amber); color: #1b1405; font-weight: 600; }
.status { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; min-width: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); grid-row: span 2; }
.dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(111, 207, 142, 0.2); }
.dot.offline { background: var(--red); }
.status-main { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-sub { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-danger { color: var(--red); font-weight: 700; }

.banner { margin: 8px 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--amber-bg); border: 1px solid var(--amber); font-size: 0.9rem; }
.picker { padding: 10px 12px 0; }
select {
  width: 100%; min-height: var(--touch); padding: 0 10px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); font-size: 16px;
}

.panel { margin: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; min-width: 0; }
.image-panel { padding: 8px; text-align: center; }
.image-panel img { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; border-radius: 8px; background: #000; }

/* table */
.table-bar { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dirty { color: var(--blue); font-size: 0.85rem; white-space: nowrap; }
.table-wrap { overflow: auto; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; }
table { border-collapse: separate; border-spacing: 0; font: 14px/1.3 var(--mono); width: max-content; min-width: 100%; }
th, td { padding: 0; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); padding: 8px 10px; text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); }
th.rec, td.rec { position: sticky; left: 0; z-index: 3; background: var(--surface-2); text-align: center; min-width: 44px; padding: 0 8px; color: var(--muted); }
th.rec { z-index: 4; }
td.cell { min-width: 64px; min-height: 40px; height: 40px; padding: 0 10px; cursor: text; }
td.cell.empty::after { content: "\00a0"; }
td.flagged { background: var(--amber-bg); box-shadow: inset 0 0 0 1px var(--amber); }
td.unsaved { background: var(--blue-bg); box-shadow: inset 0 0 0 1px var(--blue); }
td.saved-edit { font-style: italic; }
td.ditto { color: var(--muted); }
td.editing { padding: 0; }
td.editing input {
  min-width: 90px; width: 100%; min-height: 40px; border: 0; border-radius: 0; background: var(--bg);
  font: 16px var(--mono); padding: 0 8px; box-shadow: inset 0 0 0 2px var(--amber);
}
td.editing .birth { display: flex; }
td.editing .birth input { min-width: 0; width: 64px; }
td.editing .birth input.year { width: 84px; }

.edit-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.flag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.flag-list button {
  width: 100%; text-align: left; min-height: 42px; padding: 6px 10px; border-radius: 8px;
  background: var(--amber-bg); border: 1px solid transparent; cursor: pointer; font-size: 0.9rem;
}
.flag-list button:hover { border-color: var(--amber); }
.flag-list .none { color: var(--muted); }

/* commands */
.cmd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cmd-grid .btn { min-height: 52px; padding: 0 8px; }
.pickers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; font-size: 0.8rem; color: var(--muted); }
.pickers select { margin-top: 4px; }
.cmd-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.88rem; }
.cmd-log li { padding: 8px 10px; border-radius: 8px; background: var(--bg); border-left: 3px solid var(--muted); overflow-wrap: anywhere; }
.cmd-log li.ok { border-left-color: var(--green); }
.cmd-log li.fail { border-left-color: var(--red); }

.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
  max-width: 480px; margin: 0 auto; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--amber); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  overflow-wrap: anywhere;
}
.toast.fail { border-color: var(--red); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.7); }
.modal-box { width: 100%; max-width: 380px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.modal-box h2 { font-size: 1.15rem; margin-bottom: 8px; }
.modal-box p { margin: 0; overflow-wrap: anywhere; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

@media (min-width: 720px) {
  #app { max-width: 960px; margin: 0 auto; }
  .cmd-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
