:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1c2230;
    --muted: #677085;
    --line: #e1e4ea;
    --accent: #2f5bd3;
    --accent-soft: #e8eefc;
    --ok: #1f8a4c;
    --warn: #a86400;
    --error: #b42318;
    --s0: #d8f0e0;
    --s1: #fbf0c4;
    --s2: #fbd9b4;
    --s3: #f6c3bd;
    --c0: #2f5bd3;
    --c1: #19a0a0;
    --c2: #8e5bd3;
    --c3: #d38a2f;
    --c4: #d3456a;
    --c5: #5b8a2f;
    color-scheme: light;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h4 { margin: 6px 0; font-size: .9rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: #eef0f4; padding: 1px 4px; border-radius: 4px; }
code.big { font-size: 1.15rem; padding: 3px 8px; }
pre { white-space: pre-wrap; word-break: break-word; background: #f7f8fa; border: 1px solid var(--line); border-radius: 6px; padding: 10px; max-height: 480px; overflow: auto; font-size: .85rem; }
pre.template { max-height: 640px; }

.shell { min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: #1c2230; color: #fff; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .02em; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #c9cfdc; padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #2c3446; color: #fff; text-decoration: none; }
.topbar .logout { display: flex; align-items: center; gap: 8px; color: #c9cfdc; margin: 0; }
.topbar .logout .link { color: #c9cfdc; }

.content { padding: 22px 24px 60px; max-width: 1500px; margin: 0 auto; }
.content.narrow { max-width: 420px; padding-top: 80px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 14px 0; }
details.card > summary { cursor: pointer; }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--error); }
.warn { color: var(--warn); }

button, .button {
    display: inline-block; border: 0; border-radius: 7px; background: var(--accent); color: #fff;
    padding: 7px 14px; font: inherit; cursor: pointer; line-height: 1.3;
}
.button:hover { text-decoration: none; filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: default; }
button.secondary, .button.secondary { background: #e7eaf0; color: var(--text); }
button.danger, .link.danger { color: var(--error); }
button.secondary.danger { background: #fbe9e7; }
button.link { background: none; color: var(--accent); padding: 0 4px; }
button.link:disabled { color: var(--muted); }

label { display: block; margin: 8px 0; }
input, select, textarea {
    font: inherit; border: 1px solid #c9ceda; border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text);
}
label > input, label > select { display: block; width: 100%; margin-top: 4px; }
textarea { width: 100%; resize: vertical; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
input.tiny, select.tiny { width: 70px; display: inline-block; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 4px 14px 4px 0; }
.check input { width: auto; margin: 0; }
.check.disabled { color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; flex-direction: column; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.inline-form label { margin: 0; }
.inline-form label > input, .inline-form label > select { display: inline-block; width: auto; margin: 0 0 0 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }

table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { background: #f0f2f6; font-weight: 600; font-size: .82rem; color: #3c4459; }
.grid.compact th, .grid.compact td { padding: 4px 8px; }
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover { background: #f8f9fc; }
.grid tr.open { background: var(--accent-soft); }
.grid tr.details > td { background: #fafbfd; }
.grid tr.unpaired { background: #fff8ec; }
.grid tr.highlight { background: #fff8ec; }

table.matrix { border-collapse: collapse; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 4px 10px; text-align: center; }
.matrix th { background: #f0f2f6; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e7eaf0; }
.badge.running { background: var(--accent-soft); color: var(--accent); }
.badge.completed { background: #dcf2e4; color: var(--ok); }
.badge.failed { background: #fbe1de; color: var(--error); }
.badge.waitingforwindow, .badge.waitingforlogin { background: #fdf0d9; color: var(--warn); }
.badge.paused, .badge.cancelled { background: #eceef2; color: var(--muted); }

.score { display: inline-block; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 5px; font-weight: 700; font-size: .85rem; background: #eceef2; }
.score.s0 { background: var(--s0); }
.score.s1 { background: var(--s1); }
.score.s2 { background: var(--s2); }
.score.s3 { background: var(--s3); }

.label { display: inline-block; width: 20px; text-align: center; border-radius: 4px; font-weight: 700; background: #eceef2; }
.label.lA { background: var(--s0); }
.label.lB { background: var(--s1); }
.label.lC { background: var(--s2); }
.label.lD { background: var(--s3); }
.counts { color: var(--muted); font-size: .8rem; margin-left: 4px; }

.chip { display: inline-block; padding: 3px 9px; margin: 2px 4px 2px 0; border-radius: 999px; background: var(--accent-soft); }

.codex-summary { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.window { white-space: nowrap; }
.meter { display: inline-block; width: 120px; height: 8px; background: #e7eaf0; border-radius: 4px; overflow: hidden; vertical-align: middle; }
.meter.wide { width: 100%; max-width: 480px; }
.meter > div { height: 100%; background: var(--accent); }
.progress { display: flex; gap: 12px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.run-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.run-status .progress { width: 100%; }
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 6px 18px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tab { background: #eceef2; color: var(--text); border-radius: 6px; padding: 4px 10px; }
.tab.active { background: var(--accent); color: #fff; }

.text-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 10px 0; }
.text-row-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.text-preview { margin: 6px 0; }
.text-preview summary { cursor: pointer; }

.sticky-actions { position: sticky; top: 52px; z-index: 5; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.align-table .sentence { margin-bottom: 4px; }
.align-table td.tools { white-space: nowrap; font-size: .82rem; }
.align-table .move { display: block; color: var(--muted); }

.attempts { border-left: 3px solid var(--line); padding-left: 10px; margin: 8px 0; }
.attempt { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.attempt.current { border-left: 3px solid var(--accent); margin-left: -13px; padding-left: 10px; }
.attempt-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.reason { margin-top: 3px; white-space: pre-wrap; }

.view .cell-text { color: #3c4459; margin-top: 3px; }
.view .corrected { color: var(--ok); }
.view td { min-width: 180px; }

.chart { margin: 8px 0 18px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; font-size: .85rem; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 4px 0; border-bottom: 1px solid #f0f2f5; }
.chart-label { font-weight: 600; }
.bar-line { display: flex; align-items: center; gap: 6px; height: 14px; margin: 2px 0; }
.bar { height: 10px; border-radius: 3px; min-width: 1px; }
.bar-value { font-size: .78rem; color: var(--muted); }
.c0 { background: var(--c0); } .c1 { background: var(--c1); } .c2 { background: var(--c2); }
.c3 { background: var(--c3); } .c4 { background: var(--c4); } .c5 { background: var(--c5); }

.login { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 26px; }
.login button { margin-top: 10px; width: 100%; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 24px; background: #fff3cd; z-index: 100; }
#blazor-error-ui .reload { margin-left: 8px; }

@media (max-width: 720px) {
    .content { padding: 14px 16px 40px; }
    .topbar { padding: 10px 16px; }
    .grid { display: block; overflow-x: auto; }
}
