:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dedcd6;
  --grid: #e7e5e0;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #77756f;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0a7d0a;
  --warn: #9a6a00;
  --bad: #c22f2f;
  --good-bg: #e4f4e4;
  --warn-bg: #fbf0d6;
  --bad-bg: #fbe3e3;
  --star: #c98500;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #383835; --grid: #2c2c2a;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #95938a; --accent: #3987e5; --accent-ink: #86b6ef;
    --series-1: #3987e5; --series-2: #d95926;
    --good: #4cc44c; --warn: #f0b429; --bad: #ef7070;
    --good-bg: #183218; --warn-bg: #3a2f12; --bad-bg: #3d1c1c; --star: #f0b429;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #383835; --grid: #2c2c2a;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #95938a; --accent: #3987e5; --accent-ink: #86b6ef;
  --series-1: #3987e5; --series-2: #d95926;
  --good: #4cc44c; --warn: #f0b429; --bad: #ef7070;
  --good-bg: #183218; --warn-bg: #3a2f12; --bad-bg: #3d1c1c; --star: #f0b429;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; line-height: 1.25; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { padding: 6px 10px; border-radius: 8px; color: var(--text-2); }
#nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
#nav a:hover { text-decoration: none; background: var(--surface-2); }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--text-2); font-size: 13px; }
.role-badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); margin-left: 4px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: 13px; overflow-wrap: anywhere; }

/* controls */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 13px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--accent-ink); }
button:disabled { opacity: .55; cursor: default; }
input, 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:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; background: var(--surface); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); font-weight: 600; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.spin { width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .8s linear infinite; display: inline-block; }
@keyframes s { to { transform: rotate(360deg); } }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.grid { display: grid; gap: 14px; }
.apps { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.app-card { display: block; color: var(--text); }
.app-card:hover { text-decoration: none; border-color: var(--accent); }
.app-card .t { font-weight: 650; font-size: 15px; }
.app-card .p { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.mini div b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.mini div span { font-size: 12px; color: var(--text-2); }

.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 14px; }
.kpi .l { font-size: 12px; color: var(--text-2); cursor: help; }
.kpi .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.charts { grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); margin-bottom: 14px; }
.chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--border); }
.chart .xh { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dlabel { font-size: 11px; fill: var(--text-2); }
.empty { padding: 34px 10px; text-align: center; color: var(--muted); }
details.tbl { margin-top: 8px; font-size: 12px; }
details.tbl summary { cursor: pointer; color: var(--muted); }
details.tbl .scroll { max-height: 260px; overflow: auto; margin-top: 6px; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .14); min-width: 120px;
}
.tip .h { font-weight: 600; margin-bottom: 3px; }
.tip .r { display: flex; gap: 10px; justify-content: space-between; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.bar-cell { position: relative; min-width: 90px; }
.bar-cell span { position: absolute; left: 0; top: 50%; height: 6px; margin-top: -3px; border-radius: 0 3px 3px 0; background: var(--series-1); opacity: .5; }

/* stars */
.stars-dist { display: grid; gap: 7px; }
.stars-dist .row { display: grid; grid-template-columns: 34px 1fr 58px; gap: 8px; align-items: center; font-size: 13px; }
.stars-dist .track { height: 10px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.stars-dist .fill { height: 100%; background: var(--series-1); border-radius: 0 3px 3px 0; }
.st { color: var(--star); letter-spacing: 1px; }

/* reviews */
.reviews { display: grid; gap: 10px; }
.review { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.review .meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; font-size: 12px; color: var(--muted); }
.review .meta b { color: var(--text); font-size: 13px; }
.review .body { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.review .reply { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.review .reply .who { font-size: 12px; color: var(--muted); margin-bottom: 3px; display: block; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--text-2); }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn); }
.banner.info { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.banner.bad { background: var(--bad-bg); border: 1px solid var(--bad); }

/* login */
body.login-bg {
  min-height: 100vh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cg fill='%23ffffff' fill-opacity='.045'%3E%3Crect x='14' y='70' width='14' height='36' rx='3'/%3E%3Crect x='38' y='50' width='14' height='56' rx='3'/%3E%3Crect x='62' y='30' width='14' height='76' rx='3'/%3E%3Crect x='86' y='14' width='14' height='92' rx='3'/%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(circle at 15% 20%, rgb(255 255 255 / .18), transparent 45%),
    radial-gradient(circle at 85% 85%, rgb(27 175 122 / .45), transparent 50%),
    linear-gradient(135deg, #104281 0%, #2a78d6 55%, #1baf7a 100%);
  background-attachment: fixed;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body.login-bg {
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cg fill='%23ffffff' fill-opacity='.035'%3E%3Crect x='14' y='70' width='14' height='36' rx='3'/%3E%3Crect x='38' y='50' width='14' height='56' rx='3'/%3E%3Crect x='62' y='30' width='14' height='76' rx='3'/%3E%3Crect x='86' y='14' width='14' height='92' rx='3'/%3E%3C/g%3E%3C/svg%3E"),
      radial-gradient(circle at 85% 85%, rgb(25 158 112 / .3), transparent 50%),
      linear-gradient(135deg, #07182e 0%, #0d366b 60%, #0d4a3a 100%);
    background-attachment: fixed;
  }
}
.login { max-width: 360px; margin: 0 auto; padding-top: 12vh; }
.login .card { padding: 26px; display: grid; gap: 14px; box-shadow: 0 18px 50px rgb(0 0 0 / .28); border-color: transparent; }
.login .logo { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.ok-msg { color: var(--good); font-size: 13px; }

/* admin forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.app-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px; max-height: 260px; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.app-checks label { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 8px; }
code { font: 12px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre.detail { white-space: pre-wrap; font: 12px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 8px; border-radius: 6px; margin: 6px 0 0; overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .top { padding: 8px 16px; gap: 10px; }
  .who { margin-left: 0; width: 100%; justify-content: space-between; }
  main { padding: 16px; }
  .kpi .v { font-size: 20px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .card { padding: 12px; }
}
@media (forced-colors: active) {
  .stars-dist .fill, .bar-cell span { background: CanvasText; }
}
