:root {
  --ink: #14202E;
  --ink-soft: #47566A;
  --ink-faint: #7C8AA0;
  --line: #D8DEE6;
  --line-soft: #E8ECF1;
  --paper: #F3F5F8;
  --card: #FFFFFF;
  --rail: #10192A;
  --rail-ink: #C7D2E0;
  --rail-ink-dim: #7C8AA0;
  --accent: #B4590E;
  --accent-ink: #FFFFFF;
  --accent-soft: #F5E2CE;
  --ok: #2E7D4F;
  --ok-bg: #E3F3E9;
  --warn: #A35C00;
  --warn-bg: #FBEBDA;
  --bad: #B3261E;
  --bad-bg: #FBE3E1;
  --muted-bg: #E9ECF1;
  --focus: #2B5FAD;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 25, 42, .06), 0 4px 16px rgba(16, 25, 42, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E7ECF3; --ink-soft: #9CA9BC; --ink-faint: #6B7789;
    --line: #2A3444; --line-soft: #222B3A; --paper: #0E1420; --card: #161F2E;
    --rail: #0A0F19; --accent: #E08A3E; --accent-ink: #1A1206; --accent-soft: #3A2A1A;
    --ok: #59C486; --ok-bg: #163223; --warn: #E8A14F; --warn-bg: #3A2A17;
    --bad: #F2867E; --bad-bg: #3B1A19; --muted-bg: #1D2635; --focus: #7FA8E0;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── layout ── */
.app { display: flex; min-height: 100vh; }
.rail {
  width: 232px; flex-shrink: 0; background: var(--rail); color: var(--rail-ink);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 8px; }
.brand-name { color: #fff; font-weight: 650; font-size: 15px; letter-spacing: .01em; }
.brand-sub { color: var(--rail-ink-dim); font-size: 12px; margin-top: 2px; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-label { color: var(--rail-ink-dim); font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; padding: 14px 10px 6px; }
.nav a, .nav span.soon {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 7px; text-decoration: none; font-size: 13.5px;
}
.nav a:hover { background: rgba(255,255,255,.05); }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav span.soon { color: var(--rail-ink-dim); cursor: default; }
.nav .tag { font-size: 10.5px; color: var(--rail-ink-dim); border: 1px solid rgba(255,255,255,.12);
  border-radius: 4px; padding: 0 5px; }
.rail-foot { margin-top: auto; font-size: 12px; color: var(--rail-ink-dim); padding: 0 8px; }
.rail-foot a { color: var(--rail-ink); }

.main { flex: 1; min-width: 0; padding: 28px 36px 64px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 22px; }
.eyebrow { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 4px; }
.eyebrow a { color: var(--ink-soft); text-decoration: none; }
.eyebrow a:hover { text-decoration: underline; }
h1 { font-size: 23px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 12px; }
.sub { color: var(--ink-soft); margin: 6px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── cards / tables ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.section { margin-top: 26px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.stat-head { display: flex; justify-content: space-between; align-items: baseline; }
.stat-title { font-weight: 600; }
.stat-link { font-size: 12.5px; color: var(--ink-soft); }
.stat-num { font-size: 32px; font-weight: 650; line-height: 1.1; margin: 10px 0 2px; }
.stat-num small { font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.stat-bar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; background: var(--muted-bg);
  margin: 12px 0 10px; }
.stat-bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-soft); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px;
  vertical-align: 0; }
.bg-ok { background: var(--ok); } .bg-warn { background: var(--warn); } .bg-bad { background: var(--bad); }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tr.row-link { cursor: pointer; }
table.list tr.row-link:hover td { background: var(--paper); }
table.list tr.dim td { color: var(--ink-faint); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-soft); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.progress { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.progress-bar { flex: 1; height: 6px; border-radius: 4px; background: var(--muted-bg); overflow: hidden; }
.progress-bar span { display: block; height: 100%; }
.progress-txt { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }

/* ── pills ── */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.muted { background: var(--muted-bg); color: var(--ink-soft); }
.pill.plain::before { display: none; }
.pills { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── buttons / forms ── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 13px;
  font-size: 13.5px; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.link { border: none; background: none; padding: 4px 6px; color: var(--ink-soft);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: default; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--card); padding: 6px 12px; font-size: 13px; cursor: pointer;
  color: var(--ink-soft); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--muted-bg); color: var(--ink); font-weight: 600; }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); font-size: 14px; }
.field textarea { min-height: 70px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.field input[type=file] { padding: 7px; }

/* ── checklist ── */
.check { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 13px 18px; border-bottom: 1px solid var(--line-soft); }
.check:last-child { border-bottom: none; }
.check-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; }
.check-icon.ok { background: var(--ok-bg); color: var(--ok); }
.check-icon.warn { background: var(--warn-bg); color: var(--warn); }
.check-icon.bad { background: var(--bad-bg); color: var(--bad); }
.check-icon.muted { background: var(--muted-bg); color: var(--ink-faint); }
.check-label { font-weight: 600; }
.check-ref { color: var(--ink-faint); font-size: 12px; font-weight: 400; margin-left: 6px; }
.check-meta { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.check-meta a { color: var(--ink); }
.check-actions { display: flex; gap: 6px; align-items: center; }

.issue-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 18px; border-bottom: 1px solid var(--line-soft); text-decoration: none; }
.issue-row:last-child { border-bottom: none; }
.issue-row:hover { background: var(--paper); }
.issue-name { font-weight: 600; }
.issue-what { color: var(--ink-soft); font-size: 13px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 9px 18px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.activity li:last-child { border-bottom: none; }
.activity .when { color: var(--ink-faint); font-size: 12px; }
.activity .who { font-weight: 600; }

.empty { padding: 32px 20px; text-align: center; color: var(--ink-soft); }
.note { background: var(--accent-soft); color: var(--ink); border-radius: 8px; padding: 10px 14px;
  font-size: 13px; }
.muted-txt { color: var(--ink-soft); }
.small-txt { font-size: 12.5px; }

/* ── policy document ── */
.callout { border-left: 4px solid var(--warn); margin-bottom: 16px; }
.confirm-list { margin: 0; padding-left: 20px; }
.confirm-list li { margin: 4px 0; }
.doc { padding: 26px 34px 30px; }
.doc-facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0 0 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line); font-size: 13px; }
.doc-facts dt { color: var(--ink-soft); font-size: 11.5px; font-weight: 600; }
.doc-facts dd { margin: 0; }
.doc-body { max-width: 76ch; font-size: 14.5px; line-height: 1.6; }
.doc-body h2 { font-size: 16px; margin: 24px 0 8px; }
.doc-body h3 { font-size: 14.5px; margin: 18px 0 6px; }
.doc-body p { margin: 8px 0; }
.doc-body ul, .doc-body ol { padding-left: 22px; }
.doc-body li { margin: 4px 0; }
.doc-body table { border-collapse: collapse; margin: 10px 0 16px; font-size: 13.5px; width: 100%; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.doc-body th { background: var(--paper); font-weight: 600; }
.doc-body .table-scroll { overflow-x: auto; }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; color: var(--ink); }
.check-row input { width: auto; }

/* ── policy editor ── */
.editor { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.editor-pane { display: flex; flex-direction: column; min-height: 560px; }
.pane-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft); font-size: 13px; }
#polBody { flex: 1; border: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 14px 16px; resize: vertical;
  font: 13px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--card); min-height: 520px; }
#polBody:focus { outline: 2px solid var(--focus); outline-offset: -2px; }
.preview { padding: 14px 20px; overflow: auto; max-height: 720px; }

/* ── logs ── */
.log-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.log-card { text-decoration: none; display: block; }
.log-card:hover { border-color: var(--ink-faint); }
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); min-width: 220px; }
.activity.mini li { padding: 4px 0; border: none; font-size: 12.5px; }

/* ── audit readiness ── */
.readiness { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.sec-nav { padding: 6px; position: sticky; top: 16px; }
.sec-btn { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left;
  padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink); }
.sec-btn:hover { background: var(--paper); }
.sec-btn.on { background: var(--muted-bg); font-weight: 600; }
.sec-name { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ritem { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 14px 20px;
  border-top: 1px solid var(--line-soft); align-items: start; }
.ritem-ctl { display: flex; align-items: center; gap: 8px; }
.rtag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 5px; margin-bottom: 5px; }
.t-policy { background: #E1EAF7; color: #2B5FAD; }
.t-records { background: #DDF0EC; color: #0F766E; }
.t-people { background: var(--accent-soft); color: var(--accent); }
.t-physical { background: #EAE7F2; color: #5B3FA8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .t-policy { background: #1C2C42; color: #7FA8E0; }
  :root:not([data-theme="light"]) .t-records { background: #113330; color: #5FC9B8; }
  :root:not([data-theme="light"]) .t-physical { background: #241F38; color: #A794D9; }
}
.auto-tag { font-size: 10.5px; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.item-note { width: 100%; margin-top: 8px; border: 1px dashed var(--line); border-radius: 7px; background: transparent;
  padding: 6px 9px; font-size: 13px; resize: none; overflow: hidden; }
.item-note:focus { border-style: solid; background: var(--card); }
.seg.small button { padding: 5px 9px; font-size: 12px; }
.seg button.st-ready { background: var(--ok-bg); color: var(--ok); }
.seg button.st-progress { background: var(--warn-bg); color: var(--warn); }
.seg button.st-pending { background: var(--bad-bg); color: var(--bad); }
.seg button.st-na { background: var(--muted-bg); color: var(--ink-soft); }

/* auditor (read-only) mode: the server rejects changes; hide the controls */
.ro-banner { background: var(--accent); color: var(--accent-ink); text-align: center; font-size: 13px;
  font-weight: 600; padding: 6px 12px; }
.readonly .btn.primary, .readonly [data-upload], .readonly [data-edit], .readonly [data-archive],
.readonly #editEntity, .readonly #uploadAny, .readonly #syncBtn, .readonly #addVehicle, .readonly #addDriver,
.readonly .modal-foot button[type=submit], .readonly .modal-foot [data-danger], .readonly #auditorAccess,
.readonly .callout p, .readonly #editPolicy { display: none !important; }

/* ── modal / toast ── */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: grid;
  place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 640px;
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { padding: 18px 22px 0; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 4px 0 0; color: var(--ink-soft); font-size: 13px; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 8px;
  border-top: 1px solid var(--line-soft); }
.form-error { color: var(--bad); font-size: 13px; margin-top: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink);
  color: var(--paper); padding: 10px 16px; border-radius: 8px; font-size: 13.5px; z-index: 60;
  box-shadow: var(--shadow); }

/* ── login ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 32px 30px; }
.login-card h1 { font-size: 20px; }
.login-card .sub { margin-bottom: 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }
.login-error { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 9px 12px;
  font-size: 13px; margin-bottom: 14px; }

/* ── responsive ── */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .rail { width: 100%; height: auto; position: static; padding: 14px 16px; gap: 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-label, .rail-foot, .nav span.soon { display: none; }
  .main { padding: 20px 16px 48px; }
  .grid-2, .form { grid-template-columns: 1fr; }
  .check { grid-template-columns: 26px minmax(0, 1fr); }
  .check-actions { grid-column: 2; }
  .issue-row { grid-template-columns: 1fr; gap: 4px; }
  .doc { padding: 18px 16px; }
  .readiness, .editor { grid-template-columns: 1fr; }
  .editor-pane { min-height: 0; }
  .sec-nav { position: static; }
  .ritem { grid-template-columns: 1fr; }
  .doc-body { overflow-x: auto; }
  .hide-sm { display: none; }
}
