/* Cairo — self-hosted variable font (weights 400–800), arabic + latin subsets */
@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/cairo-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/cairo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --navy: #102a43;
  --navy-2: #1e4b73;
  --gold: #d4a017;
  --ink: #243447;
  --muted: #6b7785;
  --line: #dbe3ec;
  --bg: #eef1f5;
  --surface: #ffffff;
  --ok: #1f7a4d;
  --ok-bg: #e3f3ea;
  --danger: #c0392b;
  --danger-bg: #fce4e2;
  --neutral: #7b8794;
  /* chart series — validated for CVD + contrast on white */
  --chart-gold: #a17c00;
  --chart-blue: #2e6fba;
  --r-s: 8px;
  --r-m: 12px;
  --shadow: 0 1px 3px rgba(16, 42, 67, 0.07);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Cairo", Tahoma, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }
.num { font-variant-numeric: tabular-nums; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--navy);
  padding: 8px 16px;
  border-radius: var(--r-s);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  transition: background 150ms ease-out, border-color 150ms ease-out;
}
.btn:hover { background: #f0f4f8; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: #0b1f33; }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.35); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.1); }
:is(.btn, .link, .tabs button, input, select):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--gold);
  border-radius: var(--r-m);
  padding: 32px 28px;
  width: 352px;
  box-shadow: 0 10px 30px rgba(16, 42, 67, 0.12);
}
.login-card h1 { margin: 0 0 2px; font-size: 20px; font-weight: 700; color: var(--navy); }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 12px; }
.login-card label { display: block; margin: 14px 0 5px; font-size: 12px; font-weight: 600; color: var(--navy); }
.login-card input, .toolbar input, .toolbar select, .u-form input, .u-form select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.login-card .btn { width: 100%; margin-top: 20px; }

/* topbar */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 58px;
  border-bottom: 3px solid var(--gold);
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.brand svg { color: var(--gold); }
.tabs { display: flex; gap: 4px; margin-inline-start: auto; }
.tabs button {
  background: transparent;
  border: 0;
  color: #cdd8e6;
  padding: 8px 14px;
  border-radius: var(--r-s);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 150ms ease-out;
}
.tabs button:hover { background: rgba(255, 255, 255, 0.08); }
.tabs button.on { background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 700; }
.me { display: flex; align-items: center; gap: 12px; font-size: 13px; }

main { max-width: 1200px; margin: 24px auto; padding: 0 20px; }

/* overview header + live indicator */
.ov-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.ov-head h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--navy); }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 122, 77, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(31, 122, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 122, 77, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .live .dot { animation: none; }
}

/* stat tiles */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.card .ic {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f4f8;
  color: var(--navy-2);
}
.card .ic.gold { background: #faf3df; color: #8a6a06; }
.card .ic.ok { background: var(--ok-bg); color: var(--ok); }
.card .ic.bad { background: var(--danger-bg); color: var(--danger); }
.card .k { color: var(--muted); font-size: 12px; }
.card .v {
  font-size: 26px;
  font-weight: 800;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.grid2 .panel { margin-bottom: 0; }
.panel h3 { margin: 0 0 14px; font-size: 14px; font-weight: 700; color: var(--navy); }
.panel .empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

/* donut + legend */
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut-wrap svg { flex: none; }
.donut-total { font-size: 22px; font-weight: 800; fill: var(--navy); }
.donut-total-k { font-size: 10px; fill: var(--muted); }
.legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.legend .lg-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .lg-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .lg-n { font-weight: 700; font-variant-numeric: tabular-nums; }
.legend .lg-pct { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; width: 44px; text-align: end; }

/* ranked bars */
.bar-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; font-size: 13px; }
.bar-row .lbl { width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { flex: 1; height: 10px; background: #eef2f6; border-radius: 5px; overflow: hidden; }
.bar-row .track > i {
  display: block;
  height: 100%;
  background: var(--chart-gold);
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  transition: width 400ms ease-out;
}
.bar-row .n { width: 48px; text-align: start; font-weight: 700; font-variant-numeric: tabular-nums; }

/* activity chart */
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 3px; }
#activity-chart { width: 100%; }
#activity-chart .hit { fill: transparent; cursor: default; }
#activity-chart .hit:hover { fill: rgba(16, 42, 67, 0.05); }
#activity-chart .axis-lbl { font-size: 10px; fill: var(--muted); font-family: inherit; }
#activity-chart .grid-line { stroke: #eef2f6; stroke-width: 1; }

/* tooltip */
.tip {
  position: fixed;
  z-index: 90;
  background: var(--navy);
  color: #fff;
  border-radius: var(--r-s);
  padding: 8px 12px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(16, 42, 67, 0.3);
  max-width: 240px;
}
.tip .t-title { font-weight: 700; margin-bottom: 3px; }
.tip .t-row { display: flex; align-items: center; gap: 6px; }
.tip .sw { width: 8px; height: 8px; border-radius: 2px; flex: none; }

/* toolbar + table */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 240px; }
.toolbar select { width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid #eef2f6; white-space: nowrap; }
th { background: #f7f9fc; color: var(--navy); font-size: 12px; font-weight: 700; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbfd; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--danger-bg); color: var(--danger); }
.badge.role { background: #edf1f6; color: var(--navy-2); }
.link { color: var(--navy-2); cursor: pointer; text-decoration: underline; background: none; border: 0; font-size: 13px; font-family: inherit; padding: 2px 4px; border-radius: 4px; }
.link.danger { color: var(--danger); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 14px 0; }
.u-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.u-form input { width: auto; flex: 1; min-width: 160px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(16, 42, 67, 0.5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card {
  background: var(--surface);
  border-radius: var(--r-m);
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  padding: 24px;
  position: relative;
}
.modal-x { position: absolute; inset-inline-start: 14px; top: 12px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; border-radius: 6px; }
.modal-x:hover { color: var(--ink); background: #f0f4f8; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; padding-inline-start: 30px; }
.modal-card h2 { margin: 0; color: var(--navy); font-size: 18px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 7px 14px; margin-top: 14px; font-size: 13px; }
.kv .k { color: var(--muted); }
.kv .v-cell { overflow-wrap: anywhere; }
.modal-card h3 { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--navy); }
.modal-card table { margin-top: 6px; border: 1px solid var(--line); border-radius: var(--r-s); }
.detail-group { border: 1px solid var(--line); border-radius: var(--r-s); padding: 12px 14px; margin-top: 10px; }
.detail-group > .dg-title { font-size: 12px; font-weight: 700; color: var(--navy-2); margin-bottom: 6px; }

/* edit form */
.edit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-top: 14px; }
.edit-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--navy); }
.edit-form input, .edit-form select {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--r-s);
  font-size: 14px; font-family: inherit; font-weight: 400; background: var(--surface); color: var(--ink);
}
.edit-form .edit-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 6px; }
.edit-form .err { grid-column: 1 / -1; margin: 0; }

/* attribution (view-only, never exported) — collapsed behind a checkbox */
.att-toggle {
  display: flex; align-items: center; gap: 8px;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.att-toggle input { accent-color: var(--navy); cursor: pointer; }
.att-toggle:hover { color: var(--ink); }
.attribution { background: #f7f9fc; border: 1px solid var(--line); border-radius: var(--r-s); padding: 12px 14px; margin-top: 10px; }
.attribution .att-note { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.attribution .kv { margin-top: 0; }

@media (max-width: 800px) {
  .edit-form { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .tabs { font-size: 12px; }
  .donut-wrap { flex-direction: column; align-items: stretch; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv .k { margin-top: 8px; }
}
