:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #e2e7ef;
  --text: #1c2433;
  --muted: #65718a;
  --primary: #2f6fed;
  --primary-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);

  --c-pass: #1f9d55;
  --c-fail: #e03e3e;
  --c-blocked: #e8871e;
  --c-skip: #8a6d3b;
  --c-retest: #8b5cf6;
  --c-notexec: #9aa4b5;

  --c-bloker: #d62f2f;
  --c-major: #ec7a1c;
  --c-medium: #e3b008;
  --c-minor: #9aa4b5;

  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c;
    --surface: #171e29;
    --surface-2: #1e2734;
    --border: #2a3545;
    --text: #e6ebf3;
    --muted: #93a0b5;
    --primary: #5b8cff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c;
  --surface: #171e29;
  --surface-2: #1e2734;
  --border: #2a3545;
  --text: #e6ebf3;
  --muted: #93a0b5;
  --primary: #5b8cff;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 14px; margin-top: 18px; }
.mt { margin-top: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { font-size: 28px; }
.brand h1 { font-size: 18px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; gap: 6px; align-items: center; }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 230px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px;
}
.menu-list button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0;
  background: none; color: var(--text); border-radius: 6px; cursor: pointer; font: inherit;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu-list .danger { color: var(--c-fail); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 0; z-index: 10;
}
.tabs a {
  padding: 12px 14px; text-decoration: none; color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: flex; flex-direction: column; gap: 16px; }
.tab-panel[hidden] { display: none; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card h2 + .table-wrap, .card h2 + .bars, .card h2 + .donut-wrap { margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.count {
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
  padding: 1px 8px; border-radius: 999px;
}

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.good .value { color: var(--c-pass); }
.kpi.bad .value { color: var(--c-fail); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--c-pass); border-radius: 999px; }

/* ---------- charts ---------- */
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut-wrap svg { width: 180px; height: 180px; flex: none; }
.donut-center { font-size: 22px; font-weight: 700; fill: var(--text); }
.donut-sub { font-size: 10px; fill: var(--muted); }
.legend { display: grid; gap: 6px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .n { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; padding-left: 16px; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 32px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; min-width: 2px; }
.bar-row .n { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th {
  background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px;
  position: sticky; top: 0; white-space: nowrap;
}
.tbl.compact th, .tbl.compact td { padding: 7px 10px; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.total td { font-weight: 700; background: var(--surface-2); }
.tbl.clickable tbody tr { cursor: pointer; }
.tbl.clickable tbody tr:hover td { background: var(--surface-2); }
.tbl .id { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; white-space: nowrap; }
.tbl .wrap { min-width: 220px; max-width: 420px; }
.tbl .steps { white-space: pre-line; min-width: 220px; color: var(--muted); }
.tbl .auto { color: var(--muted); font-style: italic; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }
.zero { color: var(--muted); }

/* ---------- pills ---------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; border: 1px solid transparent;
}
.s-pass { background: color-mix(in srgb, var(--c-pass) 15%, transparent); color: var(--c-pass); }
.s-fail { background: color-mix(in srgb, var(--c-fail) 15%, transparent); color: var(--c-fail); }
.s-blocked { background: color-mix(in srgb, var(--c-blocked) 15%, transparent); color: var(--c-blocked); }
.s-skip { background: color-mix(in srgb, var(--c-skip) 15%, transparent); color: var(--c-skip); }
.s-retest { background: color-mix(in srgb, var(--c-retest) 15%, transparent); color: var(--c-retest); }
.s-notexec { background: color-mix(in srgb, var(--c-notexec) 18%, transparent); color: var(--muted); }

.v-bloker { background: color-mix(in srgb, var(--c-bloker) 15%, transparent); color: var(--c-bloker); }
.v-major { background: color-mix(in srgb, var(--c-major) 15%, transparent); color: var(--c-major); }
.v-medium { background: color-mix(in srgb, var(--c-medium) 18%, transparent); color: #a07a00; }
.v-minor { background: color-mix(in srgb, var(--c-minor) 18%, transparent); color: var(--muted); }
:root[data-theme="dark"] .v-medium { color: var(--c-medium); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .v-medium { color: var(--c-medium); } }

.b-new { background: color-mix(in srgb, #9aa4b5 18%, transparent); color: var(--muted); }
.b-open { background: color-mix(in srgb, #e03e3e 15%, transparent); color: #e03e3e; }
.b-wip { background: color-mix(in srgb, #e3b008 18%, transparent); color: #b38900; }
.b-ready { background: color-mix(in srgb, #2f6fed 15%, transparent); color: #2f6fed; }
.b-fixed { background: color-mix(in srgb, #8b5cf6 15%, transparent); color: #8b5cf6; }
.b-reopen { background: color-mix(in srgb, #ec7a1c 15%, transparent); color: #ec7a1c; }
.b-done { background: color-mix(in srgb, #1f9d55 15%, transparent); color: #1f9d55; }
.b-deploy { background: color-mix(in srgb, #8a6d3b 15%, transparent); color: #8a6d3b; }
.b-skip { background: color-mix(in srgb, #9aa4b5 12%, transparent); color: var(--muted); }

.flag { color: var(--c-fail); font-weight: 700; }
.flow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ---------- toolbar & controls ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input[type="search"], input[type="text"], input[type="url"], input[type="date"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input[type="search"] { width: 260px; }
textarea { width: 100%; resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 0; border-color: var(--primary); }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--c-fail); border-color: transparent; }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--c-fail) 10%, transparent); }

/* ---------- modal ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 15, 25, .45); }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 18px; }
.modal-head { border-bottom: 1px solid var(--border); justify-content: space-between; }
.modal-head h2 { font-size: 16px; }
.modal-foot { border-top: 1px solid var(--border); }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field .ro { padding: 7px 10px; background: var(--surface-2); border-radius: 8px; color: var(--muted); white-space: pre-line; min-height: 34px; }
.section-title { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; margin-top: 6px; }

/* ---------- misc ---------- */
.prose ol { padding-left: 20px; }
.prose li { margin: 6px 0; }
.footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 16px 24px 28px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px 16px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  input[type="search"] { width: 100%; }
  .modal-body { grid-template-columns: 1fr; }
  .subtitle { display: none; }
}
