:root {
    color-scheme: light dark;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --text: #17191c;
    --muted: #68707d;
    --border: #dfe3e8;
    --brand: #c8102e;
    --brand-dark: #840016;
    --ok: #087f5b;
    --warn: #a15c00;
    --danger: #b42318;
}

[data-theme="dark"] {
    --bg: #101214;
    --surface: #171a1f;
    --surface-2: #22262d;
    --text: #f4f6f8;
    --muted: #a9b0ba;
    --border: #303640;
    --brand: #f04438;
    --brand-dark: #c8102e;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
    background: #0b0c0f;
    color: #f7f7f8;
    padding: 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand img { width: 150px; max-width: 100%; height: auto; display: block; }
.nav { display: grid; gap: 4px; }
.nav a, .nav button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 36px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #d8dce3;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
}
.nav a:hover, .nav button:hover, .nav .active { background: #1f232b; color: #fff; }
.nav .nav-logout {
    color: #ffb4ac;
}
.nav .nav-logout:hover {
    background: rgba(240, 68, 56, 0.16);
    color: #fff;
}
.main { padding: 24px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
h1 { font-size: 22px; margin: 0; letter-spacing: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 14px; }
.metrics { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card, .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}
.metric strong { display: block; font-size: 28px; line-height: 1; margin-top: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.field { display: grid; gap: 6px; }
label { font-size: 12px; color: var(--muted); }
input, select, textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    padding: 8px 10px;
}
input[type="checkbox"] {
    accent-color: #cfd5dd;
}
textarea { min-height: 90px; resize: vertical; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font: inherit;
    white-space: nowrap;
}
.btn.primary { border-color: var(--brand); background: var(--brand); color: white; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.ok { border-color: var(--ok); color: var(--ok); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--surface-2); }
.thumb { width: 74px; height: 74px; object-fit: contain; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.thumb-empty { display: inline-grid; place-items: center; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.badge.active, .badge.resolved, .badge.succeeded { color: var(--ok); }
.badge.missing, .badge.pending, .badge.failed { color: var(--danger); }
.badge.queued, .badge.running, .badge.partial { color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.select-col { width: 44px; text-align: center; }
.select-col input { width: 18px; min-height: 18px; cursor: pointer; }
.select-all { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.select-all span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.bulk-toolbar {
    position: sticky;
    top: 12px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}
.bulk-toolbar[hidden] { display: none; }
.notice { margin-bottom: 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.danger-notice { border-color: var(--danger); color: var(--danger); }
.import-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
.sync-status { margin-top: 18px; }
.sync-status-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.sync-status-head strong { font-size: 24px; }
.progress-bar {
    width: 100%;
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.progress-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--brand);
    transition: width 240ms ease;
}
.sync-facts { display: flex; flex-wrap: wrap; gap: 10px 18px; color: var(--muted); margin-bottom: 14px; }
.log-box {
    max-width: 520px;
    max-height: 220px;
    overflow: auto;
    margin: 8px 0 0;
    padding: 10px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    white-space: pre-wrap;
}
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); }
.login-logo { width: 240px; max-width: 100%; height: auto; display: block; margin: 0 auto 18px; }
.inline-check { display: flex; gap: 8px; align-items: center; }
.inline-check input { width: auto; min-height: auto; }
.pagination { margin-top: 14px; }
.pagination nav > div:first-child { display: none; }
.pagination nav > div:last-child { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.pagination nav p { margin: 0; color: var(--muted); font-size: 13px; }
.pagination nav a,
.pagination nav span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
}
.pagination nav span[aria-current="page"] span {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}
.pagination svg {
    width: 16px;
    height: 16px;
}
.theme-fab {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
    width: 42px;
    height: 42px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
    cursor: pointer;
}
.theme-fab:hover {
    border-color: var(--brand);
}
.theme-icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
[data-theme="dark"] .theme-icon-dark,
[data-theme="light"] .theme-icon-light {
    display: none;
}
@media (max-width: 820px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .main { padding: 16px; }
    .topbar { align-items: flex-start; flex-direction: column; }
}
