:root {
    --ink: #111827;
    --muted: #64748b;
    --paper: #f5f6f8;
    --panel: #ffffff;
    --line: #dfe3e8;
    --navy: #111d35;
    --navy-2: #1d2c4b;
    --gold: #c99a2e;
    --gold-dark: #9b7317;
    --green: #16794f;
    --red: #b42318;
    --amber: #a15c05;
    --shadow: 0 12px 36px rgba(17, 29, 53, .08);
}

* { box-sizing: border-box; }
html { color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; }
a { color: var(--navy-2); }
code, pre, textarea { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
pre { background: #0d1628; color: #e7edf8; padding: 1rem; border-radius: 10px; overflow: auto; max-height: 650px; font-size: .8rem; line-height: 1.55; }
h1, h2 { margin-top: 0; letter-spacing: -.025em; }
h1 { font-size: clamp(1.8rem, 3vw, 2.7rem); margin-bottom: .45rem; }
h2 { font-size: 1.12rem; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .83rem; }
.eyebrow { color: var(--gold-dark); font-weight: 800; font-size: .72rem; letter-spacing: .15em; margin: 0 0 .55rem; }
.topbar { min-height: 68px; background: var(--navy); color: white; padding: 0 max(1rem, calc((100vw - 1220px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 2rem; box-shadow: 0 3px 14px rgba(0,0,0,.16); }
.brand { display: flex; align-items: center; gap: .7rem; color: white; font-weight: 800; text-decoration: none; white-space: nowrap; }
.brand span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--gold); color: var(--navy); }
.brand small { color: #a8b3c8; font-weight: 600; }
.topbar nav { display: flex; align-items: center; gap: 1.15rem; }
.topbar nav a, .link-button { color: #dce3ef; font-weight: 650; font-size: .9rem; text-decoration: none; background: none; border: 0; cursor: pointer; padding: 0; }
.topbar nav a:hover, .link-button:hover { color: white; }
.topbar nav form { margin: 0; }
.main-shell { width: min(1220px, calc(100% - 2rem)); margin: 2rem auto 4rem; }
.auth-page { background: radial-gradient(circle at 20% 15%, #293a5e 0, var(--navy) 36%, #0a1221 100%); }
.auth-shell, .install-shell { width: min(500px, calc(100% - 2rem)); margin: 0 auto; min-height: 100vh; display: grid; place-items: center; padding: 2rem 0; }
.install-shell { width: min(900px, calc(100% - 2rem)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.35rem; box-shadow: var(--shadow); }
.auth-panel { width: 100%; padding: 2rem; }
.install-panel { width: 100%; padding: 2rem; }
.compact { padding: 1.1rem 1.25rem; }
.no-pad { padding: 0; }
.stack { display: grid; gap: 1rem; }
.grid { display: grid; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gap { gap: 1.2rem; }
.align-start { align-items: start; }
label { display: grid; gap: .42rem; color: #334155; font-weight: 700; font-size: .86rem; }
input, select, textarea { width: 100%; border: 1px solid #cbd2dc; border-radius: 9px; padding: .72rem .78rem; background: white; color: var(--ink); font: inherit; font-weight: 500; }
textarea { line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(201,154,46,.18); border-color: var(--gold); }
.button { display: inline-flex; align-items: center; justify-content: center; width: max-content; border: 1px solid transparent; border-radius: 9px; padding: .7rem 1rem; font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; }
.button.primary { background: var(--gold); color: #161d2b; }
.button.primary:hover { background: #d8aa40; }
.button.secondary, .button.tiny { border-color: #c9d0db; background: white; color: var(--navy); }
.button.warning { background: #f5b942; color: #2d2104; }
.button.tiny { font-size: .78rem; padding: .42rem .7rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.35rem; }
.page-head p:last-child { margin-bottom: 0; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin: 1.2rem 0; }
.card { background: linear-gradient(145deg, #fff, #f9fafb); border: 1px solid var(--line); border-radius: 13px; padding: 1.2rem; box-shadow: var(--shadow); }
.card span { display: block; color: var(--muted); font-size: .8rem; font-weight: 750; }
.card strong { display: block; margin-top: .6rem; font-size: 1.9rem; color: var(--navy); overflow-wrap: anywhere; }
.compact-cards .card strong { font-size: 1.15rem; }
.notice, .flash { border-radius: 10px; padding: .85rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.notice.warning, .flash-warning { color: #6c4104; background: #fff7df; border-color: #ead39c; }
.notice.error, .flash-error { color: #7a271a; background: #fff0ed; border-color: #efb7ae; }
.flash-success { color: #075c3a; background: #eaf8f1; border-color: #a7d9bf; }
.flash-info { color: #174c77; background: #edf6ff; border-color: #b7d6ef; }
.requirements { display: flex; flex-wrap: wrap; gap: .55rem; margin: 1.2rem 0; }
.requirement { border-radius: 999px; padding: .38rem .65rem; font-size: .78rem; font-weight: 800; }
.requirement.ok { color: #075c3a; background: #eaf8f1; }
.requirement.bad { color: #7a271a; background: #fff0ed; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .28rem .55rem; font-size: .7rem; font-weight: 850; letter-spacing: .03em; background: #edf0f4; color: #475569; }
.badge.large { padding: .48rem .8rem; font-size: .82rem; }
.badge.good, .state-created, .state-done, .level-info { color: #075c3a; background: #dff5e9; }
.badge.bad, .state-error, .state-identity_collision, .state-unas_sync_conflict, .level-error { color: #8c2017; background: #fde5e1; }
.badge.neutral, .state-new { color: #334155; background: #e9edf2; }
.state-ready { color: #164e80; background: #e1f1ff; }
.state-manual_review, .state-created_review, .state-ambiguous, .state-unas_sync_ambiguous, .level-warning { color: #7a4800; background: #fff0c7; }
.state-sending, .state-syncing_unas { color: #51338c; background: #eee7ff; }
.status-list { display: grid; margin: 0; }
.status-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .72rem 0; border-bottom: 1px solid #edf0f3; }
.status-list div:last-child { border-bottom: 0; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; font-weight: 750; text-align: right; overflow-wrap: anywhere; }
.settings-actions { margin-bottom: 1.2rem; }
.settings-form { gap: 1.2rem; }
.danger-zone { border-color: #e6c26c; }
.check { display: flex; align-items: flex-start; gap: .65rem; }
.check input { width: auto; margin-top: .18rem; }
.filters { display: flex; align-items: flex-end; gap: .75rem; margin-bottom: 1rem; }
.filters label { min-width: 240px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { text-align: left; padding: .85rem 1rem; border-bottom: 1px solid #e7ebef; vertical-align: middle; }
th { color: #475569; background: #f7f8fa; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
td small { display: block; color: var(--muted); margin-top: .25rem; }
tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); text-align: center; padding: 2rem; }
.pagination { display: flex; gap: .4rem; margin-top: 1rem; }
.pagination a { width: 34px; height: 34px; display: grid; place-items: center; background: white; border: 1px solid var(--line); border-radius: 7px; text-decoration: none; }
.pagination a.active { background: var(--navy); color: white; }
.action-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; margin-bottom: 1.2rem; }
.confirm-form { display: flex; align-items: flex-end; gap: .7rem; margin-left: auto; }
.confirm-form label { min-width: 260px; }
details summary { cursor: pointer; font-weight: 750; color: var(--navy); }

.diagnostics-head { align-items: center; }
.diagnostics-scope { line-height: 1.55; }
.diagnostics-migration { margin-bottom: 1rem; }
.diagnostics-migration form { max-width: 560px; }
.diagnostics-empty { text-align: center; padding-block: 2.4rem; }
.diagnostics-summary { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.2rem; border-left: 5px solid var(--line); }
.diagnostics-summary-ok { border-left-color: var(--green); }
.diagnostics-summary-warning { border-left-color: var(--amber); }
.diagnostics-summary-error { border-left-color: var(--red); }
.diagnostics-counts { display: grid; grid-template-columns: repeat(4, minmax(88px, 1fr)); gap: .65rem; }
.diagnostics-count { min-width: 88px; padding: .72rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; text-align: center; }
.diagnostics-count strong { display: block; font-size: 1.45rem; color: var(--navy); }
.diagnostics-count span { display: block; margin-top: .2rem; color: var(--muted); font-size: .72rem; font-weight: 750; }
.diagnostics-count-ok { border-color: #a7d9bf; background: #eefaf4; }
.diagnostics-count-warning { border-color: #ead39c; background: #fff9e9; }
.diagnostics-count-error { border-color: #efb7ae; background: #fff4f1; }
.diagnostics-group { margin-top: 1.2rem; }
.diagnostics-list { display: grid; gap: .75rem; }
.diagnostics-check { border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; padding: 1rem; background: #fbfcfd; }
.diagnostics-check-ok { border-left-color: var(--green); }
.diagnostics-check-warning { border-left-color: var(--amber); }
.diagnostics-check-error { border-left-color: var(--red); }
.diagnostics-check-skipped { border-left-color: #64748b; }
.diagnostics-check-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.diagnostics-check-head > div { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.diagnostics-check-head h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.diagnostics-check-head code { color: var(--muted); font-size: .72rem; overflow-wrap: anywhere; text-align: right; }
.diagnostics-check p { margin: .7rem 0 0; line-height: 1.5; }
.diagnostics-action { color: #334155; padding-top: .65rem; border-top: 1px solid #e7ebef; }
.diagnostics-badge-ok { color: #075c3a; background: #dff5e9; }
.diagnostics-badge-warning { color: #7a4800; background: #fff0c7; }
.diagnostics-badge-error { color: #8c2017; background: #fde5e1; }
.diagnostics-badge-skipped { color: #334155; background: #e9edf2; }

@media (max-width: 880px) {
    .topbar { align-items: flex-start; padding: 1rem; flex-direction: column; }
    .topbar nav { width: 100%; flex-wrap: wrap; }
    .cards, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.two { grid-template-columns: 1fr; }
    .confirm-form { margin-left: 0; width: 100%; flex-direction: column; align-items: stretch; }
    .confirm-form label, .confirm-form .button { width: 100%; }
    .diagnostics-summary { align-items: stretch; flex-direction: column; }
    .diagnostics-counts { width: 100%; }
}

@media (max-width: 560px) {
    .main-shell { width: min(100% - 1rem, 1220px); margin-top: 1rem; }
    .cards, .grid.four { grid-template-columns: 1fr; }
    .page-head { align-items: stretch; flex-direction: column; }
    .page-head .button { width: 100%; }
    .filters { align-items: stretch; flex-direction: column; }
    .filters label, .filters .button { width: 100%; }
    .diagnostics-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .diagnostics-check-head { flex-direction: column; }
    .diagnostics-check-head > div { align-items: flex-start; flex-direction: column; }
    .diagnostics-check-head code { text-align: left; }
}
