:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #1f2933; --muted: #637083; --line: #dde2e8; --accent: #2f5597;
  --accent-ink: #ffffff; --ok: #2e7d32; --warn: #b26a00; --bad: #c62828; --ok-bg: #e8f5e9; --warn-bg: #fff4e0;
  --bad-bg: #fdecea; --nav-w: 190px; --top-h: 52px;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* ---- layout */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top-h); display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--accent); color: var(--accent-ink); z-index: 20; }
.topbar a, .topbar .link { color: var(--accent-ink); }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.quicksearch { flex: 1; max-width: 560px; }
.quicksearch input { width: 100%; padding: 7px 10px; border-radius: 6px; border: 0; font-size: 14px; }
.userbox { display: flex; gap: 12px; align-items: center; white-space: nowrap; font-size: 13px; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 20px; }
.sidebar { position: fixed; top: var(--top-h); bottom: 0; left: 0; width: var(--nav-w); overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line); padding: 10px 0; z-index: 10; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: 8px 18px; color: var(--ink); }
.sidebar a.active, .sidebar a:hover { background: #e8eef8; color: var(--accent); text-decoration: none; }
.nav-section { margin: 14px 18px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
main.with-nav { margin: var(--top-h) 0 0 var(--nav-w); padding: 18px 22px 40px; }
main.bare { padding: 60px 16px; }
@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .sidebar { visibility: hidden; transform: translateX(-100%); transition: transform .15s; box-shadow: 2px 0 8px rgba(0,0,0,.1); }
  body.nav-open .sidebar { visibility: visible; transform: none; }
  main.with-nav { margin-left: 0; padding: 14px 12px 40px; }
  .userbox .who { display: none; }
  .quicksearch { max-width: none; min-width: 0; }
}
@media (max-width: 560px) {
  /* phones: the search box matters more than the title; the menu (☰) is still there */
  .brand { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .userbox { gap: 8px; font-size: 12px; }
  .userbox a[href$="/password"] { display: none; }
}

/* ---- panels */
.skip-link { position: fixed; top: -100px; left: 12px; z-index: 1000; padding: 12px; background: white; color: #17478b; }
.skip-link:focus { top: 8px; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid #2463a3; outline-offset: 3px; }
.task-links { display: flex; flex-wrap: wrap; gap: 10px; }
.task-links a { white-space: normal; padding: 11px 15px; }
@media (max-width: 640px) {
  .task-links { display: grid; grid-template-columns: 1fr; }
  button, .button, select, input:not([type=checkbox]):not([type=radio]) { min-height: 44px; max-width: 100%; }
  .tabs a { padding-top: 12px; padding-bottom: 12px; }
  textarea { max-width: 100%; }
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 0 auto 16px; }
.page-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-bottom: 14px; }
.page-header p { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.cols-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }

/* ---- tiles & pills */
.tile { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); color: var(--ink); }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile-value { font-size: 26px; font-weight: 700; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile.ok .tile-value { color: var(--ok); } .tile.warn .tile-value { color: var(--warn); } .tile.bad .tile-value { color: var(--bad); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #eef1f5; font-size: 12px; white-space: nowrap; }
.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); }
.zone { display: inline-block; padding: 2px 8px; border-radius: 4px; border: 1px solid rgba(0,0,0,.08); font-size: 12px; }

/* ---- tabs (shared) */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 12px; }
.tabs a { padding: 7px 14px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs a.active { background: var(--panel); border-color: var(--line); color: var(--accent); font-weight: 600; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--accent); }
.tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #eef1f5; font-size: 12px; text-align: center; }
tr[data-href] { cursor: pointer; }
.busy-note { display: none; color: var(--warn); margin-left: 8px; }
form.is-busy .busy-note { display: inline; }

/* ---- flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; background: #e8eef8; }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.error { background: var(--bad-bg); color: var(--bad); }

/* ---- tables */
.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-height: 72vh; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { position: sticky; top: 0; background: #f0f3f7; font-weight: 600; white-space: nowrap; z-index: 1; }
table.data tbody tr:hover { background: #f7f9fc; }
table.data td.num, table.data th.num { text-align: right; }
table.kv th { width: 34%; color: var(--muted); font-weight: normal; }
table.kv td, table.kv th { padding: 5px 8px; border-bottom: 1px dashed var(--line); }
.zone-panel { border-left: 6px solid var(--zone, #ddd); }
.note { color: var(--warn); font-size: 12px; }

/* ---- forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid { display: grid; gap: 10px 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c5ccd6; border-radius: 6px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8cbee; border-color: var(--accent); }
input[readonly], select[disabled] { background: #f3f4f6; color: var(--muted); }
button, .button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid #c5ccd6; background: #fff;
  color: var(--ink); cursor: pointer; display: inline-block; white-space: nowrap; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger, .button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.checklist { columns: 3 220px; }
.checklist label { display: block; break-inside: avoid; padding: 2px 0; color: var(--ink); }
.req-badge { font-size: 11px; color: var(--warn); }
.help { font-size: 12px; color: var(--muted); }
.pager { display: flex; gap: 12px; align-items: center; margin: 10px 0; color: var(--muted); }
.pager a { padding: 2px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }

/* ---- touch friendly entry screen (supervisors on phones) */
.entry-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.entry-card select, .entry-card input { font-size: 16px; padding: 10px; }
.entry-card .form-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

@media print {
  .topbar, .sidebar, .actions, .filters, .pager, .flash, form button { display: none !important; }
  main.with-nav { margin: 0; padding: 0; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  table.data th { position: static; }
}
