:root {
  --paper: #f3f6f5;
  --surface: #ffffff;
  --ink: #0f3b3a;
  --ink-2: #44605d;
  --muted: #7a8f8c;
  --line: #dde6e4;
  --saffron: #d9971a;
  --saffron-soft: #fbefd6;
  --up: #2f8f6b;
  --down: #c2453d;
  --heat-0: #e6edeb;
  --heat-1: #c4dcd6;
  --heat-2: #8ec1b5;
  --heat-3: #4f9a8b;
  --heat-4: #1f6b60;
  --heat-5: #0f3b3a;
  --shadow: 0 1px 0 rgba(15, 59, 58, .06);
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Public Sans", "Segoe UI", system-ui, sans-serif;
  --arabic: "Amiri", "Traditional Arabic", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1a19; --surface: #132322; --ink: #e2ecea; --ink-2: #b2c4c1; --muted: #7f9592; --line: #213634;
    --saffron: #f0b13b; --saffron-soft: #3a2f17; --up: #4fbf93; --down: #ec6f66;
    --heat-0: #1b2e2c; --heat-1: #1f4741; --heat-2: #24665b; --heat-3: #2f8c7a; --heat-4: #4fbfa6; --heat-5: #a6ecd9;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1a19; --surface: #132322; --ink: #e2ecea; --ink-2: #b2c4c1; --muted: #7f9592; --line: #213634;
  --saffron: #f0b13b; --saffron-soft: #3a2f17; --up: #4fbf93; --down: #ec6f66;
  --heat-0: #1b2e2c; --heat-1: #1f4741; --heat-2: #24665b; --heat-3: #2f8c7a; --heat-4: #4fbfa6; --heat-5: #a6ecd9;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--saffron); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* header */
.top { display: flex; align-items: center; gap: 16px; padding: 20px 0 8px; }
.mark { display: flex; align-items: baseline; gap: 10px; text-decoration: none; }
.mark b { font: 700 22px/1 var(--display); letter-spacing: -.01em; }
.mark span { font: 400 24px/1 var(--arabic); color: var(--saffron); }
.top .spacer { flex: 1; }
.top .meta { color: var(--muted); font-size: 13px; }
.iconbtn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px; align-items: center;
}
.iconbtn:hover { border-color: var(--ink-2); }
.iconbtn[aria-busy="true"] { opacity: .6; pointer-events: none; }

/* lede */
.lede { padding: 28px 0 22px; }
.lede h1 {
  font: 600 clamp(30px, 4.6vw, 56px)/1.05 var(--display);
  letter-spacing: -.025em; margin: 0; max-width: 20ch;
}
.lede h1 .n { font-weight: 800; }
.lede p { margin: 14px 0 0; font-size: 17px; color: var(--ink-2); max-width: 64ch; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-top: 22px; }
.fact { display: flex; align-items: baseline; gap: 8px; }
.fact strong { font: 700 22px/1 var(--display); }
.fact span { color: var(--muted); font-size: 14px; }
.pulse {
  width: 10px; height: 10px; border-radius: 50%; background: var(--saffron); align-self: center;
  box-shadow: 0 0 0 0 var(--saffron); animation: pulse 2s infinite;
}
.pulse.off { background: var(--muted); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--saffron) 60%, transparent); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 10px 0 14px; border-top: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.controls .search { margin-left: auto; }
.search input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; width: 220px; max-width: 100%;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 3px 10px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.chip[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); background: var(--surface); }

/* layout */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; padding-bottom: 48px; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

/* ranking */
.board { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.board-head, .row {
  display: grid; align-items: center; gap: 14px;
  grid-template-columns: 32px minmax(150px, 1.3fr) 120px minmax(190px, 1.6fr) 74px 86px;
  padding: 10px 18px;
}
.board-head { color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); padding-top: 12px; }
.board-head .r, .st { text-align: right; }
.row { border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--paper) 70%, var(--surface)); }
.rank { font: 600 15px/1 var(--display); color: var(--muted); }
.row:nth-child(-n+4) .rank { color: var(--saffron); }
.who { min-width: 0; }
.who .nm { font-weight: 600; display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.who .nm em { font: normal 16px/1 var(--arabic); color: var(--muted); }
.who .nm .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .dm { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { text-align: right; }
.num b { font: 700 19px/1 var(--display); display: block; }
.delta { font-size: 12.5px; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }

.heat { display: grid; grid-template-columns: repeat(30, 1fr); gap: 2px; height: 22px; }
.heat i { display: block; border-radius: 2px; background: var(--heat-0); }
.heat i.h1 { background: var(--heat-1); } .heat i.h2 { background: var(--heat-2); } .heat i.h3 { background: var(--heat-3); }
.heat i.h4 { background: var(--heat-4); } .heat i.h5 { background: var(--heat-5); }
.heat i.dim { opacity: .35; }
.heat i.today { outline: 1.5px solid var(--saffron); outline-offset: 1px; }

.live { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; font-size: 13px; color: var(--muted); }
.live.on { color: var(--ink); font-weight: 600; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.live.on .dot { background: var(--saffron); }
.health { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; font-size: 12.5px; color: var(--muted); }
.health .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); }
.health.bad { color: var(--down); font-weight: 600; }
.health.bad .dot { background: var(--down); }
.health.na .dot { background: var(--line); }
.r, .st { text-align: right; }

.empty { padding: 40px 24px; text-align: center; color: var(--ink-2); }
.empty code { background: var(--paper); padding: 2px 6px; border-radius: 4px; }
.untracked { color: var(--muted); font-size: 12.5px; }

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .board-head { display: none; }
  .row { grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-areas: "rank who num" ". heat heat" ". live st"; row-gap: 8px; padding: 12px 14px; }
  .row .rank { grid-area: rank; } .row .who { grid-area: who; } .row .num { grid-area: num; }
  .row .heat, .row .heat-none { grid-area: heat; height: 16px; }
  .row .heat-none { display: none; }
  .row .live { grid-area: live; justify-content: flex-start; }
  .row .st { grid-area: st; }
  .top { flex-wrap: wrap; gap: 8px; }
  .top .spacer { flex-basis: 100%; height: 0; }
  .top .meta { margin-right: auto; }
  .controls .search { margin-left: 0; width: 100%; }
  .search input { width: 100%; }
}

/* aside */
.side { display: grid; gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.panel h2 { font: 600 16px/1.3 var(--display); margin: 0 0 10px; }
.panel .sub { color: var(--muted); font-size: 13px; margin: -6px 0 10px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.list li button { all: unset; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li button:hover { text-decoration: underline; }
.list li button:focus-visible { outline: 2px solid var(--saffron); }
.list .v { color: var(--muted); white-space: nowrap; }
.list .v.up { color: var(--up); } .list .v.down { color: var(--down); }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis { fill: var(--muted); font-size: 10px; }

/* drawer */
dialog.drawer {
  margin: 0 0 0 auto; height: 100%; max-height: 100%; width: min(520px, 100%); border: 0; padding: 0;
  background: var(--surface); color: var(--ink); box-shadow: -10px 0 40px rgba(0,0,0,.18);
}
dialog.drawer::backdrop { background: rgba(8, 25, 24, .35); }
dialog.drawer[open] { animation: slide .22s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.drawer[open], .pulse { animation: none; } }
.dr { padding: 22px 24px 40px; }
.dr-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.dr h3 { font: 700 28px/1.1 var(--display); margin: 0; letter-spacing: -.02em; }
.dr h3 em { font: normal 26px/1 var(--arabic); color: var(--saffron); margin-left: 8px; }
.dr .dm a { color: var(--ink-2); font-size: 14px; }
.close { border: 1px solid var(--line); background: none; border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 18px; line-height: 1; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; margin: 20px 0; }
.kpi span { display: block; color: var(--muted); font-size: 12.5px; }
.kpi b { font: 700 22px/1.1 var(--display); }
.dr h4 { font: 600 15px/1.3 var(--display); margin: 22px 0 8px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px; }
@media (max-width: 480px) { .cols, .kpis { grid-template-columns: 1fr 1fr; } }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.bars li { position: relative; display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 3px 6px; border-radius: 4px; overflow: hidden; }
.bars li::before { content: ""; position: absolute; inset: 0; width: var(--w); background: var(--heat-0); z-index: 0; }
.bars li > * { position: relative; z-index: 1; }
.bars li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .none { color: var(--muted); font-size: 13px; }
.ustrip { display: grid; grid-template-columns: repeat(48, 1fr); gap: 2px; height: 18px; }
.ustrip i { border-radius: 2px; background: var(--up); }
.ustrip i.x { background: var(--down); }
.ustrip i.n { background: var(--heat-0); }
.small { color: var(--muted); font-size: 12.5px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; }
.note { background: var(--saffron-soft); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-top: 14px; }
.err { background: color-mix(in srgb, var(--down) 12%, var(--surface)); color: var(--ink); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 0 0 12px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); }
.login h1 { font: 700 40px/1 var(--display); margin: 0 0 4px; letter-spacing: -.02em; }
.login .ar { font: 400 34px/1.2 var(--arabic); color: var(--saffron); }
.login p { color: var(--ink-2); margin: 10px 0 22px; }
.login label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.login input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 14px; }
.login button { margin-top: 14px; width: 100%; border: 0; border-radius: 10px; padding: 11px; background: var(--ink); color: var(--paper); font-weight: 600; cursor: pointer; }
.login .msg { color: var(--down); font-size: 13.5px; min-height: 20px; margin-top: 10px; }
