/* حارس طالب برو — لوحة التحكم
   Direction: calm "control room" in the platform's own pine + lime.
   Pine = dominant brand surface, lime = the one accent, neutrals come from Telegram. */

:root {
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;

  /* type scale, ratio 1.25 on 16 */
  --t-xs: 12.8px;
  --t-sm: 14px;
  --t-md: 16px;
  --t-lg: 20px;
  --t-xl: 25px;
  --t-2xl: 31px;
  --t-hero: 48px;

  /* 8px grid */
  --s-1: 4px;
  --s0: 8px;
  --s1: 12px;
  --s2: 16px;
  --s3: 24px;
  --s4: 32px;
  --s5: 40px;

  --r-xl: 22px;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 8px;
  --r-pill: 999px;

  --pine: #082b2d;
  --pine-2: #0e3f40;
  --lime: #d3fa58;
  --ok: #0f7d47;
  --ok-deep: #0a5532;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 200ms;

  --tab-h: 64px;
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

/* fallback neutrals (used outside Telegram / when theme vars are missing) */
[data-theme="light"] {
  --bg-fb: #eef1ed;
  --card-fb: #ffffff;
  --text-fb: #102122;
  --danger-fb: #c0362c;

  --accent: #0f6b64;            /* accent ink on neutral surfaces (6.1:1 on white) */
  --accent-wash: rgba(15, 107, 100, .10);
  --accent-wash-2: rgba(15, 107, 100, .18);
  --primary-bg: var(--pine);
  --primary-fg: var(--lime);
  --primary-sh: #000c0d;
  --sel-bg: var(--pine);
  --sel-fg: #f1f4e7;
  --hero-bg: var(--pine);
  --hero-line: rgba(211, 250, 88, .16);
  --mark-bg: var(--pine);
  --mark-fg: var(--lime);
  --warn: #8a5a00;
  --warn-wash: #fff3d6;
  --danger-wash: rgba(192, 54, 44, .09);
  --ok-wash: rgba(15, 125, 71, .10);
  --ok-ink: #0d6e3f;
  --shadow: 0 1px 2px rgba(8, 43, 45, .06), 0 4px 16px rgba(8, 43, 45, .05);
  --shadow-lg: 0 -8px 40px rgba(8, 43, 45, .18);
  --scrim: rgba(6, 22, 23, .48);
  --skel: rgba(8, 43, 45, .07);
}

[data-theme="dark"] {
  --bg-fb: #0c1414;
  --card-fb: #152120;
  --text-fb: #e9efe7;
  --danger-fb: #ff7a6e;

  --accent: #d3fa58;
  --accent-wash: rgba(211, 250, 88, .10);
  --accent-wash-2: rgba(211, 250, 88, .18);
  --primary-bg: var(--lime);
  --primary-fg: var(--pine);
  --primary-sh: #8fb02a;
  --sel-bg: var(--lime);
  --sel-fg: var(--pine);
  --hero-bg: #0d3537;
  --hero-line: rgba(211, 250, 88, .14);
  --mark-bg: var(--lime);
  --mark-fg: var(--pine);
  --warn: #ffc65a;
  --warn-wash: rgba(255, 198, 90, .12);
  --danger-wash: rgba(255, 122, 110, .12);
  --ok-wash: rgba(76, 214, 140, .12);
  --ok-ink: #6fe0a4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 -8px 40px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .6);
  --skel: rgba(255, 255, 255, .07);
}

:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--bg-fb));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--card-fb)));
  --text: var(--tg-theme-text-color, var(--text-fb));
  --danger: var(--tg-theme-destructive-text-color, var(--danger-fb));
  /* hint derived from text so it always clears AA, whatever Telegram's hint color is */
  --muted: color-mix(in srgb, var(--text) 64%, var(--card));
  --faint: color-mix(in srgb, var(--text) 46%, var(--card));
  --line: color-mix(in srgb, var(--text) 10%, var(--card));
  --line-2: color-mix(in srgb, var(--text) 16%, var(--card));
  --field: color-mix(in srgb, var(--text) 5%, var(--card));
  --raise: color-mix(in srgb, var(--text) 4%, var(--card));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea { outline: none; }
img, svg { display: block; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 16px; height: 16px; }
svg.i.lg { width: 24px; height: 24px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s1);
  padding: calc(var(--s1) + var(--tg-content-safe-area-inset-top, 0px)) var(--s2) var(--s1);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.brand { display: flex; align-items: center; gap: var(--s1); min-width: 0; }
.brand-mark svg { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: var(--t-lg); font-weight: 700; }
.brand-text span { font-size: var(--t-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-pill);
  display: grid; place-items: center; color: var(--text);
  background: var(--card); box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }

/* ---------- view ---------- */
.view {
  max-width: 760px; margin: 0 auto;
  padding: var(--s0) var(--s2) calc(var(--tab-h) + var(--safe-b) + var(--s4));
  outline: none;
}
.view > * + * { margin-top: var(--s2); }
.view.enter { animation: viewIn 220ms var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.sec-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s0);
  margin: var(--s3) var(--s-1) calc(var(--s0) * -1);
  font-size: var(--t-md); font-weight: 700;
}
.sec-title small { font-size: var(--t-xs); font-weight: 400; color: var(--muted); }

.card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: var(--s2);
}
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); margin-bottom: var(--s1); }
.card-h h3 { margin: 0; font-size: var(--t-md); font-weight: 700; }
.card-h .sub { font-size: var(--t-xs); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: var(--t-sm); }
.xs { font-size: var(--t-xs); }
.grid2 { display: grid; gap: var(--s2); }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } .grid2 > * + * { margin-top: 0; } }

/* ---------- segmented / chips ---------- */
.seg {
  display: flex; padding: 4px; gap: 4px;
  background: var(--card); border-radius: var(--r-pill); box-shadow: var(--shadow);
}
.seg button {
  flex: 1; min-height: 40px; border-radius: var(--r-pill);
  font-size: var(--t-sm); font-weight: 500; color: var(--muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  white-space: nowrap; padding: 0 var(--s1);
}
.seg button[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-fg); font-weight: 700; }
.hero .seg { background: rgba(255,255,255,.07); box-shadow: none; }
.hero .seg button { color: rgba(241,244,231,.78); }
.hero .seg button[aria-pressed="true"] { background: var(--lime); color: var(--pine); }

.chips { display: flex; gap: var(--s0); overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--s2) * -1); padding: 2px var(--s2); }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin-inline: 0; padding: 0; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 var(--s2);
  border-radius: var(--r-pill);
  background: var(--card); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-2);
  font-size: var(--t-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.chip .cnt { font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-fg); box-shadow: none; }
.chip[aria-pressed="true"] .cnt { color: inherit; opacity: .8; }
.card .chip:not([aria-pressed="true"]) { background: var(--card); }

.tag-chip {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 36px; padding: 0 var(--s1) 0 4px;
  border-radius: var(--r-pill); background: var(--field);
  font-size: var(--t-sm); direction: ltr;
}
.tag-chip button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.tag-chip button:active { background: var(--line); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-weight: 500; line-height: 1.6; white-space: nowrap;
  background: var(--field); color: var(--muted);
}
.badge.ok { background: var(--ok-wash); color: var(--ok-ink); }
.badge.bad { background: var(--danger-wash); color: var(--danger); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.acc { background: var(--accent-wash); color: var(--accent); }
.badge svg.i { width: 13px; height: 13px; stroke-width: 2.4; }

/* ---------- hero (dashboard focal point) ---------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--hero-bg); color: #f1f4e7;
  border-radius: var(--r-xl); padding: var(--s2) var(--s2) var(--s3);
  box-shadow: 0 8px 28px rgba(8, 43, 45, .22);
}
.hero::after { /* quiet grid texture = the "control room" signature */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(var(--hero-line) 1px, transparent 1px), linear-gradient(90deg, var(--hero-line) 1px, transparent 1px);
  background-size: 24px 24px; opacity: .5;
  mask-image: linear-gradient(to bottom, transparent, #000 60%, #000);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 60%, #000);
}
.hero > * { position: relative; z-index: 1; }
.hero-status { display: flex; align-items: center; gap: var(--s0); font-size: var(--t-sm); color: rgba(241,244,231,.86); margin: var(--s2) 0 var(--s-1); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 0 rgba(211,250,88,.6); animation: pulse 2.4s var(--ease) infinite; }
.live-dot.off { background: #ffb4a8; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(211,250,88,.5); } 70% { box-shadow: 0 0 0 10px rgba(211,250,88,0); } 100% { box-shadow: 0 0 0 0 rgba(211,250,88,0); } }
.hero-fig { display: flex; flex-direction: column; }
.hero-num { font-size: var(--t-hero); font-weight: 700; line-height: 1.05; letter-spacing: -.5px; color: #fff; }
.hero-lbl { font-size: var(--t-sm); color: rgba(241,244,231,.78); margin-top: 4px; }
.hero-delta { align-self: flex-start; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-xs); padding: 2px 8px; border-radius: var(--r-pill); background: rgba(211,250,88,.14); color: var(--lime); margin-top: var(--s0); }
.hero-delta.down { background: rgba(255,255,255,.1); color: rgba(241,244,231,.85); }
.hero-spark { width: 100%; height: 64px; margin-top: var(--s2); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s0); }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border-radius: var(--r-lg); padding: var(--s1) var(--s2); box-shadow: var(--shadow); min-height: 96px; display: flex; flex-direction: column; gap: 2px; }
.kpi-l { display: flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--muted); line-height: 1.4; }
.kpi-l svg.i { width: 16px; height: 16px; color: var(--accent); }
.kpi-v { font-size: var(--t-xl); font-weight: 700; line-height: 1.25; }
.delta { font-size: var(--t-xs); display: inline-flex; align-items: center; gap: 2px; color: var(--muted); line-height: 1.4; }
.delta.good { color: var(--ok-ink); }
.delta.bad { color: var(--danger); }
.delta svg.i { width: 14px; height: 14px; stroke-width: 2.2; }

/* ---------- charts ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-lbl { display: flex; justify-content: space-between; align-items: baseline; margin: var(--s0) 0 2px; font-size: var(--t-sm); }
.chart-lbl b { font-weight: 500; }
.chart-lbl span { font-size: var(--t-xs); color: var(--muted); }
.axis text { font-size: 11px; fill: var(--muted); font-family: var(--font); font-variant-numeric: tabular-nums; }
.grid-l { stroke: var(--line); stroke-width: 1; }
.s-line { stroke: var(--accent); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.s-area { fill: var(--accent); opacity: .1; }
.s-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.x-hair { stroke: var(--line-2); stroke-width: 1; }
.tip {
  position: absolute; z-index: 3; pointer-events: none;
  background: var(--text); color: var(--card);
  padding: 6px 10px; border-radius: var(--r-sm); font-size: var(--t-xs); line-height: 1.5;
  white-space: nowrap; transform: translate(50%, -100%); top: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.tip b { font-weight: 700; }

.bars { display: flex; flex-direction: column; gap: var(--s1); }
.bar-row { display: grid; grid-template-columns: 112px 1fr 44px; align-items: center; gap: var(--s0); font-size: var(--t-sm); }
.bar-row .bl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bt { height: 12px; border-radius: 0 4px 4px 0; background: transparent; position: relative; }
.bar-row .bf { position: absolute; inset-block: 0; right: 0; background: var(--accent); border-radius: 4px 0 0 4px; min-width: 2px; transition: width 400ms var(--ease); }
.bar-row .bv { text-align: left; font-variant-numeric: tabular-nums; color: var(--muted); font-size: var(--t-xs); }

.hours { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; }
.hours button { height: 40px; min-width: 0; border-radius: 4px; background: var(--accent); }
.hours-ax { display: grid; grid-template-columns: repeat(4, 1fr); font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.hours-note { font-size: var(--t-xs); color: var(--muted); margin-top: var(--s0); min-height: 20px; }
.hours-note b { color: var(--text); font-weight: 500; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: var(--s1);
  padding: var(--s1) var(--s2); min-height: 56px; width: 100%; text-align: right;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
button.row:active, .row.tap:active { background: var(--raise); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.45; }
.row-t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-s { font-size: var(--t-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { flex: none; display: flex; align-items: center; gap: 6px; font-size: var(--t-sm); color: var(--muted); }
.row-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.rank { width: 24px; flex: none; text-align: center; font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-wash-2); color: var(--accent);
  font-weight: 700; font-size: var(--t-sm);
}
.avatar.lg { width: 64px; height: 64px; font-size: var(--t-lg); }
.mini-bar { width: 40px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; margin-right: 0; }
.chev { color: var(--faint); }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s1) var(--s0); }
@media (min-width: 560px) { .totals { grid-template-columns: repeat(6, 1fr); } }
.totals div { display: flex; flex-direction: column; line-height: 1.35; }
.totals b { font-size: var(--t-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.totals span { font-size: var(--t-xs); color: var(--muted); }

.q-item { padding: var(--s1) var(--s2); border-bottom: 1px solid var(--line); }
.q-item:last-child { border-bottom: 0; }
.q-q { font-weight: 500; line-height: 1.55; }
.q-a { font-size: var(--t-sm); color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.q-item.open .q-a { -webkit-line-clamp: unset; display: block; }
.q-meta { display: flex; align-items: center; gap: var(--s0); flex-wrap: wrap; margin-top: 6px; font-size: var(--t-xs); color: var(--muted); }

/* ---------- groups / perms ---------- */
.grp { padding: var(--s1) 0; border-bottom: 1px solid var(--line); }
.grp:last-child { border-bottom: 0; padding-bottom: 0; }
.grp:first-child { padding-top: 0; }
.grp-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s0); }
.grp-t { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perms { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.alert {
  display: flex; gap: var(--s0); align-items: flex-start;
  padding: var(--s1); border-radius: var(--r-md);
  background: var(--warn-wash); color: var(--warn);
  font-size: var(--t-sm); line-height: 1.55; margin-top: var(--s0);
}
.alert svg.i { margin-top: 2px; }
.alert.info { background: var(--accent-wash); color: var(--text); }
.alert.info svg.i { color: var(--accent); }
.alert.danger { background: var(--danger-wash); color: var(--danger); }

.kn { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s0); margin-bottom: var(--s1); }
.kn div { background: var(--field); border-radius: var(--r-md); padding: var(--s0) var(--s1); display: flex; flex-direction: column; line-height: 1.35; }
.kn b { font-size: var(--t-lg); font-variant-numeric: tabular-nums; }
.kn span { font-size: var(--t-xs); color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s0);
  min-height: 48px; padding: 0 var(--s3);
  border-radius: var(--r-md); font-weight: 700; font-size: var(--t-md);
  background: var(--primary-bg); color: var(--primary-fg);
  box-shadow: 0 3px 0 var(--primary-sh);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), opacity var(--dur);
  white-space: nowrap;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--primary-sh); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.block { width: 100%; }
a.btn { text-decoration: none; }
.btn.ghost { background: var(--field); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.btn.ghost:active { transform: scale(.98); }
.btn.sm { min-height: 40px; padding: 0 var(--s2); font-size: var(--t-sm); border-radius: var(--r-sm); }
.btn.danger { background: var(--danger-wash); color: var(--danger); box-shadow: none; }
.btn.dangerfill { background: var(--danger); color: #fff; box-shadow: none; }
[data-theme="dark"] .btn.dangerfill { color: #2a0906; }
.btn.okfill { background: var(--ok); color: #fff; box-shadow: 0 3px 0 var(--ok-deep); }
.btn.loading { pointer-events: none; opacity: .8; }
.btn.loading::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-left-color: transparent; animation: spin .7s linear infinite; }
.btn-row { display: flex; gap: var(--s0); flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
.link-btn { color: var(--accent); font-weight: 500; font-size: var(--t-sm); min-height: 44px; padding: 0 var(--s0); display: inline-flex; align-items: center; gap: 4px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--s2); }
.field label, .lbl { font-size: var(--t-sm); font-weight: 500; }
.field .hint { font-size: var(--t-xs); color: var(--muted); line-height: 1.5; }
.inp, .ta {
  width: 100%; min-height: 48px; padding: var(--s1) var(--s2);
  border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--field); font-size: var(--t-md);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.inp:focus, .ta:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.ta { min-height: 140px; resize: vertical; line-height: 1.7; }
.ta.tall { min-height: 220px; font-size: var(--t-sm); }
.inp.code { text-align: center; letter-spacing: 8px; font-size: var(--t-xl); font-weight: 700; direction: ltr; }
.inp[dir="ltr"] { text-align: left; }
.inp::placeholder, .ta::placeholder { color: var(--faint); }
.counter { font-size: var(--t-xs); color: var(--muted); text-align: left; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); }
.inline-add { display: flex; gap: var(--s0); margin-top: var(--s1); }
.inline-add .inp { flex: 1; min-width: 0; }
.inline-add .btn { padding: 0 var(--s2); }

.search { position: relative; }
.search svg.i { position: absolute; top: 50%; right: var(--s2); transform: translateY(-50%); color: var(--muted); }
.search .inp { padding-right: 48px; background: var(--card); border-color: transparent; box-shadow: var(--shadow); min-height: 52px; border-radius: var(--r-lg); }
.search .inp:focus { border-color: var(--accent); }
.search .clr { position: absolute; top: 50%; left: 4px; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); }

/* switch */
.tg-row { display: flex; align-items: center; gap: var(--s1); padding: var(--s1) var(--s2); min-height: 64px; border-bottom: 1px solid var(--line); width: 100%; text-align: right; }
.tg-row:last-child { border-bottom: 0; }
.tg-row .row-main .row-t { white-space: normal; }
.tg-row .row-main .row-s { white-space: normal; line-height: 1.5; margin-top: 2px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--line-2); transition: background var(--dur) var(--ease); }
.switch span::after { content: ""; position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--dur) var(--ease); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(-20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--field); border-radius: var(--r-pill); padding: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); }
.stepper button:disabled { opacity: .4; }
.stepper b { min-width: 40px; text-align: center; font-size: var(--t-lg); font-variant-numeric: tabular-nums; }
.set-line { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding: var(--s1) 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.set-line:last-child { border-bottom: 0; padding-bottom: 0; }
.set-line:first-child { padding-top: 0; }
.set-line .seg { box-shadow: none; background: var(--field); }
.set-line .row-main { min-width: 160px; }
.set-line .row-t, .set-line .row-s { white-space: normal; }

/* photo picker */
.picker { display: flex; align-items: center; gap: var(--s1); }
.pick-btn { display: inline-flex; align-items: center; gap: var(--s0); min-height: 44px; padding: 0 var(--s2); border-radius: var(--r-md); border: 1px dashed var(--line-2); color: var(--muted); font-size: var(--t-sm); position: relative; overflow: hidden; }
.pick-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.preview { position: relative; margin-top: var(--s1); border-radius: var(--r-md); overflow: hidden; background: var(--field); }
.preview img { width: 100%; max-height: 260px; object-fit: cover; }
.preview .rm { position: absolute; top: 8px; left: 8px; width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }

/* broadcast */
.compose { border: 1px solid transparent; }
.aud { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s0); }
.aud button {
  min-height: 64px; border-radius: var(--r-md); padding: var(--s0);
  background: var(--field); box-shadow: inset 0 0 0 1px var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.3;
  font-size: var(--t-xs); color: var(--muted); text-align: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.aud button b { font-size: var(--t-lg); color: var(--text); font-variant-numeric: tabular-nums; }
.aud button[aria-pressed="true"] { background: var(--sel-bg); color: var(--sel-fg); box-shadow: none; }
.aud button[aria-pressed="true"] b { color: inherit; }
.divider { height: 1px; background: var(--line); margin: var(--s2) 0; }
.bc-item { padding: var(--s2); border-bottom: 1px solid var(--line); }
.bc-item:last-child { border-bottom: 0; }
.bc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s1); }
.bc-text { font-size: var(--t-sm); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bc-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.prog { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: var(--s1); display: flex; gap: 2px; }
.prog i { display: block; height: 100%; background: var(--accent); transition: width 600ms var(--ease); }
.prog i.f { background: var(--danger); opacity: .7; }
.bc-nums { display: flex; flex-wrap: wrap; gap: 4px var(--s2); margin-top: var(--s0); font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.bc-nums b { color: var(--text); font-weight: 500; }
.key { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-left: 4px; vertical-align: middle; }
.key.f { background: var(--danger); opacity: .7; }
.key.b { background: var(--line-2); }

/* log */
.log-item { display: flex; gap: var(--s1); padding: var(--s1) var(--s2); border-bottom: 1px solid var(--line); }
.log-item:last-child { border-bottom: 0; }
.log-ic { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--field); color: var(--muted); margin-top: 2px; }
.log-ic.bad { background: var(--danger-wash); color: var(--danger); }
.log-ic.warn { background: var(--warn-wash); color: var(--warn); }
.log-ic.ok { background: var(--ok-wash); color: var(--ok-ink); }
.log-ic svg.i { width: 18px; height: 18px; }
.log-body { flex: 1; min-width: 0; }
.log-t { font-weight: 500; line-height: 1.5; }
.log-t .who { color: var(--accent); }
.quote { margin-top: 6px; padding: 6px 10px; border-right: 3px solid var(--line-2); background: var(--field); border-radius: var(--r-sm) 0 0 var(--r-sm); font-size: var(--t-sm); color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.log-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s0); margin-top: 6px; flex-wrap: wrap; }
.log-foot .xs { color: var(--muted); }

.rep { padding: var(--s2); }
.rep + .rep { border-top: 1px solid var(--line); }
.rep-top { display: flex; gap: var(--s1); }
.thumb { width: 84px; height: 112px; flex: none; border-radius: var(--r-md); overflow: hidden; background: var(--field); position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.empty { display: grid; place-items: center; color: var(--faint); }
.cand { display: flex; align-items: center; gap: var(--s1); padding: var(--s0) 0; border-top: 1px solid var(--line); }
.cand:first-child { border-top: 0; }
.score { font-size: var(--t-xs); font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- empty / skeleton / states ---------- */
.empty { text-align: center; padding: var(--s4) var(--s3); color: var(--muted); }
.empty .ei { width: 56px; height: 56px; margin: 0 auto var(--s1); border-radius: 50%; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent); }
.empty b { display: block; color: var(--text); font-size: var(--t-md); margin-bottom: 4px; }
.empty p { margin: 0; font-size: var(--t-sm); line-height: 1.6; }
.sk { background: var(--skel); border-radius: var(--r-sm); position: relative; overflow: hidden; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: shimmer 1.3s infinite; }
[data-theme="dark"] .sk::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes shimmer { to { transform: translateX(-100%); } }
.sk-line { height: 14px; margin: 8px 0; }
.more { padding: var(--s2); text-align: center; color: var(--muted); font-size: var(--t-sm); }

.gate { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--s4) var(--s3); gap: var(--s1); }
.gate .gm svg { width: 88px; height: 88px; }
.gate h1 { margin: var(--s1) 0 0; font-size: var(--t-xl); line-height: 1.4; }
.gate p { margin: 0 0 var(--s2); color: var(--muted); max-width: 32ch; line-height: 1.7; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px max(var(--s0), calc((100vw - 760px) / 2)) calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; color: var(--muted); font-size: 11.5px; font-weight: 500; line-height: 1.3;
  position: relative;
}
.tab .ti { width: 56px; height: 30px; border-radius: var(--r-pill); display: grid; place-items: center; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.tab[aria-current="page"] { color: var(--text); font-weight: 700; }
.tab[aria-current="page"] .ti { background: var(--sel-bg); color: var(--sel-fg); }
.tab .dot { position: absolute; top: 4px; left: calc(50% - 22px); width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--card); }

/* ---------- layers: sheet, modal, viewer ---------- */
.layer { position: fixed; inset: 0; z-index: 50; }
.scrim { position: absolute; inset: 0; background: var(--scrim); animation: fadeIn var(--dur) var(--ease); }
.layer.closing .scrim { animation: fadeOut 180ms var(--ease) forwards; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
.sheet {
  position: absolute; inset-inline: 0; bottom: 0; max-height: 94vh;
  max-width: 760px; margin: 0 auto;
  background: var(--bg); border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: sheetIn 240ms var(--ease);
}
.layer.closing .sheet { animation: sheetOut 180ms var(--ease) forwards; }
@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheetOut { to { transform: translateY(40px); opacity: 0; } }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding: var(--s1) var(--s2) var(--s0); }
.sheet-h::before { content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); }
.sheet-h h2 { margin: var(--s0) 0 0; font-size: var(--t-lg); }
.sheet-b { overflow-y: auto; padding: var(--s0) var(--s2) calc(var(--s3) + var(--safe-b)); overscroll-behavior: contain; }
.sheet-b > * + * { margin-top: var(--s2); }

.modal-wrap { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: var(--s2); padding-bottom: calc(var(--s2) + var(--safe-b)); }
@media (min-width: 560px) { .modal-wrap { align-items: center; } }
.modal {
  position: relative; width: 100%; max-width: 420px;
  background: var(--card); border-radius: var(--r-xl); padding: var(--s3) var(--s2) var(--s2);
  box-shadow: 0 16px 48px rgba(0,0,0,.28);
  animation: modalIn 220ms var(--ease);
}
.layer.closing .modal { animation: sheetOut 160ms var(--ease) forwards; }
@keyframes modalIn { from { transform: translateY(16px) scale(.98); opacity: 0; } }
.modal h2 { margin: 0; font-size: var(--t-lg); line-height: 1.45; }
.modal p { margin: var(--s0) 0 0; color: var(--muted); font-size: var(--t-sm); line-height: 1.7; }
.modal .extra { margin-top: var(--s2); }
.modal .extra .chips { margin: 0; padding: 0; flex-wrap: wrap; }
.modal-btns { display: flex; gap: var(--s1); margin-top: var(--s3); } /* RTL: first child sits on the right */
.modal-btns .back { flex: 1; min-height: 52px; border-radius: var(--r-md); font-weight: 700; background: var(--field); box-shadow: inset 0 0 0 1px var(--line-2); }
.modal-btns .back:active { transform: scale(.98); }
.btn-yes {
  flex: 1.4; min-height: 52px; border-radius: var(--r-md);
  font-weight: 700; font-size: var(--t-md); color: #fff;
  background: linear-gradient(180deg, #149456 0%, var(--ok) 100%);
  box-shadow: 0 4px 0 var(--ok-deep), 0 6px 14px rgba(15, 125, 71, .35), inset 0 1px 0 rgba(255,255,255,.22);
  text-shadow: 0 1px 0 rgba(0,0,0,.18);
  transition: transform 100ms var(--ease), box-shadow 100ms var(--ease);
}
.btn-yes:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ok-deep), 0 2px 6px rgba(15, 125, 71, .3), inset 0 1px 0 rgba(255,255,255,.22); }

.viewer { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s2); }
.viewer img { max-width: 100%; max-height: 88vh; border-radius: var(--r-md); }
.viewer .close { position: absolute; top: calc(var(--s2) + var(--tg-content-safe-area-inset-top, 0px)); left: var(--s2); width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; }

.close-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--card); box-shadow: var(--shadow); flex: none; }

/* member sheet */
.m-head { display: flex; align-items: center; gap: var(--s2); }
.m-head h3 { margin: 0; font-size: var(--t-lg); line-height: 1.35; word-break: break-word; }
.m-id { font-size: var(--t-xs); color: var(--muted); }
.m-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s0); }
.m-stats div { background: var(--card); border-radius: var(--r-md); padding: var(--s0) var(--s1); box-shadow: var(--shadow); display: flex; flex-direction: column; line-height: 1.35; }
.m-stats b { font-size: var(--t-lg); font-variant-numeric: tabular-nums; }
.m-stats span { font-size: var(--t-xs); color: var(--muted); }
.acts { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s0); }
@media (min-width: 560px) { .acts { grid-template-columns: repeat(4, 1fr); } }
.act {
  min-height: 56px; border-radius: var(--r-md); background: var(--card); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: var(--s0); padding: 0 var(--s1);
  font-weight: 500; font-size: var(--t-sm); text-align: right;
}
.act:active { transform: scale(.98); }
.act .ai { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--field); flex: none; }
.act.bad { color: var(--danger); }
.act.bad .ai { background: var(--danger-wash); }
.act.warn .ai { background: var(--warn-wash); color: var(--warn); }
.act.ok .ai { background: var(--ok-wash); color: var(--ok-ink); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s2); font-size: var(--t-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: left; font-variant-numeric: tabular-nums; }

/* wizard */
.steps { display: flex; align-items: center; gap: var(--s0); margin: var(--s1) 0 var(--s2); }
.steps .st { display: flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--muted); }
.steps .st i { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 700; background: var(--field); box-shadow: inset 0 0 0 1px var(--line-2); font-variant-numeric: tabular-nums; }
.steps .st.on { color: var(--text); font-weight: 500; }
.steps .st.on i { background: var(--sel-bg); color: var(--sel-fg); box-shadow: none; }
.steps .st.done i { background: var(--ok); color: #fff; box-shadow: none; }
.steps .ln { flex: 1; height: 1px; background: var(--line-2); min-width: 8px; }
.guide { margin: 0; padding: 0; list-style: none; counter-reset: g; display: flex; flex-direction: column; gap: var(--s0); }
.guide li { counter-increment: g; display: flex; gap: var(--s1); font-size: var(--t-sm); line-height: 1.6; }
.guide li::before { content: counter(g); flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent); font-weight: 700; font-size: var(--t-xs); margin-top: 1px; }
.guide code { direction: ltr; unicode-bidi: isolate; background: var(--field); padding: 0 6px; border-radius: 4px; font-family: var(--font); font-weight: 500; }
.why { display: flex; flex-direction: column; gap: 6px; margin: 0 0 var(--s2); padding: 0; list-style: none; }
.why li { display: flex; gap: var(--s0); font-size: var(--t-sm); line-height: 1.6; }
.why li svg.i { color: var(--ok-ink); margin-top: 2px; width: 18px; height: 18px; }
.acc-head { display: flex; align-items: center; gap: var(--s1); }
.acc-grp { padding: var(--s1) 0; border-top: 1px solid var(--line); }
.acc-grp .btn-row { margin-top: var(--s0); }

/* ---------- toast ---------- */
.toasts { position: fixed; z-index: 90; inset-inline: var(--s2); top: calc(var(--s1) + var(--tg-content-safe-area-inset-top, 0px)); display: flex; flex-direction: column; align-items: center; gap: var(--s0); pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 460px; width: 100%;
  display: flex; align-items: flex-start; gap: var(--s0);
  background: var(--text); color: var(--card);
  padding: var(--s1) var(--s2); border-radius: var(--r-md);
  font-size: var(--t-sm); line-height: 1.55; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: toastIn 220ms var(--ease);
}
.toast.out { animation: toastOut 180ms var(--ease) forwards; }
.toast .ic { width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--ok); color: #fff; margin-top: 1px; }
.toast.err .ic { background: var(--danger-fb); }
.toast .ic svg.i { width: 14px; height: 14px; stroke-width: 2.6; }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-12px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .live-dot { animation: none; }
}
