.login-card { width: min(360px, 100%); padding: 20px; display: grid; gap: 12px; }
.form-error { color: var(--err); margin: 0; min-height: 1.2em; font-size: 14px; }

label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .6; cursor: progress; }

.top-inner { justify-content: space-between; max-width: 1180px; }
#logout { margin-left: auto; }
.save-status + #logout { margin-left: 0; }
.save-status.hidden + #logout { margin-left: auto; }
.save-status { margin-left: auto; color: var(--muted); font-size: 13.5px; }
.save-status.busy { color: var(--accent); }
.save-status.err { color: var(--err); }

main.admin { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; display: grid; gap: 18px; }
.section { padding: 20px 22px; display: grid; gap: 14px; }
.section h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.step {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px;
  background: var(--accent-soft); color: var(--accent);
}
.hint { color: var(--muted); margin: 0; font-size: 14px; }
.hint.small { font-size: 13px; }

.switch { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 8px; color: var(--text); font-size: 14.5px; font-weight: 500; cursor: pointer; width: fit-content; }
.switch input, .row input[type=radio] { width: auto; accent-color: var(--accent); transform: scale(1.2); }

/* provider + engine rows */
.row { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 10px; margin-bottom: 10px; }
.row.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.row-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-head .title { font-weight: 700; color: var(--text); }
.row-head .sub { color: var(--muted); font-size: 13px; }
.row-head .actions { margin-left: auto; display: flex; gap: 6px; }
.row .pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: #fff; }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.test-out { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.test-out:empty { display: none; }
.test-out.ok { color: var(--ok); }
.test-out.err { color: var(--err); }

.add-ai { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 8px; }
.add-custom { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 8px; }
@media (max-width: 600px) { .add-custom { grid-template-columns: 1fr; } }
.env-pill { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
@media (max-width: 600px) { .add-ai { grid-template-columns: 1fr; } }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .two-col { grid-template-columns: 1fr; } }

details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
details.more[open] { display: grid; gap: 12px; }
details.more[open] summary { margin-bottom: 4px; }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.adv[open] .row-fields { margin-top: 8px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* stats */
.stat-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; }
.tile span { font-size: 13px; color: var(--muted); }
.tile b { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.bars { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; align-items: end; height: 90px; }
.bar { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bar.zero { background: var(--border); }
.bar:hover { opacity: 1; }
.sub-h { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.top-list { margin: 0; padding-left: 22px; display: grid; gap: 3px; font-size: 14.5px; }
.top-list li span { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 6px; font-size: 13px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* account */
.account-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.account-form .row-between { grid-column: 1 / -1; }
input:disabled { opacity: .65; cursor: not-allowed; }

/* ---------- view tabs ---------- */
.view-tabs { display: flex; gap: 4px; }
.view-tab { border: 0; background: none; color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.view-tab.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- dashboard ---------- */
.dash {
  /* Chart roles. Single-series marks use the brand accent; splits use the
     reference palette's first three categorical slots (validated for CVD). */
  --mark: var(--accent);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --st-good: #0ca30c; --st-warn: #fab219; --st-bad: #d03b3b;
  --grid: var(--border);
  max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px;
}
@media (prefers-color-scheme: dark) {
  .dash { --s1: #3987e5; --s2: #d95926; --s3: #199e70; }
}
.dash-filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.dash .seg { display: flex; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.dash .seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.dash .seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dash-updated { color: var(--muted); font-size: 13px; margin-left: auto; }

.dash-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; transition: opacity .2s; }
.dash-body.refreshing { opacity: .55; }
.dash-body > .wide, .kpis { grid-column: 1 / -1; }
@media (max-width: 860px) { .dash-body { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.kpi-hint { font-size: 12px; color: var(--muted); }
.delta { font-size: 12.5px; font-weight: 600; }
.delta.good { color: var(--ok); }
.delta.bad { color: var(--err); }
.delta.flat { color: var(--muted); font-weight: 500; }

.panel-card { padding: 16px 18px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.pc-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pc-head h2 { margin: 0; font-size: 16px; }
.pc-sub { color: var(--muted); font-size: 12.5px; }
.pc-h3 { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.pc-note { margin: 0; color: var(--muted); font-size: 13px; }
.empty-note { color: var(--muted); font-size: 14px; margin: 6px 0; }

.chart { width: 100%; min-width: 0; }
.svg-chart { display: block; overflow: visible; }
.svg-chart .grid { stroke: var(--grid); stroke-width: 1; }
.svg-chart .axis { stroke: var(--muted); stroke-opacity: .5; stroke-width: 1; }
.svg-chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.svg-chart .bar { fill: var(--mark); }
.svg-chart .hit { fill: transparent; }
.svg-chart .col { outline: none; cursor: default; }
.svg-chart .col:hover .bar, .svg-chart .col:focus .bar { opacity: .75; }
.svg-chart .col:hover .hit, .svg-chart .col:focus-visible .hit { fill: var(--accent-soft); fill-opacity: .5; }

.stack { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; }
.seg-fill { min-width: 3px; outline: none; }
.seg-fill:hover, .seg-fill:focus-visible { opacity: .75; }
.s1 { background: var(--s1); } .s2 { background: var(--s2); } .s3 { background: var(--s3); }
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 8px; font-size: 14px; }
.legend .key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend b { font-variant-numeric: tabular-nums; }
.legend small { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 90px; text-align: right; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.hbars li { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.hb-fill { display: block; height: 100%; background: var(--mark); border-radius: 0 4px 4px 0; }
.hb-value { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; min-width: 40px; }

.dash table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dash th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--border); padding: 6px 8px; }
.dash td { padding: 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.dash tr:last-child td { border-bottom: 0; }
.data-table summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.data-table[open] > div { max-height: 300px; overflow: auto; margin-top: 8px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.status i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 11px; color: #fff; }
.st-good i { background: var(--st-good); } .st-warn i { background: var(--st-warn); color: #1b1b1f; } .st-bad i { background: var(--st-bad); } .st-none i { background: var(--border); color: var(--muted); }

.privacy-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 860px) { .privacy-grid { grid-template-columns: 1fr; } }
.privacy-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; color: var(--text); }
.privacy-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.pv-stat { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.pv-stat b { font-size: 20px; }
.pv-stat span { font-size: 12px; color: var(--muted); }
.privacy-controls { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; }
.inline-num { display: inline-flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 500; color: var(--text); }
.inline-num input { width: 64px; padding: 5px 8px; }
.privacy-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.dash-tip {
  position: absolute; z-index: 20; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px; display: grid; gap: 1px; box-shadow: var(--shadow); white-space: nowrap;
}
.dash-tip b { font-size: 14px; }
.dash-tip span { opacity: .8; }
.dash-tip[hidden] { display: none; }
