[hidden] { display: none !important; }
:root {
  --bg: #f4f6f9; --card: #fff; --ink: #18202a; --muted: #6b7684; --line: #e3e7ec;
  --brand: #115ea3; --brand-2: #0d4a82; --green: #1f8a4c; --red: #c23434; --amber: #b7791f; --purple: #6b46c1;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
code.wrap { display: inline-block; word-break: break-all; }
kbd { font: 11px ui-monospace, monospace; background: rgba(255,255,255,.2); border: 1px solid rgba(0,0,0,.15); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.muted { color: var(--muted); } .small, small { font-size: 12px; } .right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.25; } h3 { font-size: 16px; } h4 { font-size: 14px; margin-top: 1.2em; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: #0f1c2b; color: #c9d3de; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { font-weight: 700; font-size: 17px; color: #fff; padding: 18px 20px; display: flex; gap: 10px; align-items: center; }
.brand.big { color: var(--ink); font-size: 22px; padding: 0 0 6px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; font-size: 16px; }
.sidebar nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav-item { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 8px; color: #c9d3de; margin-bottom: 2px; }
.nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d8b9b; padding: 16px 12px 6px; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .me { color: #fff; display: flex; flex-direction: column; } .sidebar-foot .me small { color: #8fa0b2; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; }
.menu-btn { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; }
.content { padding: 24px 28px; max-width: 1400px; width: 100%; }
.scan-page .content { max-width: none; padding: 16px 20px; }

/* Cards, grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; } .card-head h3 { margin: 0; }
.table-card { padding: 0; overflow: hidden; } .scroll-x { overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; } .grid-2.tight { gap: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.narrow { max-width: 860px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--muted); box-shadow: var(--shadow); }
.stat span { display: block; font-size: 26px; font-weight: 700; color: var(--ink); }
.book-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.book-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); }
.book-card:hover { border-color: var(--brand); text-decoration: none; } .book-card span { color: var(--muted); font-size: 12px; margin-top: 6px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 12px; } .dl dt { color: var(--muted); } .dl dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; } .chip { background: #eef3fa; color: var(--brand-2); padding: 3px 10px; border-radius: 99px; font-size: 12px; }
.list { padding-left: 18px; margin: 0; } .list li { margin-bottom: 6px; }
.danger-zone { border-color: #f1c4c4; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; font-weight: 600; }
.table th, .table td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: 7px 12px; }
.table tr.dim td { opacity: .55; }
.matrix td.center, .matrix th.center { width: 120px; }
.group-row td { background: #f3f6fa; font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.tick { color: var(--green); font-weight: 700; font-size: 16px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .panel label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd6de; border-radius: 7px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(17,94,163,.25); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=range] { padding: 0; border: 0; accent-color: var(--brand); }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; max-height: 260px; overflow: auto; }
.perm-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
legend { font-weight: 600; padding: 0 6px; }
output { font-weight: 400; color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; } .toolbar input, .toolbar select { max-width: 320px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; } .row-actions.right { justify-content: flex-end; } .row-actions.spread { justify-content: space-between; }
form.inline { display: inline; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 7px; border: 1px solid #cfd6de; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: var(--red); border-color: #efc2c2; } .btn-danger:hover { background: #fdf2f2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.2); color: #c9d3de; } .btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-sm { padding: 5px 10px; font-size: 13px; } .btn-xs { padding: 2px 8px; font-size: 12px; } .btn-lg { padding: 11px 20px; font-size: 15px; } .btn-block { width: 100%; }

/* Badges / alerts */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #eef1f5; color: #4a5563; }
.badge-green { background: #e5f5ec; color: var(--green); } .badge-red { background: #fbeaea; color: var(--red); }
.badge-blue { background: #e7f0fa; color: var(--brand); } .badge-amber { background: #fdf3e1; color: var(--amber); } .badge-purple { background: #efe9fb; color: var(--purple); }
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: #ecf8f1; border-color: #bfe5cf; color: #14653a; }
.alert-error { background: #fdf0f0; border-color: #f1c4c4; color: #8e2222; }
.alert-warn { background: #fff8e8; border-color: #f2dca6; color: #7a5410; }
.alert-info { background: #eef5fc; border-color: #c7dcf1; color: #154c7f; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }

/* Modal */
dialog.modal { border: 0; border-radius: 12px; padding: 24px; width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog.modal.wide { width: min(860px, 96vw); }
dialog::backdrop { background: rgba(15,28,43,.45); }

/* Page grid */
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.page-tile { margin: 0; position: relative; }
.page-tile img { width: 100%; aspect-ratio: 3/4; object-fit: contain; background: #eef0f3; border: 1px solid var(--line); border-radius: 6px; display: block; }
.page-tile figcaption { font-size: 12px; text-align: center; margin-top: 4px; font-weight: 600; } .page-tile figcaption small { color: var(--muted); font-weight: 400; }
.page-tile .pick { position: absolute; top: 6px; left: 6px; z-index: 1; width: 18px; height: 18px; }
.pager { display: flex; gap: 8px; justify-content: center; }

/* ---------- Scanner ---------- */
.scanner { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.stage { position: relative; background: #0b1018; border-radius: 12px; overflow: hidden; min-height: 420px; display: grid; place-items: center; }
.stage canvas { width: 100%; height: auto; display: block; max-height: calc(100vh - 230px); object-fit: contain; }
.stage-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #d5dde6; padding: 30px; gap: 8px; }
.stage-empty .muted { color: #8796a7; max-width: 440px; }
.status-pill { position: absolute; top: 14px; right: 14px; background: rgba(10,16,24,.82); color: #fff; padding: 7px 14px; border-radius: 99px; font-weight: 600; display: flex; gap: 8px; align-items: center; font-size: 13px; max-width: 70%; }
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa3ad; flex-shrink: 0; }
.status-pill.ok .dot { background: #3ad07a; } .status-pill.busy .dot { background: #ffcc00; animation: pulse 1s infinite; }
.status-pill.warn .dot { background: #ff9f1a; } .status-pill.error .dot { background: #ff5252; }
@keyframes pulse { 50% { opacity: .3; } }
.settle-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; } .settle-bar i { display: block; height: 100%; width: 0; background: #ffcc00; transition: width .09s linear; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; } @keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.controls { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.next-page { display: flex; align-items: center; gap: 8px; } .next-page label { font-weight: 600; } .next-page input { width: 90px; font-size: 16px; font-weight: 700; text-align: center; }
.meter { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-left: auto; }
.meter > div { position: relative; width: 120px; height: 8px; background: #e6eaef; border-radius: 9px; overflow: hidden; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--brand); width: 0; transition: width .08s; }
.meter b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--red); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; background: #cfd6de; border-radius: 99px; position: relative; transition: .2s; flex-shrink: 0; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); } .switch input:checked + span::after { left: 21px; }
.retake-banner { margin-top: 10px; background: #fff8e8; border: 1px solid #f2dca6; color: #7a5410; padding: 10px 14px; border-radius: 8px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

.panel-col { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 110px); overflow-y: auto; position: sticky; top: 76px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
details.panel > summary { font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.panel > summary::after { content: "▾"; color: var(--muted); } details.panel:not([open]) > summary::after { content: "▸"; }
details.panel[open] > summary { margin-bottom: 4px; }
.seg { display: flex; border: 1px solid #cfd6de; border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 8px; font: inherit; cursor: pointer; } .seg button + button { border-left: 1px solid #cfd6de; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
.crop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.queue-panel { min-height: 160px; } .queue-head { display: flex; justify-content: space-between; align-items: baseline; }
.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.q-item { display: flex; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; border-left: 4px solid #cfd6de; }
.q-item.ok { border-left-color: var(--green); } .q-item.busy { border-left-color: #ffcc00; } .q-item.warn { border-left-color: var(--amber); } .q-item.error { border-left-color: var(--red); background: #fffafa; }
.q-item img { width: 52px; height: 68px; object-fit: contain; background: #eef0f3; border-radius: 4px; flex-shrink: 0; }
.q-body { min-width: 0; font-size: 13px; } .q-status { font-size: 12px; color: var(--muted); word-break: break-word; }
.q-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 12px; }

@media (max-width: 1100px) { .scanner { grid-template-columns: 1fr; } .panel-col { position: static; max-height: none; } }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; } .sidebar.open { left: 0; }
  .menu-btn { display: block; } .grid-2 { grid-template-columns: 1fr; } .content { padding: 16px; } .topbar { padding: 12px 16px; }
  .table { font-size: 13px; } .table th, .table td { padding: 8px 10px; }
}
