:root {
  --bg: #eef0ee; --surface: #fff; --ink: #1d2327; --muted: #5f6b70; --line: #d9dedc; --line-soft: #e9ecea;
  --accent: #1f4e5f; --accent-ink: #fff; --accent-soft: #e3eef1; --hover: #f3f6f5; --danger: #a3302a;
  --warn-bg: #fff6df; --warn-ink: #6b4e00; --ok: #2f6b3a; --radius: 10px;
  --shadow: 0 1px 2px rgba(20,30,35,.06), 0 2px 8px rgba(20,30,35,.04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: Consolas, "SF Mono", Menlo, monospace; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .linkish:focus-visible, .tab:focus-visible, .queue-list button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.icon { width: 34px; padding: 0; font-weight: 700; font-family: Georgia, serif; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: default; pointer-events: none; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
input:not([type=checkbox]):not([type=file]), select, textarea { width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); }
label > input, label > textarea, label > select { margin-top: 4px; font-weight: 400; color: var(--ink); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 13px; }
.form-error { color: var(--danger); margin: 8px 0 0; font-size: 13px; }
.form-error:empty { display: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px 16px; }
.notice { margin: 0; padding: 8px 12px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; border-radius: 7px; }
.notice:empty { display: none; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 30px 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 21px; margin: 12px 0 4px; }
.step { display: grid; gap: 14px; }
.step p { margin: 0; }
.steps { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 13.5px; }
.secret { display: block; margin: 6px 0; padding: 8px 10px; background: var(--hover); border: 1px dashed var(--line); border-radius: 7px; font-size: 15px; letter-spacing: .06em; word-break: break-all; user-select: all; }
.secret.big { font-size: 18px; text-align: center; }
.brand-mark { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand-mark.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }

/* app frame */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 600; font-size: 15px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; }
.tab { position: relative; border: 0; background: none; padding: 8px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tab:hover { background: var(--hover); color: var(--ink); }
.tab[aria-current=page] { background: var(--accent-soft); color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.user { position: relative; margin-left: auto; }
.menu { position: absolute; right: 0; top: 36px; z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 180px; padding: 4px; display: grid; }
.menu button { text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--hover); }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(360px, 460px) minmax(0, 1fr); gap: 14px; padding: 14px; }
.left { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }

/* search */
.search { padding: 14px 16px 16px; }
.search-head, .results-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.fields.one { grid-template-columns: 1fr; }
.field.full { grid-column: 1 / -1; }
.field label { margin-bottom: 4px; }
.ft { margin-top: 10px; }
.range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; color: var(--muted); }
.search-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.results { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 0 0; }
.results .results-head { padding: 0 16px; }
.table-wrap { flex: 1; min-height: 100px; overflow: auto; border-top: 1px solid var(--line-soft); }
.table-wrap.tall { max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { position: sticky; top: 0; background: #f7f8f7; text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
#results-table tbody tr { cursor: pointer; }
#results-table tbody tr:hover { background: var(--hover); }
#results-table tbody tr.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; }
#more-btn { margin: 8px 12px 12px; }

/* viewer */
.viewer { min-height: 0; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.viewer-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.viewer-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.viewer-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.doc-title { min-width: 0; flex: 1; }
.doc-title h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { color: var(--muted); font-size: 12.5px; }
.toolbar { display: flex; gap: 6px; }
.back { display: none; }
.details { margin: 0; padding: 10px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 18px; border-bottom: 1px solid var(--line); background: #fafbfa; }
.details dt { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.details dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame-wrap, .review-frame { position: relative; flex: 1; min-height: 0; background: #525659; }
iframe { width: 100%; height: 100%; border: 0; display: block; }

/* review */
.queue { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-top: 14px; }
.queue .results-head { padding: 0 16px; }
.queue select { width: auto; height: 30px; }
.queue-list { list-style: none; margin: 0; padding: 0; }
.queue-list button { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--line-soft); background: none; cursor: pointer; }
.queue-list button:hover { background: var(--hover); }
.queue-list button.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.queue-list .q-type { font-weight: 600; }
.queue-list .q-reason { grid-column: 1 / -1; color: var(--warn-ink); font-size: 12.5px; }
.queue-list .q-when { color: var(--muted); font-size: 12px; }
.review-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.review-form { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; overflow: auto; border-left: 1px solid var(--line); }
.sugg { display: grid; gap: 6px; }
.sugg button { text-align: left; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px 10px; cursor: pointer; }
.sugg button:hover { border-color: var(--accent); background: var(--accent-soft); }
.sugg b { display: block; }
.sugg small { color: var(--muted); }
.tag-ok { color: var(--ok); font-weight: 600; }
.row-actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 4px; }

/* admin */
.admin { flex: 1; overflow: auto; padding: 14px; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 14px; }
.admin-grid .wide { grid-column: 1 / -1; }
.admin .table-wrap { max-height: 360px; }
#users-table tbody tr { cursor: pointer; }
#users-table tbody tr:hover { background: var(--hover); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; background: var(--hover); border: 1px solid var(--line); margin-right: 3px; }
.pill.warn { background: var(--warn-bg); border-color: #f0e2b8; color: var(--warn-ink); }
.pill.bad { background: #fbe9e7; border-color: #f2c4bf; color: var(--danger); }
.status-box { display: grid; gap: 10px; font-size: 13px; }
.status-box dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.status-box dd { margin: 0; font-weight: 600; text-align: right; }
.status-box h3 { margin: 6px 0 2px; font-size: 12.5px; color: var(--muted); }
.status-box ul { margin: 0; padding-left: 16px; }
.sub-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.file-btn { cursor: pointer; font-size: 13px; color: var(--ink); font-weight: 500; }
.audit-filter { display: flex; gap: 6px; }
.audit-filter input { height: 28px !important; width: 140px !important; font-size: 13px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,28,32,.4); }
dialog form { padding: 22px; display: grid; gap: 12px; }
dialog h2 { font-size: 18px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
fieldset.access { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 10px; }
fieldset.access legend { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 0 4px; }
fieldset.access td, fieldset.access th { padding: 5px 6px; text-align: center; }
fieldset.access td:first-child, fieldset.access th:first-child { text-align: left; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2327; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .brand-title { display: none; }
  .app { height: auto; min-height: 100%; }
  .workspace { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .fields { grid-template-columns: 1fr; }
  .results { flex: none; }
  .table-wrap { max-height: 60vh; }
  .viewer { position: fixed; inset: 0; z-index: 20; border-radius: 0; border: 0; display: none; }
  body.viewing .viewer { display: flex; }
  .back { display: inline-flex; }
  .toolbar { width: 100%; }
  .toolbar .btn:not(.icon) { flex: 1; }
  .review-body { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .review-form { border-left: 0; border-top: 1px solid var(--line); }
  .admin { padding: 12px 16px; }
  .admin-grid { grid-template-columns: minmax(0, 1fr); }
  .audit-filter { flex-wrap: wrap; }
  .search-foot .hint { display: none; }
}
