:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: #0e1b26;
  --panel-2: #132331;
  --line: #263c4b;
  --text: #e8f1f5;
  --muted: #91a6b3;
  --teal: #46d6c5;
  --teal-dark: #123f41;
  --amber: #ffbd5b;
  --danger: #ff776f;
  --shadow: 0 16px 45px rgba(0, 0, 0, .28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; scrollbar-gutter: stable; }
body { min-height: 100%; }
body { margin: 0; background: radial-gradient(circle at 18% 0%, #102b36 0, transparent 32rem), var(--bg); color: var(--text); }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-shell { width: min(100%, 430px); }
.login-panel { background: rgba(14, 27, 38, .94); border: 1px solid var(--line); border-radius: 22px; padding: 38px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--teal); color: #05221f; font-weight: 900; font-size: 20px; }
.eyebrow { color: var(--teal); letter-spacing: .18em; font-weight: 800; font-size: 11px; margin: 28px 0 6px; }
h1 { font-size: clamp(28px, 6vw, 42px); line-height: 1.05; margin: 0; letter-spacing: -.04em; }
.muted { color: var(--muted); line-height: 1.6; }
.login-form { display: grid; gap: 12px; margin-top: 28px; }
.login-form label, .filter-form label { font-size: 13px; color: var(--muted); font-weight: 700; }
input[type="password"], select { width: 100%; border: 1px solid var(--line); background: #07131c; color: var(--text); border-radius: 10px; padding: 12px 14px; outline: none; }
input[type="password"]:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(70, 214, 197, .14); }

.button { min-height: 38px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--text); cursor: pointer; font-weight: 750; font-size: 13px; background: transparent; transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .38; cursor: not-allowed; transform: none; }
.button.primary { background: var(--teal); color: #05221f; }
.button.secondary { background: var(--panel-2); border-color: var(--line); }
.button.ghost { border-color: var(--line); color: #c6d5dc; }
.button.restore { background: var(--amber); color: #2e1a00; }
.button.approve { background: var(--teal); color: #05221f; }
.button.danger { background: var(--danger); color: #2a0604; }
.button.wide { width: 100%; margin-top: 6px; }

.topbar { min-height: 68px; padding: 11px 22px; border-bottom: 1px solid var(--line); background: rgba(7, 16, 24, .88); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 30; backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-copy { display: grid; }
.brand-copy strong { font-size: 16px; }
.brand-copy span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-actions form { margin: 0; }
.settings-button { background: var(--teal); color: #05221f; }
.workspace { width: min(100%, 1800px); margin: 0 auto; padding: 22px; }
.section-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab { padding: 10px 16px; color: var(--muted); border-radius: 10px; display: flex; align-items: center; gap: 9px; font-weight: 750; }
.tab b { background: #263d48; color: var(--text); border-radius: 999px; padding: 2px 8px; font-size: 11px; }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.tab.active::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 12px var(--teal); }
.sub-tabs { display: flex; gap: 6px; margin: -8px 0 14px; }
.sub-tab { padding: 7px 12px; border: 1px solid transparent; border-radius: 8px; color: var(--muted); font-size: 12px; font-weight: 750; }
.sub-tab.active { color: var(--teal); border-color: var(--line); background: var(--panel); }

.task-status-panel { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.status-metric, .refresh-control { min-width: 0; border: 1px solid var(--line); border-radius: 11px; background: rgba(14, 27, 38, .94); padding: 10px 12px; }
.status-metric { display: grid; gap: 3px; }
.status-metric span, .refresh-control label { color: var(--muted); font-size: 11px; font-weight: 750; white-space: nowrap; }
.scan-count-card > span { white-space: normal; }
.status-metric strong { font-size: 18px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-metric small, .refresh-control small { min-height: 15px; color: #708895; font-size: 10px; line-height: 1.45; }
.audit-summary-card { grid-column: span 2; grid-template-columns: .8fr 2.2fr; gap: 0; padding: 0; overflow: hidden; }
.audit-summary-section { min-width: 0; display: grid; align-content: start; gap: 3px; padding: 10px 12px; }
.audit-summary-section + .audit-summary-section { border-left: 1px solid var(--line); }
.audit-summary-section.audit-metric small { overflow: visible; white-space: normal; line-height: 1.45; }
.audit-total-values { display: flex; align-items: baseline; gap: 7px; }
.audit-total-values span { color: var(--text); font-size: 18px; font-weight: 800; }
.audit-total-values i { color: #59717e; font-style: normal; font-weight: 500; }
.refresh-control { display: grid; grid-template-columns: minmax(76px, 1fr) auto auto; align-items: center; gap: 7px; }
.refresh-control label { grid-column: 1 / -1; }
.refresh-control input { min-width: 76px; width: 100%; height: 38px; border: 1px solid var(--line); background: #07131c; color: var(--text); border-radius: 9px; padding: 7px 10px; outline: none; }
.refresh-control input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(70, 214, 197, .14); }
.refresh-control small { grid-column: 1 / -1; }
.control-strip, .batch-bar { border: 1px solid var(--line); background: rgba(14, 27, 38, .94); border-radius: 12px; padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.filter-form { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; min-width: 0; }
.filter-form label { white-space: nowrap; flex: 0 0 auto; }
.filter-form select { width: auto; min-width: 280px; padding: 8px 34px 8px 11px; }
.filter-form input[type="search"] { width: clamp(220px, 24vw, 360px); min-width: 220px; border: 1px solid var(--line); background: #07131c; color: var(--text); border-radius: 10px; padding: 8px 11px; outline: none; }
.filter-form input[type="search"]::placeholder { color: #637b88; }
.filter-form input[type="search"]:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(70, 214, 197, .14); }
.filter-form .button { white-space: nowrap; flex: 0 0 auto; }
.multi-version-count { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #0a1720; font-size: 12px; white-space: nowrap; }
.multi-version-count strong { color: #a8d8ff; font-size: 13px; }
.view-switch { display: flex; gap: 5px; }
.batch-bar { position: sticky; top: 80px; z-index: 20; justify-content: flex-start; box-shadow: 0 10px 25px rgba(0,0,0,.24); }
.check-label { color: #c9d7dd; font-size: 13px; display: inline-flex; align-items: center; gap: 7px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--teal); }
#selected-count { font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); padding-left: 12px; }
.review-actions { display: flex; gap: 7px; margin-left: auto; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.image-card { min-width: 0; position: relative; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; transition: transform .18s ease, border-color .18s ease; }
.image-card:hover { transform: translateY(-2px); border-color: #3b5a69; }
.image-frame { display: block; aspect-ratio: 1 / 1; background: #03080c; overflow: hidden; }
.image-frame img { width: 100%; height: 100%; display: block; object-fit: contain; transition: transform .25s ease; }
.image-card:hover .image-frame img { transform: scale(1.025); }
.card-check { position: absolute; left: 8px; top: 8px; z-index: 5; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: rgba(3, 8, 12, .82); border: 1px solid rgba(255,255,255,.18); cursor: pointer; }
.card-check input { margin: 0; }
.card-meta { padding: 9px 10px 11px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.label-row strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.label-row span { color: var(--amber); font: 750 12px ui-monospace, monospace; }
.card-meta p { margin: 7px 0; color: #b2c2ca; font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta p.expected-key, .key-cell .expected-key { display: block; color: var(--amber); }
.card-meta small { color: #708895; font-size: 10px; }
.meta-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.storage-times { display: grid; gap: 2px; margin: 6px 0; }
.storage-times small:first-child { color: #a8efb5; }
.meta-footer a, .original-link { color: var(--teal); font-size: 11px; font-weight: 750; white-space: nowrap; }
.item-links { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; }
.item-links form { margin: 0; }
.link-button { appearance: none; border: 0; padding: 0; background: transparent; color: var(--amber); cursor: pointer; font: inherit; font-size: 11px; font-weight: 750; }
.link-button:hover { color: #ffd38d; }
.history-restore-all-form { margin-left: auto; }
.restore-origin { color: #55d9c9; }
.table-origin { display: block; margin-top: 4px; white-space: nowrap; }
.version-badge { display: inline-flex; align-items: center; border: 1px solid #355263; border-radius: 999px; padding: 2px 7px; color: #a8d8ff; background: rgba(92,171,238,.10); font: 750 11px ui-monospace, monospace; }
.history-heading { border: 1px solid var(--line); background: rgba(14,27,38,.94); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.history-heading > div { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; gap: 3px 12px; }
.history-heading strong { color: var(--teal); }
.history-heading small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px ui-monospace, monospace; }
.history-heading span { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; text-align: left; color: var(--muted); background: #10202b; padding: 10px 12px; white-space: nowrap; }
.sortable-heading { display: inline-flex; align-items: center; gap: 5px; color: #b9cbd4; }
.sortable-heading:hover { color: var(--teal); }
.sortable-heading span { display: inline-block; min-width: 10px; color: var(--teal); font-weight: 900; }
td { padding: 8px 12px; border-top: 1px solid #1c303d; vertical-align: middle; }
tr:hover td { background: #10212c; }
.table-thumb { width: 58px; height: 50px; object-fit: contain; display: block; border-radius: 6px; background: #020608; }
.tag { display: inline-block; background: var(--teal-dark); color: #8df0e4; border-radius: 999px; padding: 4px 8px; white-space: nowrap; }
.key-cell { max-width: 520px; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: #b8c9d0; }
.select-column { width: 48px; }
.selection-controls-hidden .card-check,
.selection-controls-hidden .select-column,
.selection-controls-hidden .selection-cell { display: none; }

.alert { border-radius: 10px; padding: 11px 13px; margin: 12px 0; font-size: 13px; }
.alert.error { background: rgba(255,119,111,.1); border: 1px solid rgba(255,119,111,.4); color: #ffc1bd; }
.alert.success { background: rgba(70,214,197,.1); border: 1px solid rgba(70,214,197,.35); color: #9bf1e7; }
.confirm-dialog { width: min(92vw, 480px); color: var(--text); background: rgba(14,27,38,.98); border: 1px solid #355263; border-radius: 16px; padding: 0; box-shadow: 0 24px 80px rgba(0,0,0,.58); }
.confirm-dialog::backdrop { background: rgba(2,8,12,.72); backdrop-filter: blur(4px); }
.confirm-dialog form { padding: 22px; display: grid; grid-template-columns: 42px 1fr; gap: 13px 15px; }
.confirm-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #2a0604; background: var(--danger); font-size: 22px; font-weight: 900; }
.confirm-copy h2 { margin: 1px 0 7px; font-size: 18px; }
.confirm-copy p { margin: 0; color: #b9c9d0; font-size: 13px; line-height: 1.65; overflow-wrap: anywhere; }
.confirm-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 9px; margin-top: 7px; }
.settings-dialog { width: min(92vw, 520px); color: var(--text); background: rgba(14,27,38,.99); border: 1px solid #355263; border-radius: 18px; padding: 0; box-shadow: 0 24px 80px rgba(0,0,0,.58); }
.settings-dialog::backdrop { background: rgba(2,8,12,.72); backdrop-filter: blur(4px); }
.settings-panel { padding: 22px; }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.settings-heading span { color: var(--teal); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.settings-heading h2 { margin: 4px 0 0; font-size: 21px; }
.dialog-close { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: #07131c; color: var(--muted); cursor: pointer; font-size: 21px; }
.settings-section { padding-top: 18px; }
.settings-section label { display: block; font-size: 14px; font-weight: 800; }
.settings-section p { margin: 6px 0 14px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.settings-field { display: grid; grid-template-columns: minmax(90px, 1fr) auto auto auto; align-items: center; gap: 8px; }
.settings-field input { min-width: 90px; height: 38px; border: 1px solid var(--line); background: #07131c; color: var(--text); border-radius: 9px; padding: 7px 10px; outline: none; }
.settings-field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(70,214,197,.14); }
.settings-field span, .settings-section small { color: var(--muted); font-size: 12px; }
.settings-section small { display: block; margin-top: 12px; }
.settings-service-section { margin-top: 18px; border-top: 1px solid var(--line); }
.settings-priority-form { display: block; }
.settings-priority-form code { color: #a8efb5; }
.settings-priority-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.settings-priority-field select { min-width: 0; padding-block: 9px; }
.empty-state { min-height: 360px; border: 1px dashed var(--line); border-radius: 14px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state div { color: var(--teal); font-size: 30px; }
.empty-state h2 { color: var(--text); margin: 8px 0 0; }
.empty-state p { margin: 8px 0; }
.pagination { margin: 18px 0 5px; display: flex; justify-content: center; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.pagination-summary, .page-size-form, .page-numbers { display: inline-flex; align-items: center; gap: 5px; }
.page-size-form select { width: 96px; min-width: 96px; padding: 7px 36px 7px 12px; }
.page-arrow, .page-number { min-width: 25px; height: 25px; padding: 0 5px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 5px; color: #aebdc5; }
.page-arrow:hover, .page-number:hover { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.page-arrow.disabled { opacity: .28; }
.page-number.current { color: #08171e; background: var(--teal); border-color: var(--teal); font-weight: 850; }
.page-ellipsis { padding: 0 3px; color: #6f8490; }
.queue-status { display: inline-block; padding: 4px 8px; border-radius: 999px; white-space: nowrap; font-weight: 750; }
.status-queued { color: #ffe0a8; background: rgba(255,189,91,.14); }
.status-processing { color: #9bf1e7; background: rgba(70,214,197,.14); }
.status-running { color: #9bf1e7; background: rgba(70,214,197,.14); }
.status-completed { color: #a8efb5; background: rgba(77,205,105,.14); }
.status-failed { color: #ffc1bd; background: rgba(255,119,111,.14); }
.status-pass, .status-restored { color: #a8efb5; background: rgba(77,205,105,.14); }
.status-review, .status-pending { color: #ffe0a8; background: rgba(255,189,91,.14); }
.status-renamed, .status-blocked { color: #ffc1bd; background: rgba(255,119,111,.14); }
.status-unsupported, .status-superseded { color: #b8c9d0; background: rgba(145,166,179,.14); }
.status-missing { color: #ffc1bd; background: rgba(255,119,111,.14); }
.status-waiting-scan { color: #a8d8ff; background: rgba(92,171,238,.14); }
.status-waiting-rescan { color: #ffc1bd; background: rgba(255,119,111,.14); }
.batch-cell { max-width: 180px; font: 11px ui-monospace, monospace; word-break: break-all; color: var(--muted); }
.queue-error { max-width: 320px; color: #ffc1bd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-clear-form { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.queue-clear-form small { color: var(--muted); }
.batch-restore-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.batch-restore-heading > div { display: grid; gap: 3px; }
.batch-restore-heading small { color: var(--muted); }
.restore-all-form, .restore-batch-form { display: flex; align-items: center; gap: 9px; }
.quarantine-batches td:last-child { white-space: nowrap; }

.focus-mode .topbar { min-height: 48px; padding-block: 5px; }
.focus-mode .brand-copy, .focus-mode .section-tabs { display: none; }
.focus-mode .workspace { max-width: none; padding: 8px; }
.focus-mode .control-strip { margin-bottom: 7px; padding-block: 5px; }
.focus-mode .batch-bar { top: 56px; margin-bottom: 7px; padding-block: 5px; }
.focus-mode .image-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 5px; }
.focus-mode .image-card { border-radius: 7px; }
.focus-mode .card-meta { padding: 6px 7px; }
.focus-mode .card-meta small { display: none; }

@media (max-width: 760px) {
  .topbar { align-items: flex-start; gap: 12px; }
  .brand-copy { display: none; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .workspace { padding: 12px; }
  .section-tabs { overflow-x: auto; }
  .task-status-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .audit-summary-card { grid-column: 1 / -1; grid-template-columns: 1fr; }
  .audit-summary-section + .audit-summary-section { border-top: 1px solid var(--line); border-left: 0; }
  .audit-summary-state { grid-column: auto; }
  .refresh-control { grid-column: 1 / -1; }
  .control-strip, .batch-bar { align-items: stretch; flex-direction: column; }
  .filter-form { display: grid; grid-template-columns: 1fr auto; }
  .filter-form label { grid-column: 1 / -1; }
  .filter-form select { min-width: 0; }
  .filter-form input[type="search"] { width: 100%; min-width: 0; }
  .view-switch { width: 100%; }
  .view-switch .button { flex: 1; }
  .batch-bar { top: 76px; }
  .batch-bar .restore { margin-left: 0; }
  .review-actions { width: 100%; margin-left: 0; display: grid; grid-template-columns: repeat(3, 1fr); }
  .restore-all-form, .restore-batch-form { align-items: stretch; flex-direction: column; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 7px; }
  .pagination { flex-wrap: wrap; }
  .pagination-summary { flex-wrap: wrap; justify-content: center; }
  .card-meta small { display: none; }
}

@media (min-width: 761px) and (max-width: 1400px) {
  .task-status-panel { grid-template-columns: repeat(3, minmax(105px, 1fr)); }
  .audit-summary-card { grid-column: span 3; }
  .refresh-control { grid-column: span 3; }
}

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #111; }
  .top-actions, .section-tabs, .control-strip, .batch-bar, .pagination, .card-check { display: none !important; }
  .topbar { position: static; background: #fff; border-color: #bbb; }
  .workspace { max-width: none; padding: 10px; }
  .image-grid { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .image-card, .table-wrap { break-inside: avoid; background: #fff; border-color: #bbb; color: #111; }
  .card-meta p, .card-meta small, td, th { color: #333; }
}
