:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #4f46e5;
    --accent-ink: #ffffff;
    --accent-soft: #eef2ff;
    --good: #047857;
    --good-soft: #ecfdf5;
    --warn: #b45309;
    --warn-soft: #fffbeb;
    --bad: #b91c1c;
    --bad-soft: #fef2f2;
    --chip: #f3f4f6;
    --shadow: 0 10px 30px rgba(17, 24, 39, 0.12);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']) {
        --bg: #0b0d12;
        --panel: #141821;
        --ink: #e5e7eb;
        --muted: #9ca3af;
        --line: #262b36;
        --accent: #818cf8;
        --accent-ink: #0b0d12;
        --accent-soft: #1e1b4b;
        --good: #34d399;
        --good-soft: #052e22;
        --warn: #fbbf24;
        --warn-soft: #2d1f05;
        --bad: #f87171;
        --bad-soft: #2d0b0b;
        --chip: #1f2430;
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}
[hidden] { display: none !important; }
h2 { font-size: 18px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.error { color: var(--bad); margin: 8px 0 0; }

.btn {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
    border-radius: 8px;
    padding: 7px 12px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.55; cursor: progress; }

input, select, textarea {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 9px;
}
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { font-size: 14px; color: var(--ink); font-weight: 400; }

.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 18px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }
.login-card .btn { width: 100%; margin-top: 4px; }

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.container { max-width: 1320px; margin: 0 auto; padding: 16px 20px 40px; }

.sync-status { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sync-pill { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); max-width: 100%; }
.sync-pill b { color: var(--ink); font-weight: 600; }
.sync-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.sync-pill.fail .dot { background: var(--bad); }
.sync-pill span.msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.stat:hover { border-color: var(--accent); }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; }

.filters { display: grid; grid-template-columns: 2fr repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; min-width: 900px; }
.grid th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--accent-soft); }
.grid tbody tr:last-child td { border-bottom: 0; }
.t-name { font-weight: 600; }
.t-sub { color: var(--muted); font-size: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); color: var(--ink); white-space: nowrap; }
.chip.running { background: var(--good-soft); color: var(--good); }
.chip.draft { background: var(--warn-soft); color: var(--warn); }
.chip.stopped { background: var(--chip); color: var(--muted); }
.chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.shipped { background: var(--good-soft); color: var(--good); }
.chip.reverted { background: var(--bad-soft); color: var(--bad); }
.chip.src { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 20;
    width: min(720px, 100%); background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
    display: flex; flex-direction: column;
}
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 2px 0 0; }
.drawer-body { overflow-y: auto; padding: 16px 20px 40px; }
.scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, 0.3); }
.section { margin-bottom: 22px; }
.section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

table.results { width: 100%; border-collapse: collapse; font-size: 13px; }
.results th, .results td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.results th:first-child, .results td:first-child { text-align: left; white-space: normal; }
.results th { font-size: 11px; color: var(--muted); font-weight: 600; }
.results tr.best td { background: var(--good-soft); }
.results td.best-cell { color: var(--good); font-weight: 600; }
.results-note { font-size: 12px; color: var(--muted); margin-top: 6px; }

.results-editor { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin: 0 0 10px; }
.results-editor legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.re-table { width: 100%; border-collapse: collapse; }
.re-table td { padding: 3px; }
.re-table input { padding: 5px 7px; font-size: 13px; }

.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(640px, calc(100% - 32px)); background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.dialog.wide { width: min(820px, calc(100% - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.ai-out { margin-top: 14px; padding: 14px 16px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.ai-out h4 { margin: 12px 0 4px; font-size: 14px; }
.ai-out h4:first-child { margin-top: 0; }
.ai-out ul { margin: 4px 0; padding-left: 18px; }
.ai-out p { margin: 6px 0; }
.review { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin-bottom: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 40; background: var(--ink); color: var(--panel); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: calc(100% - 32px); }

@media (max-width: 860px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters #f-q { grid-column: 1 / -1; }
    .form-grid { grid-template-columns: 1fr; }
    .topbar, .container { padding-left: 16px; padding-right: 16px; }
    .kv { grid-template-columns: 1fr; }
}

.coverage { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cov-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.cov-card .cov-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.cov-list { display: flex; flex-wrap: wrap; gap: 6px; }
.cov { font: inherit; font-size: 12px; border-radius: 999px; padding: 3px 9px; border: 1px solid transparent; cursor: pointer; }
.cov.on { background: var(--good-soft); color: var(--good); }
.cov.off { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); border-style: dashed; }
.cov:hover { filter: brightness(1.08); }

.tabs { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); margin: -4px 0 14px; }
.tab { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 10px; cursor: pointer; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs-close { margin-left: auto; }
.count-select { width: auto; margin-right: auto; }

.sugg-summary { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin: 14px 0 10px; font-size: 14px; }
.sugg { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.sugg-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.sugg h4 { margin: 0 0 4px; font-size: 15px; }
.sugg .prio-yüksek { background: var(--bad-soft); color: var(--bad); }
.sugg .prio-orta { background: var(--warn-soft); color: var(--warn); }
.sugg .prio-düşük { background: var(--chip); color: var(--muted); }
.sugg dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 10px 0 8px; font-size: 13px; }
.sugg dt { color: var(--muted); }
.sugg dd { margin: 0; }
.sugg ul { margin: 0; padding-left: 16px; }
.sugg .why { font-size: 13px; color: var(--muted); }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 16px 0; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 860px) { .sugg dl { grid-template-columns: 1fr; } }
.chip.auto { border: 1px dashed currentColor; }
.chip.iterate { background: var(--accent-soft); color: var(--accent); }
.chip.inconclusive { background: var(--chip); color: var(--muted); }
.auto-box { border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; }
.auto-box p { margin: 4px 0 8px; font-size: 13px; }
