:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f0f2f5; --line: #e2e5ea;
  --text: #1b1f27; --muted: #677083; --accent: #2f6fed; --accent-ink: #fff;
  --good: #1f9d55; --ok: #7aa62b; --warn: #d79b0b; --bad: #e0682a; --worst: #d23b3b;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b23; --panel-2: #1f2430; --line: #2a303c;
    --text: #e7eaf0; --muted: #9099ab; --accent: #5b8cff;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: grid; grid-template-columns: 220px 1fr;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* sidebar */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px 18px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
nav a:hover { background: var(--panel-2); }
nav a.active { background: var(--accent); color: var(--accent-ink); }
.count { font-size: 12px; opacity: .75; }
nav .short { display: none; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; display: grid; gap: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

main { padding: 24px 28px 60px; min-width: 0; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid2 .card { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .track { background: var(--panel-2); border-radius: 4px; height: 10px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.jobs { display: grid; gap: 6px; font-size: 13px; }
.job-item { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }

/* buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
label.inline { display: flex; align-items: center; gap: 8px; }
.search-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.form-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; justify-content: flex-end; flex-wrap: wrap; }
.form-row.end { justify-content: flex-end; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.chips { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.chips button { border: 0; background: none; color: var(--text); padding: 7px 12px; font: inherit; cursor: pointer; border-right: 1px solid var(--line); }
.chips button:last-child { border-right: 0; }
.chips button.on { background: var(--accent); color: var(--accent-ink); }

/* tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
table.data th.sorted::after { content: " ↓"; }
table.data th.sorted.asc::after { content: " ↑"; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--panel-2); }
td .nm { font-weight: 600; }
td .sub { color: var(--muted); font-size: 12px; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.tag.social { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tag.none { background: color-mix(in srgb, var(--worst) 15%, transparent); color: var(--worst); }
.status-sel { padding: 3px 6px; font-size: 12.5px; }

.grade { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; font-weight: 800; color: #fff; }
.grade.A { background: var(--good); } .grade.B { background: var(--ok); } .grade.C { background: var(--warn); }
.grade.D { background: var(--bad); } .grade.F { background: var(--worst); } .grade.none { background: var(--panel-2); color: var(--muted); }
.stars { display: inline-flex; gap: 1px; }
.stars button { border: 0; background: none; padding: 0 1px; font-size: 17px; line-height: 1; cursor: pointer; color: var(--line); }
.stars button.on { color: #f5b301; }

/* job progress */
.job-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.progress { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.log { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; max-height: 280px; overflow: auto; font-size: 12px; margin: 0; white-space: pre-wrap; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 10; transform: translateX(100%); transition: transform .2s ease; overflow-y: auto; padding: 22px 24px 40px; }
.drawer.open { transform: none; }
.drawer .close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; }
.drawer h2.title { font-size: 20px; margin: 0 30px 4px 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 14px 0; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 16px; }
.score-hero { display: flex; align-items: center; gap: 14px; }
.score-hero .grade { width: 52px; height: 52px; font-size: 26px; border-radius: 12px; }
.score-hero .big { font-size: 26px; font-weight: 700; }
.checks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.checks li { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; font-size: 13px; align-items: start; }
.checks .ic.pass { color: var(--good); } .checks .ic.fail { color: var(--worst); } .checks .ic.partial { color: var(--warn); }
.checks .det { color: var(--muted); font-size: 12px; max-width: 200px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.psi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.psi div { background: var(--panel-2); border-radius: 8px; padding: 8px; text-align: center; font-size: 12px; color: var(--muted); }
.psi b { display: block; font-size: 20px; color: var(--text); }
.shot { max-width: 220px; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.pitch { width: 100%; min-height: 200px; font-size: 13px; line-height: 1.5; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 22px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { display: grid; gap: 12px; }
dialog input { width: 100%; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20; font-size: 13.5px; }

/* user box */
.user-box { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--text); font-size: 13px; }
.user-box .avatar { color: var(--good); font-size: 10px; }
.user-box #who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* login page */
body.login-page { display: block; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card .brand { padding: 0 0 4px; }
.login-card h1 { font-size: 20px; }
.login-card input { width: 100%; padding: 10px 12px; }
.login-card input:focus, .login-card button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.block { width: 100%; justify-content: center; padding: 10px; font-weight: 600; }
.login-error { margin: 0; color: var(--worst); font-size: 13px; background: color-mix(in srgb, var(--worst) 10%, transparent); padding: 8px 10px; border-radius: 8px; }
.login-help { margin: 4px 0 0; text-align: center; }
.login-help code { font-size: 12px; }

/* ---------- mobile (kept last so it overrides everything above) ---------- */
@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .search-form { grid-template-columns: 1fr; }
  .hide-sm { display: none; }

  /* Header: row 1 = brand + log out, row 2 = full-width tabs */
  .sidebar {
    position: sticky; top: 0; z-index: 5; height: auto;
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand foot" "nav nav";
    align-items: center; gap: 8px 12px; padding: 10px 16px 0;
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { grid-area: brand; padding: 0; font-size: 15px; }
  .side-foot { grid-area: foot; margin: 0; padding: 0; display: block; }
  #config-status, .user-box .avatar { display: none; }
  .user-box { border: 0; margin: 0; padding: 0; gap: 8px; }
  .user-box #who { max-width: 110px; color: var(--muted); font-size: 12.5px; }

  nav { grid-area: nav; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 0 -16px; }
  nav a {
    justify-content: center; gap: 5px; padding: 10px 4px 9px; border-radius: 0;
    font-size: 13.5px; white-space: nowrap; color: var(--muted);
    border-bottom: 2px solid transparent;
  }
  nav a:hover { background: none; color: var(--text); }
  nav a.active { background: none; color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  nav .count { font-size: 11px; background: var(--panel-2); color: var(--muted); padding: 0 6px; border-radius: 999px; opacity: 1; line-height: 17px; }
  nav .count:empty { display: none; }
  nav a.active .count { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

  /* Filter chips: one swipeable row instead of wrapping */
  .chips { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .chips button { white-space: nowrap; flex: 0 0 auto; }
  .view-head h1 { font-size: 20px; }
}
@media (max-width: 420px) {
  nav .long { display: none; }
  nav .short { display: inline; }
  .user-box #who { display: none; }
  .hide-xs { display: none; }
}
