:root {
    --bg: #f9f9f7;
    --surface: #fcfcfb;
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #898781;
    --line: #e1e0d9;
    --border: rgba(11, 11, 11, .1);
    --accent: #2a78d6;
    --accent-soft: #cde2fb;
    --good: #006300;
    --bad: #d03b3b;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 1rem; }
code { font-size: .9em; }
.muted { color: var(--muted); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 1.25rem; align-items: center; }
main { max-width: 1240px; margin: 0 auto; padding: 1.5rem; }
footer { padding: 1rem; text-align: center; color: var(--muted); font-size: .8rem; }
footer span { margin: 0 .5rem; }
.sync-ok { color: var(--good); }
.sync-error { color: var(--bad); }

select, input, button { font: inherit; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
button { cursor: pointer; }
button.primary, .btn { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; padding: .45rem .9rem; border-radius: 6px; }
button.link { border: 0; background: none; color: var(--bad); padding: 0; }
form.inline { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
form.inline input, form.inline select { flex: 1 1 140px; }

.filters { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .75rem 1rem; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.filters label { display: flex; align-items: center; gap: .4rem; }
.period-label { margin-left: auto; color: var(--muted); }
.chip { padding: .35rem .7rem; background: var(--accent-soft); border-radius: 999px; }
.dropdown { position: relative; }
.dropdown summary { list-style: none; cursor: pointer; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown > div { position: absolute; top: 100%; left: 0; z-index: 10; min-width: 240px; max-height: 320px; overflow: auto; margin-top: .25rem; padding: .5rem; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .08); }
.dropdown label { display: flex; gap: .4rem; padding: .2rem .3rem; white-space: nowrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi { display: flex; flex-direction: column; gap: .1rem; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.kpi-label { color: var(--text-2); font-size: .82rem; }
.kpi-value { font-size: 1.55rem; font-weight: 600; }
.delta { font-size: .78rem; color: var(--muted); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.card { padding: 1rem 1.25rem; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }
.chart { position: relative; height: 280px; margin-bottom: 1rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; align-items: start; }
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .45rem .5rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--text-2); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; }
th a { color: inherit; text-decoration: none; }
.num { text-align: right; }
.actions { text-align: right; }
.empty { color: var(--muted); font-style: italic; }
.bar { display: inline-block; width: calc(var(--w, 0) * 1.2px); height: .6em; margin-right: .4rem; background: var(--accent); border-radius: 2px; vertical-align: middle; }

.settings fieldset { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem 1.25rem; margin: 0 0 1.25rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: 8px; }
.settings legend { font-weight: 600; padding: 0 .4rem; }
.settings label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--text-2); }
.settings input { color: var(--text); }
.test-results { list-style: none; padding: 0; margin: 0; }
.test-results li { padding: .3rem 0; }

.login { max-width: 360px; margin: 4rem auto; display: flex; flex-direction: column; gap: .75rem; }
.login label { display: flex; flex-direction: column; gap: .25rem; }
.error { color: var(--bad); }

@media (max-width: 640px) {
    main { padding: 1rem; }
    .period-label { margin-left: 0; width: 100%; }
    .topbar { flex-direction: column; align-items: flex-start; }
}
