/*
 * Tareqi console — one stylesheet, no dependencies, no build step.
 *
 * The layout is a fixed sidebar plus a scrolling column. The sidebar is the
 * only navigation: nine sections in four groups, each group named, so what the
 * console can do is readable without clicking anything.
 *
 * Spacing is deliberately loose. The previous version fitted everything into a
 * phone-first column and every panel touched its neighbour; on a desktop that
 * reads as one dense wall rather than nine separate tools. Panels here get room
 * and one job each.
 *
 * Below 900px the sidebar becomes a slide-over and the column takes the width.
 */

:root {
  color-scheme: dark light;

  --bg: #0a0f1c;
  --side: #0d1526;
  --panel: #121b2d;
  --panel-2: #16223a;
  --line: #223350;
  --line-soft: #1a2740;
  --ink: #e9effc;
  --ink-2: #93a4c4;
  --ink-3: #6b7c9c;
  --brand: #2dd4bf;
  --brand-ink: #04231f;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.28);
  --r: 14px;
  --side-w: 268px;

  /* Contribution-kind colours — fixed across chart, legend and funnel */
  --k-installs: #64748b;
  --k-traces: #2dd4bf;
  --k-suggestions: #a78bfa;
  --k-votes: #60a5fa;
  --k-fares: #fbbf24;
  --k-comments: #f472b6;
  --k-comment_votes: #4ade80;
}

html[data-theme='light'] {
  --bg: #f5f7fb;
  --side: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f8fd;
  --line: #dde4f0;
  --line-soft: #e9eef7;
  --ink: #16203a;
  --ink-2: #56668a;
  --ink-3: #8494b3;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --shadow: 0 1px 2px rgb(16 32 64 / 0.05), 0 10px 30px rgb(16 32 64 / 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    15px/1.6 'Inter',
    'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 1.05rem;
  margin: 0 0 10px;
  font-weight: 700;
}
h3 {
  font-size: 0.95rem;
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
a {
  color: var(--brand);
}
code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.85em;
  font-family: ui-monospace, 'Consolas', monospace;
}

.muted {
  color: var(--ink-2);
  font-size: 0.85rem;
}
.lede {
  color: var(--ink-2);
  font-size: 0.92rem;
  margin: 0 0 20px;
  max-width: 74ch;
}

/* ==================================================================== side */

.side {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--side-w);
  background: var(--side);
  border-inline-end: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  gap: 18px;
  overflow-y: auto;
  z-index: 30;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px;
  color: var(--brand);
}
.side-brand div {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}
.side-brand strong {
  color: var(--ink);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.side-brand span {
  color: var(--ink-3);
  font-size: 0.76rem;
}

.side-env {
  padding: 0 8px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
}

.nav-group {
  margin-top: 16px;
  padding: 0 10px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.nav-group:first-child {
  margin-top: 0;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  border-radius: 9px;
  padding: 8px 10px;
  min-height: 38px;
  font-size: 0.9rem;
  cursor: pointer;
}
.nav button:hover {
  background: var(--panel-2);
  color: var(--ink);
}
.nav button svg {
  flex: 0 0 auto;
  opacity: 0.85;
}
.nav button[aria-current='true'] {
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  color: var(--brand);
  font-weight: 600;
}
.nav button[aria-current='true'] svg {
  opacity: 1;
}

.side-foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.side-note {
  margin: 0;
  padding: 0 4px;
  font-size: 0.72rem;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}
.side-note.dim {
  line-height: 1.5;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.5);
  z-index: 25;
}

/* =================================================================== shell */

.shell {
  margin-inline-start: var(--side-w);
  min-height: 100vh;
  padding: 0 clamp(16px, 3vw, 40px) 72px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 0 16px;
  margin-bottom: 4px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-actions {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 10px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 1rem;
  cursor: pointer;
}

.only-narrow {
  display: none;
}

/* ================================================================== fields */

.env-badge {
  display: inline-block;
  width: 100%;
  text-align: center;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-2);
}
.env-badge[data-danger='true'] {
  background: color-mix(in srgb, var(--bad) 18%, transparent);
  border-color: var(--bad);
  color: var(--bad);
}
.env-badge[data-danger='false'] {
  background: color-mix(in srgb, var(--ok) 15%, transparent);
  border-color: var(--ok);
  color: var(--ok);
}

.gate {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
  margin: 12px 0 4px;
  box-shadow: var(--shadow);
}
.gate[hidden] {
  display: none;
}
.gate-actions {
  display: flex;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-3);
  min-width: 0;
}
.field.grow {
  flex: 1 1 260px;
}
.field input,
.field select {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  min-width: 0;
  width: 100%;
}
.field input:focus-visible,
.field select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  color: var(--ink-2);
  white-space: nowrap;
}

button {
  font: inherit;
  font-size: 0.88rem;
  border-radius: 9px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  min-height: 38px;
}
button:hover {
  border-color: var(--brand);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  font-weight: 700;
}
button.ghost {
  background: transparent;
}
button.block {
  width: 100%;
  text-align: center;
  font-size: 0.82rem;
  min-height: 34px;
}
button.tiny {
  font-size: 0.8rem;
  padding: 4px 11px;
  min-height: 31px;
}
button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.banner {
  margin: 14px 0 0;
  padding: 12px 15px;
  border-radius: 10px;
  border: 1px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 13%, transparent);
  font-size: 0.9rem;
}
.banner[data-kind='info'] {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 13%, transparent);
}

/* ================================================================== pages */

main {
  padding-top: 22px;
}

.page[hidden] {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px;
  margin: 0 0 18px;
  box-shadow: var(--shadow);
}
.panel:empty {
  display: none;
}

.row {
  display: flex;
  gap: 14px;
  align-items: center;
}
.row.wrap {
  flex-wrap: wrap;
}

.split {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}
@media (min-width: 1100px) {
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================= stat cards */

.cards {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  margin-bottom: 18px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  border-inline-start: 3px solid var(--accent, var(--line));
  box-shadow: var(--shadow);
}
.card .k {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
  margin-bottom: 4px;
}
.card .v {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.card .sub {
  display: block;
  margin-top: 3px;
  font-size: 0.79rem;
  color: var(--ink-2);
}
.card .delta {
  display: block;
  margin-top: 2px;
  font-size: 0.79rem;
  color: var(--ok);
}
.card .delta[data-zero='true'] {
  color: var(--ink-3);
}

/* =================================================================== funnel */

.funnel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.funnel .bar {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  padding: 11px 15px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.funnel .fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  background: color-mix(in srgb, var(--brand) 24%, transparent);
}
.funnel .bar > span {
  position: relative;
}
.funnel .n {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.note {
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 20px;
  font-size: 0.88rem;
}
.note summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 600;
}
.note ul {
  margin: 12px 0 0;
  padding-inline-start: 20px;
  color: var(--ink-2);
}
.note li {
  margin-bottom: 9px;
  max-width: 80ch;
}
.note b {
  color: var(--ink);
}

/* ==================================================================== chart */

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}
.seg button {
  border: 0;
  border-radius: 0;
  background: transparent;
  min-height: 34px;
  padding: 4px 14px;
  font-size: 0.85rem;
}
.seg button[aria-pressed='true'] {
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
}

#chart svg {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 16px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--ink-2);
}
.legend button {
  border: 0;
  background: transparent;
  padding: 2px 0;
  min-height: 0;
  font-size: inherit;
  color: inherit;
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-inline-end: 6px;
}

/* ===================================================================== feed */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 62vh;
  overflow-y: auto;
}
.feed li {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.9rem;
}
.feed li:first-child {
  padding-top: 0;
}
.feed li:last-child {
  border-bottom: 0;
}
.tag {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent, var(--line)) 22%, transparent);
  color: var(--accent, var(--ink-2));
  white-space: nowrap;
  flex: 0 0 auto;
  min-width: 84px;
  text-align: center;
}
.feed .what {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.feed .when {
  flex: 0 0 auto;
  color: var(--ink-3);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ================================================================= datasets */

.sets {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  margin-bottom: 18px;
}
.set {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.set h3 {
  margin: 0;
  font-size: 0.95rem;
}
.set .desc {
  font-size: 0.82rem;
  color: var(--ink-2);
  margin: 5px 0 14px;
  flex: 1 1 auto;
}
.set .acts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.set[data-available='false'] {
  opacity: 0.5;
}

.progress {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}
.progress i {
  display: block;
  height: 100%;
  background: var(--brand);
  width: 0;
  transition: width 0.2s;
}

/* =================================================================== tables */

.scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 14px;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  white-space: nowrap;
}
th,
td {
  text-align: start;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}
th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover td {
  background: color-mix(in srgb, var(--panel-2) 60%, transparent);
}
td.num {
  font-variant-numeric: tabular-nums;
}
td.wrap {
  white-space: normal;
  min-width: 240px;
  overflow-wrap: anywhere;
}
.mono {
  font-family: ui-monospace, 'Consolas', monospace;
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 0.8rem;
}
/*
 * A raw line from the server (the router status, say) can be one long word with
 * no space in it, which would stretch the whole page unless breaking is allowed
 * anywhere.
 */
.raw {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  text-align: start;
}

/* =================================================================== review */

.item {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.item:last-child {
  margin-bottom: 0;
}
.item .head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}
.item .title {
  font-weight: 700;
}
.item .meta {
  font-size: 0.8rem;
  color: var(--ink-3);
}
.item .body {
  margin: 12px 0;
  overflow-wrap: anywhere;
}
.item .body p {
  margin: 4px 0;
}
.item .acts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/*
 * A pill is one unit: if its text wrapped it would read as two half-pills on a
 * narrow screen. Breaking is forbidden inside, allowed between; an over-long
 * one is clipped with an ellipsis rather than stretching the page.
 */
.pill {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-size: 0.76rem;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.pill[data-tone='warn'] {
  border-color: var(--warn);
  color: var(--warn);
}
.pill[data-tone='bad'] {
  border-color: var(--bad);
  color: var(--bad);
}
.pill[data-tone='ok'] {
  border-color: var(--ok);
  color: var(--ok);
}

.empty {
  color: var(--ink-3);
  font-size: 0.9rem;
  padding: 6px 0;
  margin: 0;
}

/* =================================================================== dialog */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--ink);
  padding: 24px;
  max-width: min(540px, 92vw);
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}
dialog menu {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin: 22px 0 0;
  padding: 0;
}
.confirm-env {
  font-weight: 700;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  margin: 0 0 14px;
  font-size: 0.88rem;
}
.confirm-env[data-danger='true'] {
  border-color: var(--bad);
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
}

.toast {
  position: fixed;
  inset-block-end: 20px;
  inset-inline: 20px;
  margin: auto;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--brand);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  z-index: 40;
  font-size: 0.9rem;
}
.toast[data-kind='bad'] {
  border-color: var(--bad);
}

.skel {
  color: var(--ink-3);
  font-size: 0.9rem;
  padding: 6px 0;
  margin: 0;
}

/* =================================================================== narrow */

@media (max-width: 900px) {
  .side {
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }
  html[dir='rtl'] .side {
    transform: translateX(100%);
  }
  body[data-nav='open'] .side {
    transform: none;
  }
  .shell {
    margin-inline-start: 0;
  }
  .only-narrow {
    display: inline-flex;
    align-items: center;
  }
  .topbar-actions {
    gap: 8px;
  }
  .topbar-actions .muted {
    display: none;
  }
}
