/* ==========================================================================

   TRADER COMMUNITY — DESIGN SYSTEM

   Design language: INSTITUTIONAL SLATE & COBALT
   Authority: DESIGN_SYSTEM.md + .agents/skills/trader-community-master-design

   ---------------------------------------------------------------------------

   A dark operational system built from tonal separation and hairline borders,
   not from glow or glass. Depth comes from surface tiers; emphasis comes from
   weight, size and semantic colour. Cobalt is reserved for action, selection
   and focus — never for decoration.

   Financial figures use the UI face with tabular lining numerals so columns
   align without adopting a terminal costume. Monospace is reserved for
   identifiers and code, not for money.

   All logical properties preserved. All RTL rules preserved. All accessibility
   guards preserved.

   ========================================================================== */

:root {
  color-scheme: dark;

  /* -- Design Tokens: Institutional Slate & Cobalt */
  --bg-base:        #090A0D;
  --bg-surface:     #12141A;
  --bg-surface-2:   #1A1D24;
  --bg-elevated:    #1F222B;
  --bg-overlay:     rgba(9, 10, 13, 0.8);

  --border-subtle:  #1A1D24;
  --border-default: #242833;
  --border-strong:  #383E4C;

  --text-primary:   #F0F2F5;
  --text-secondary: #A0A8B8;
  --text-muted:     #81899B;
  --text-disabled:  #4A5161;

  --accent:         #6988FA;
  --accent-hover:   #6182F9;
  --accent-subtle:  rgba(105, 136, 250, 0.12);

  --focus-ring:     rgba(105, 136, 250, 0.5);

  --profit-subtle:  rgba(16, 185, 129, 0.12);
  --loss-subtle:    rgba(239, 68, 68, 0.12);

  --success:        #10B981;
  --warning:        #F59E0B;
  --critical:       #EF4444;
  --info:           #3B82F6;
  --pending:        #8B5CF6;
  --verified:       #6988FA;
  --disabled:       #4A5161;

  /* -- Legacy Aliases mapped to new tokens -- */
  --plane:          var(--bg-base);
  --surface-0:      var(--bg-surface);
  --surface-1:      var(--bg-surface);
  --surface-2:      var(--bg-surface-2);
  --surface-3:      var(--bg-elevated);
  --surface-4:      var(--bg-elevated);
  --surface-glass:  var(--bg-overlay);
  --border:         var(--border-default);
  --border-faint:   var(--border-subtle);
  --primary:        var(--accent);
  --primary-hover:  var(--accent-hover);
  --primary-press:  var(--accent);
  --primary-soft:   var(--accent-subtle);
  --primary-ring:   var(--focus-ring);
  --danger:         var(--critical);
  --danger-soft:    var(--loss-subtle);
  --danger-border:  var(--loss-subtle);
  --success-soft:   var(--profit-subtle);
  --success-border: var(--profit-subtle);
  --warning-soft:   rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.3);
  --info-soft:      rgba(59, 130, 246, 0.12);
  --info-border:    rgba(59, 130, 246, 0.3);
  
  --ai:             #8B5CF6; /* mapped to pending/violet */
  --ai-soft:        rgba(139, 92, 246, 0.12);
  --ai-border:      rgba(139, 92, 246, 0.3);
  --good:           var(--success);
  
  --vip:            var(--verified);

  --text-inverse:   #090A0D;

  /* -- Chart series -- */
  --series-1:       #0098a3;
  --series-2:       #6578e6;
  --series-3:       #00a35a;
  --series-4:       #9e8500;
  --series-5:       #a85ee0;
  --series-6:       #e63a5a;
  --buy:            var(--series-3);
  --sell:           var(--series-6);
  --series-equity:  var(--series-1);
  --series-balance: var(--series-2);
  --zero-line:      #7a2233;

  /* -- Scorecard bands -- */
  --band-critical:          var(--critical);
  --band-weak:              #FF7A45;
  --band-needs_improvement: var(--warning);
  --band-good:              #A3D94A;
  --band-excellent:         var(--success);

  /* -- Semantic financial aliases (asserted by test/ui-architecture.js §2) -- */
  --helper-gap:     4px;
  --profit:         var(--success);
  --loss:           var(--danger);
  --neutral:        var(--text-muted);

  /* -- Typography -- */
  --font-ui-latin: "TC Inter", Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-ui-arabic-script: "TC Noto Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --font: var(--font-ui-latin), var(--font-ui-arabic-script);
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", monospace;
  /* Money is set in Inter with tabular lining figures so ckb-u-nu-latn and
     ar-u-nu-latn keep Western digits even when the UI face is Noto Arabic. */
  --font-numeric: "TC Inter", var(--font-ui-latin);

  --fs-display: 32px;
  --fs-title:   24px;
  --fs-section: 16px;
  --fs-card:    14px;
  --fs-body:    14px;
  --fs-small:   13px;
  --fs-caption: 12px;
  --fs-label:   12px;
  --fs-micro:   10px;

  --lh-tight:   1.2;
  --lh-body:    1.5;

  /* -- Spacing Scale -- */
  --sp-1: 4px;
  --sp-2: 4px;
  --sp-3: 8px;
  --sp-4: 12px;
  --sp-5: 16px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* -- Radius -- */
  --radius-xs: 4px;
  --radius-s:  4px;
  --radius:    6px;
  --radius-l:  8px;
  --radius-pill: 4px; /* Explicitly flattened */

  /* -- Shadows (flattened) -- */
  --shadow-1: none;
  --shadow-2: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-3: 0 8px 24px rgba(0,0,0,0.5);
  --ring: 0 0 0 2px var(--focus-ring);

  /* -- Controls -- */
  --control-h:    36px;
  --control-h-sm: 32px;
  --control-h-lg: 44px;
  --control-px:   12px;
  --control-radius: var(--radius);
  --control-border: 1px;
  --label-gap:    4px;
  --field-gap:    var(--sp-4);

  /* -- Shell layout -- */
  --sidebar-w:          240px;
  --sidebar-w-collapsed: 64px;
  --rail-w:             200px;
  --content-max:        100%;
  --topbar-h:           56px;
  
  --speed: 100ms;
  --speed-slow: 150ms;
  --ease: ease;
  --ease-out-expo: ease-out;
}

:root:lang(en), :root:lang(ku) {
  --font: var(--font-ui-latin), var(--font-ui-arabic-script);
}

:root:lang(ar), :root:lang(ckb) {
  --font: var(--font-ui-arabic-script), var(--font-ui-latin);
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html[dir="rtl"] body { font-size: 14.5px; line-height: 1.7; }

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.018em;
  text-wrap: balance;
}
html[dir="rtl"] :is(h1, h2, h3, h4) { letter-spacing: 0; }

h1 { font-size: var(--fs-display); font-weight: 700; }
h2 { font-size: var(--fs-title); }
h3 { font-size: var(--fs-section); }
h4 { font-size: var(--fs-card); }

p { margin: 0; }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--speed) var(--ease), text-shadow var(--speed) var(--ease);
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

hr {
  border: 0;
  border-block-start: 1px solid var(--border);
  margin: var(--sp-6) 0;
}

::selection { background: var(--primary-soft); color: var(--text-primary); }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num, .kpi-value, .stat-value, .hero-value, td.num {
  font-family: var(--font-numeric);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -0.005em;
}
/* Identifiers — MT5 logins, tokens, hashes — are the monospace case. */
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/**
 * Figures keep their written order on an RTL page.
 *
 * Without `direction: ltr`, the bidi algorithm resolves a leading minus or
 * currency sign to the opposite side of the run: "-$75,252.98" renders with
 * the sign stranded on the right, reading as a positive number followed by a
 * stray dash. The digits are already LTR by Unicode class; it is the sign and
 * the separators that move.
 *
 * `text-align: end` then aligns the figure inside that LTR context, so every
 * value in a column shares an edge and the decimal points line up.
 */
html[dir="rtl"] :is(.num, .kpi-value, .stat-value, .m-value, .mono) {
  direction: ltr;
  text-align: end;
}

/**
 * The block box `direction` needs is given ONLY to non-table elements.
 *
 * A table cell must never receive `display: inline-block`. It removes the cell
 * from the table's column model — the browser wraps the loose inline boxes in
 * an anonymous cell, and the header row and body rows stop sharing a column
 * grid, so headers drift away from the data beneath them.
 *
 * It also produced an asymmetric gap. Static header rows in index.html carry
 * whitespace between their <th> tags (five text nodes in the session table
 * alone); body rows built by el() in app.js carry none. As inline-blocks that
 * whitespace becomes visible word spacing in the header and nothing in the
 * body, so the header spread progressively wider than its own column.
 *
 * A table cell already establishes its own formatting context, so `direction`
 * and `text-align` above apply correctly with no display change at all.
 */
html[dir="rtl"] :is(.num, .kpi-value, .stat-value, .m-value, .mono):not(th):not(td) {
  display: inline-block;
}

.profit, .pos { color: var(--profit); }
.loss,   .neg { color: var(--loss); }
.muted  { color: var(--text-muted); }
.small  { font-size: var(--fs-small); }
.caption{ font-size: var(--fs-caption); color: var(--text-muted); }

.label{
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.label.vip, .eyebrow.vip {
  color: var(--text-primary);
  letter-spacing: 0.12em;
}
html[dir="rtl"] .label { letter-spacing: 0; text-transform: none; }

/* ============================================================ card ======= */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--sp-5);
  transition: border-color var(--speed) var(--ease);
  position: relative;
}
.card.dense { padding: var(--sp-4); }
.card + .card { margin-block-start: var(--sp-5); }
.card.interactive:hover { border-color: var(--border-strong); }

.card.vip { border-color: var(--accent); }
.card.vip:hover { border-color: var(--accent-hover); }

.card-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-block-end: var(--sp-5);
}
.card-head > h2, .card-head > h3 { font-size: var(--fs-section); }
.card-head > p {
  flex-basis: 100%;
  margin-block-start: var(--sp-1);
  font-size: var(--fs-small);
  color: var(--text-secondary);
}
.card-head .spacer { flex: 1 1 auto; }

.section-sub {
  margin-block: var(--sp-6) var(--sp-4);
  font-size: var(--fs-card);
  color: var(--text-secondary);
}

.policy-box {
  background: var(--surface-0);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-s);
  padding: var(--sp-5);
  font-size: var(--fs-small);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* =========================================================== button ====== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-5);
  height: var(--control-h);
  min-height: var(--control-h);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 550;
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--control-radius);
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: background var(--speed) var(--ease),
              border-color var(--speed) var(--ease),
              color var(--speed) var(--ease);
}
.btn:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn:active:not(:disabled) { background: var(--primary-press); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: saturate(0.6); }

.btn.ghost, .btn.secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn.ghost:hover:not(:disabled), .btn.secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-muted);
  box-shadow: none;
}

.btn.subtle {
  background: var(--surface-2);
  color: var(--text-secondary);
  border-color: transparent;
}
.btn.subtle:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--surface-3);
  box-shadow: none;
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.danger:hover:not(:disabled) { background: #d92d3f; border-color: #d92d3f; }

.btn.success {
  background: var(--success);
  border-color: var(--success);
  color: var(--text-inverse);
}
.btn.success:hover:not(:disabled) { background: #0e9f6e; border-color: #0e9f6e; }

.btn.small { height: var(--control-h-sm); min-height: var(--control-h-sm); padding: 0 12px; font-size: var(--fs-caption); }
.btn.large { height: var(--control-h-lg); min-height: var(--control-h-lg); padding: 0 24px; font-size: var(--fs-card); }
.btn.block { width: 100%; }

.btn.icon { padding: 0; width: var(--control-h); height: var(--control-h); min-height: var(--control-h); }
.btn.icon.small { width: var(--control-h-sm); height: var(--control-h-sm); min-height: var(--control-h-sm); }

.row-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  align-items: center;
  margin-block-start: var(--sp-5);
}

/* ============================================================ form ======= */

label.block, label.field, .settings-grid > label {
  display: flex;
  flex-direction: column;
  gap: var(--label-gap);
  font-size: var(--fs-small);
}
label.block > span:first-child,
label.field > span:first-child,
.settings-grid > label > span:first-child {
  color: var(--text-secondary);
  font-weight: 500;
}

input[type="text"], input[type="email"], input[type="password"], input[type="url"],
input[type="number"], input[type="tel"], input[type="search"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="month"], input:not([type]),
select, textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0 var(--control-px);
  height: var(--control-h);
  min-height: var(--control-h);
  font: inherit;
  font-size: var(--fs-small);
  line-height: calc(var(--control-h) - 2 * var(--control-border));
  color: var(--text-primary);
  background: var(--surface-0);
  border: var(--control-border) solid var(--border);
  border-radius: var(--control-radius);
  transition: border-color var(--speed) var(--ease),
              background var(--speed) var(--ease),
              box-shadow var(--speed) var(--ease);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 0.7; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: var(--border-strong);
}
/* Form controls take the SAME focus indicator as every other control: a 2px
   solid cobalt outline at 2px offset. They previously suppressed the outline
   and substituted a 50%-alpha ring, so a keyboard user met two different
   focus treatments depending on which control they landed on. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-color: var(--primary);
  background: var(--surface-1);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: var(--surface-1);
}
input:disabled, select:disabled, textarea:disabled {
  opacity: 0.45; cursor: not-allowed; background: var(--surface-0);
}
input[aria-invalid="true"], .field.invalid input {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger-border), inset 0 1px 2px rgba(0,0,0,0.2);
}
textarea {
  height: auto; min-height: 96px; padding-block: 11px;
  resize: vertical; line-height: var(--lh-body);
}

input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  background-position: right 14px center, right 9px center;
  padding-inline-end: 32px;
}
html[dir="rtl"] select {
  background-position: left 9px center, left 14px center;
  padding-inline-end: 14px;
  padding-inline-start: 32px;
}

.hint, .helper {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  line-height: 1.45;
}
.hint.warn  { color: var(--warning); }
.hint.error { color: var(--danger); }
.hint.ok    { color: var(--success); }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--field-gap);
  align-items: start;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-small);
  cursor: pointer;
}
.check input[type="checkbox"], .check input[type="radio"] {
  width: 16px; height: 16px; min-height: 0;
  flex: none; margin: 0; padding: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ============================================================ badge ====== */

.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: 0.03em;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  white-space: nowrap;
}
html[dir="rtl"] :is(.badge, .pill) { letter-spacing: 0; }

.badge::before {
  content: "";
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge.no-dot::before { display: none; }

.badge.success, .badge.ok      { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.badge.warning, .badge.pending { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.badge.danger,  .badge.failed  { color: var(--danger);  background: var(--danger-soft);  border-color: var(--danger-border); }
.badge.info                    { color: var(--info);    background: var(--info-soft);    border-color: var(--info-border); }
.badge.ai                      { color: var(--ai);      background: var(--ai-soft);      border-color: var(--ai-border); }
.badge.primary                 { color: var(--primary); background: var(--primary-soft); border-color: var(--primary-ring); }

/* =========================================================== avatar ====== */

.avatar {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: var(--fs-caption);
  font-weight: 600;
  text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Shared inline-icon geometry for JS-built UI (post actions, avatar
   placeholders). One stroke weight, one optical size, currentColor. */
.ui-icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.avatar .avatar-mark { width: 58%; height: 58%; color: var(--text-muted); }
/* An engaged action fills its mark rather than only recolouring it, so the
   state survives for a reader who cannot separate the two hues. */
.ui-icon.is-on, .is-on > .ui-icon { fill: currentColor; }
.post-action.is-on .ui-icon { fill: currentColor; }
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }
.avatar-lg { width: 60px; height: 60px; font-size: var(--fs-section); }
.avatar-xl { width: 92px; height: 92px; font-size: var(--fs-title); }

/* ============================================================ table ====== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: var(--shadow-1);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: start;
  padding: var(--sp-3) var(--sp-5);
  white-space: nowrap;
  border-block-end: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
html[dir="rtl"] thead th { letter-spacing: 0; text-transform: none; }
tbody td {
  /* 8px, not 12px: 12 pushed every row to ~50px against a 40px spec — a whole
     screen of air across a 25-row page of dense financial records. */
  padding: var(--sp-3) var(--sp-5);
  border-block-end: 1px solid var(--border-faint);
  color: var(--text-secondary);
  vertical-align: middle;
  transition: color var(--speed) var(--ease);
}
tbody tr:last-child td { border-block-end: 0; }
tbody tr { transition: background var(--speed) var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:hover td { color: var(--text-primary); }
tbody td strong, tbody td b { color: var(--text-primary); font-weight: 600; }

td.num, th.num { text-align: end; }

/* ============================================================= tabs ====== */

.tabs {
  display: flex;
  gap: var(--sp-1);
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  border-block-end: 1px solid var(--border);
  padding-inline: var(--sp-6);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 12px 16px;
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-block-end: 2px solid transparent;
  margin-block-end: -1px;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: color var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.tab:hover { color: var(--text-secondary); }
.tab[aria-selected="true"] {
  color: var(--text-primary);
  border-block-end-color: var(--primary);
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-block-end: -2px;
  inset-inline: 20%;
  height: 2px;
  background: var(--primary);
}

/* =========================================================== states ====== */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-0);
  border: 1px dashed var(--border);
  border-radius: var(--radius-l);
}
.state-icon { font-size: 28px; opacity: 0.6; line-height: 1; }
.state-text { font-size: var(--fs-small); max-width: 46ch; line-height: 1.55; }
.state .btn { margin-block-start: var(--sp-1); }
.state.error {
  border-color: var(--danger-border);
  border-style: solid;
  background: var(--danger-soft);
}
.state.error .state-title { color: var(--danger); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: tc-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius-s);
  min-height: 12px;
}
@keyframes tc-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2.5px solid var(--border-strong);
  border-block-start-color: var(--primary);
  border-radius: 50%;
  animation: tc-spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes tc-spin { to { transform: rotate(360deg); } }

/* ============================================================ modal ====== */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: var(--sp-6);
  background: rgba(3, 4, 6, 0.78);
  animation: tc-fade var(--speed) var(--ease);
}
@supports (backdrop-filter: blur(8px)) {
  .modal-backdrop { backdrop-filter: blur(12px) saturate(1.2); }
}
.modal {
  width: min(540px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-3);
  padding: var(--sp-8);
  animation: tc-rise var(--speed-slow) var(--ease-out-expo);
  position: relative;
}
.modal::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(170deg, rgba(255,255,255,0.05) 0%, transparent 50%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.modal-title { font-size: var(--fs-section); margin-block-end: var(--sp-2); font-weight: 600; }
.modal-body { font-size: var(--fs-small); color: var(--text-secondary); }
@keyframes tc-fade { from { opacity: 0; } }
@keyframes tc-rise { from { opacity: 0; transform: translateY(16px) scale(0.97); } }

/* ========================================================= dropdown ====== */

.dropdown { position: relative; }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }

/* ========================================================== tooltip ====== */

.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  inset-block-end: calc(100% + 8px);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 6px 11px;
  font-size: var(--fs-caption);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-2);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--speed) var(--ease), transform var(--speed) var(--ease);
}
html[dir="rtl"] .tip::after { transform: translateX(50%); }
.tip:hover::after, .tip:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}
html[dir="rtl"] .tip:hover::after, html[dir="rtl"] .tip:focus-visible::after {
  transform: translateX(50%) translateY(-2px);
}

/* ============================================================ toast ====== */
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  max-width: 400px;
  padding: 13px 17px;
  font-size: var(--fs-small);
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-inline-start: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: tc-slide-in var(--speed-slow) var(--ease-out-expo);
}
@keyframes tc-slide-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* ============================================================== KPI ====== */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
}
/* `.kpi` and `.kpi-card` are the same primitive under two names: app.js emits
   both. Keeping them identical prevents the unstyled-tile regression that
   shipped when only one of the two was defined. */
.kpi, .kpi-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  min-width: 0;
  transition: border-color var(--speed) var(--ease);
}
.kpi:hover, .kpi-card:hover { border-color: var(--border-strong); }
.kpi-label {
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}
html[dir="rtl"] .kpi-label { letter-spacing: 0; text-transform: none; }
.kpi-value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text-primary);
  letter-spacing: -0.015em;
}
.kpi-value.up   { color: var(--profit); }
.kpi-value.down { color: var(--loss); }
.kpi-sub, .kpi-caption { font-size: var(--fs-caption); color: var(--text-muted); }
.kpi-delta { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-caption); font-weight: 600; }
.kpi-delta.up   { color: var(--profit); }
.kpi-delta.down { color: var(--loss); }

.kpi.flagged  { border-inline-start: 2px solid var(--warning); }
.kpi.critical { border-inline-start: 2px solid var(--danger); }

/* The one metric a surface leads with. Wider, quieter chrome, larger figure —
   hierarchy by size and span rather than by a second colour. */
.kpi.kpi-primary, .kpi-card.kpi-primary {
  grid-column: span 2;
  background: var(--surface-0);
  border-color: var(--border-strong);
}
.kpi-primary .kpi-value { font-size: 30px; }
@media (max-width: 720px) {
  .kpi.kpi-primary, .kpi-card.kpi-primary { grid-column: span 1; }
  .kpi-primary .kpi-value { font-size: 24px; }
}

/* ========================================================= progress ====== */
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger  { background: var(--danger); }

/* =========================================================== motion ====== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ======================================================== scrollbar ====== */

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid var(--plane);
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ======================================================= responsive ====== */

@media (max-width: 720px) {
  :root { --fs-display: 24px; --fs-title: 18px; --sp-6: 16px; --sp-5: 16px; }
  .card { padding: var(--sp-4); }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .kpi-value { font-size: 22px; }
  .tabs { padding-inline: var(--sp-3); }
  .toast { max-width: none; }
}

/* ==========================================================================
   NAVIGATION — LEVEL 1 SIDEBAR
   ========================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns var(--speed-slow) var(--ease);
}
.app-shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  position: sticky;
  inset-block-start: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4);
  background: var(--bg-base);
  border-inline-end: 1px solid var(--border-default);
  overflow: hidden;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding-inline: 6px; padding-block-end: var(--sp-4);
  margin-block-end: var(--sp-2);
  border-block-end: 1px solid var(--border-faint);
  min-height: 44px;
}
.sidebar-brand .brand-mark { flex: none; }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-text strong { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.sidebar-brand-text span {
  font-size: 9px; color: var(--text-muted); font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; white-space: nowrap;
}
html[dir="rtl"] .sidebar-brand-text span { letter-spacing: 0; text-transform: none; }

.sidebar-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 2px;
  margin-inline: calc(-1 * var(--sp-1));
  padding-inline: var(--sp-1);
}

.sidebar-group {
  padding: var(--sp-5) var(--sp-3) var(--sp-1);
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-muted);
  white-space: nowrap;
}
html[dir="rtl"] .sidebar-group { letter-spacing: 0; text-transform: none; }
.sidebar-group:first-child { padding-block-start: var(--sp-1); }

.sidebar .tab {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  padding: var(--sp-3);
  min-height: 36px;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 0;
  border-block-end: 0;
  border-radius: var(--radius-s);
  margin-block-end: 0;
  text-align: start;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.sidebar .tab:hover { background: var(--surface-2); color: var(--text-primary); }
.sidebar .tab[aria-selected="true"] {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  border-block-end: 0;
}
.sidebar .tab[aria-selected="true"]::before {
  content: "";
  position: absolute;
  inset-inline-start: 0; inset-block: 7px;
  width: 3px; border-radius: 0 2px 2px 0;
  background: var(--accent);
}
html[dir="rtl"] .sidebar .tab[aria-selected="true"]::before { border-radius: 2px 0 0 2px; }

/* The sprite itself never renders; only its <symbol>s, via <use>. */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sidebar-icon {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
}
.sidebar-icon svg {
  width: 18px; height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* One optical weight at every size: strokes do not thicken when the icon is
     scaled by a parent, and stay hairline-crisp on the collapsed rail. */
  vector-effect: non-scaling-stroke;
}
/* Icons are structure, not accent: they take the label's colour and inherit
   the active state from it rather than carrying a second highlight. */
.sidebar .tab .sidebar-icon { color: var(--text-muted); }
.sidebar .tab:hover .sidebar-icon { color: var(--text-secondary); }
.sidebar .tab[aria-selected="true"] .sidebar-icon { color: var(--accent); }
.sidebar-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* The collapse chevron points the way the rail will move: inward when the rail
   is open, outward when it is collapsed — mirrored on an RTL page. */
#sidebarToggleIcon svg { transition: transform var(--speed) var(--ease); }
.app-shell.is-collapsed #sidebarToggleIcon svg { transform: scaleX(-1); }
html[dir="rtl"] #sidebarToggleIcon svg { transform: scaleX(-1); }
html[dir="rtl"] .app-shell.is-collapsed #sidebarToggleIcon svg { transform: none; }

/* Topbar and rail both carried a brand lockup, with different taglines, both
   visible at once on desktop. The rail owns the identity wherever it is
   permanent; the topbar lockup is the drawer-width fallback. */
@media (min-width: 901px) { .topbar .brand { display: none; } }
.chrome-icon {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
  display: block;
}
.brand-mark svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar .tab .count {
  flex: none;
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding-inline: 6px;
  font-size: 10px; font-weight: 700;
  background: var(--surface-3); color: var(--text-secondary);
  border-radius: var(--radius-pill);
}

.app-shell.is-collapsed .sidebar-label,
.app-shell.is-collapsed .sidebar-brand-text,
.app-shell.is-collapsed .sidebar-group,
.app-shell.is-collapsed .sidebar-user-id,
.app-shell.is-collapsed .tab .count { display: none; }
.app-shell.is-collapsed .sidebar { padding-inline: 12px; }
.app-shell.is-collapsed .sidebar .tab { justify-content: center; padding-inline: 0; }
.app-shell.is-collapsed .sidebar .tab::after {
  content: attr(data-label);
  position: absolute;
  inset-inline-start: calc(100% + 10px);
  z-index: 80;
  padding: 6px 11px;
  font-size: var(--fs-caption); font-weight: 500;
  color: var(--text-primary); background: var(--surface-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-s);
  box-shadow: var(--shadow-2);
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity var(--speed) var(--ease);
}
.app-shell.is-collapsed .sidebar .tab:hover::after,
.app-shell.is-collapsed .sidebar .tab:focus-visible::after { opacity: 1; }

.sidebar-foot {
  border-block-start: 1px solid var(--border-faint);
  padding-block-start: var(--sp-3);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-user {
  display: flex; align-items: center; gap: var(--sp-2);
  width: 100%; padding: 8px 9px;
  background: none; border: 0; border-radius: var(--radius-s);
  cursor: pointer; text-align: start;
  transition: background var(--speed) var(--ease);
}
.sidebar-user:hover { background: var(--surface-2); }
.sidebar-user-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar-user-id strong {
  font-size: var(--fs-caption); font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user-id span {
  font-size: 10px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-shell.is-collapsed .sidebar-user { justify-content: center; padding-inline: 0; }

.sidebar-toggle {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 8px;
  font-size: var(--fs-caption); color: var(--text-muted);
  background: none; border: 0; border-radius: var(--radius-s); cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text-primary); }

.sidebar-scrim {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(9, 10, 13, 0.8);
  animation: tc-fade var(--speed) var(--ease);
}

/* ==========================================================================
   NAVIGATION — LEVEL 2 SECTION RAIL
   ========================================================================== */

.section-layout {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: start;
}
.section-rail {
  position: sticky;
  inset-block-start: calc(var(--topbar-h) + var(--sp-4));
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.section-rail-title {
  padding: 2px 10px var(--sp-2);
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-muted);
}
html[dir="rtl"] .section-rail-title { letter-spacing: 0; text-transform: none; }
.section-rail a {
  display: block;
  padding: 8px 11px;
  font-size: var(--fs-small);
  color: var(--text-secondary);
  border-radius: var(--radius-s);
  text-decoration: none;
  border-inline-start: 2px solid transparent;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
}
.section-rail a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.section-rail a[aria-current="true"] {
  color: var(--primary);
  background: var(--primary-soft);
  border-inline-start-color: var(--primary);
  font-weight: 600;
}
.section-anchor { scroll-margin-block-start: calc(var(--topbar-h) + var(--sp-5)); }

/* ==========================================================================
   DONUT + RANKED BARS
   ========================================================================== */

.donut {
  display: flex; align-items: center; gap: var(--sp-6); flex-wrap: wrap;
}
.donut-ring { position: relative; flex: none; width: 150px; height: 150px; }
.donut-svg { width: 150px; height: 150px; display: block; }
.donut-svg circle { transition: stroke-dasharray var(--speed-slow) var(--ease); }
.donut-centre {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; pointer-events: none; text-align: center;
}
.donut-total { font-size: 23px; font-weight: 650; color: var(--text-primary); line-height: 1.1; }
.donut-total-label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.10em;
  text-transform: uppercase; color: var(--text-muted);
}
html[dir="rtl"] .donut-total-label { letter-spacing: 0; text-transform: none; }

.donut-legend {
  flex: 1; min-width: 180px;
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.donut-legend li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center; gap: var(--sp-2);
  font-size: var(--fs-caption);
}
.donut-legend i { width: 9px; height: 9px; border-radius: 2px; }
.donut-label { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-pct { color: var(--text-primary); font-weight: 600; text-align: end; }
.donut-val { color: var(--text-muted); text-align: end; min-width: 50px; }

.mini-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-3);
}

/* ========================================================= responsive ==== */

@media (max-width: 1180px) {
  .section-layout { grid-template-columns: minmax(0, 1fr); }
  .section-rail {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    gap: var(--sp-1);
  }
  .section-rail::-webkit-scrollbar { display: none; }
  .section-rail-title { display: none; }
  .section-rail a {
    white-space: nowrap;
    border-inline-start: 0;
    border-block-end: 2px solid transparent;
  }
  .section-rail a[aria-current="true"] { border-inline-start: 0; border-block-end-color: var(--primary); }
}

@media (max-width: 900px) {
  .app-shell, .app-shell.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 50;
    width: min(84vw, var(--sidebar-w));
    transform: translateX(-102%);
    transition: transform var(--speed) var(--ease);
    box-shadow: var(--shadow-3);
  }
  html[dir="rtl"] .sidebar { transform: translateX(102%); }
  .app-shell.drawer-open .sidebar { transform: none; }
  .sidebar-toggle { display: none; }
  .app-shell.is-collapsed .sidebar-label,
  .app-shell.is-collapsed .sidebar-brand-text,
  .app-shell.is-collapsed .sidebar-group,
  .app-shell.is-collapsed .sidebar-user-id,
  .app-shell.is-collapsed .tab .count { display: revert; }
  .app-shell.is-collapsed .sidebar .tab { justify-content: flex-start; padding-inline: 10px; }
  .app-shell.is-collapsed .sidebar .tab::after { content: none; }
}

@media (min-width: 901px) {
  .drawer-btn { display: none; }
  .sidebar-scrim { display: none; }
}

@media (max-width: 620px) {
  .donut { justify-content: center; }
  .donut-legend { min-width: 100%; }
}
/* =========================================================================
   PLATFORM UPGRADE COMPONENTS
   Performance, Positions, Trade History, Alerts, MT5 management and the
   administrative centres.

   Everything here is built from the tokens already declared at the top of
   this file — no new colour is introduced. The three status modifiers that
   ARE new (.pill.neutral / .buy / .sell) exist because the stylesheet had
   ok / warn / bad / info and nothing for "no verdict" or trade direction.
   ========================================================================= */

/* -- Status pills: the three modifiers the palette was missing ------------ */
.pill.neutral { color: var(--text-secondary); background: var(--surface-3); border-color: var(--border-strong); }
/* Direction is not a verdict. Buy and sell are deliberately NOT green and
   red: a sell is not a loss, and colouring it like one misreads the table at
   a glance. They take the two neutral chart hues instead. */
.pill.buy  { color: var(--series-2); background: rgba(101, 120, 230, 0.12); border-color: rgba(101, 120, 230, 0.30); }
.pill.sell { color: var(--series-1); background: rgba(0, 152, 163, 0.12);  border-color: rgba(0, 152, 163, 0.32); }

/* -- Loading skeletons ---------------------------------------------------- */
.skeleton-block { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
.skeleton-row {
  height: 42px;
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-sweep 1.4s ease-in-out infinite;
}
@keyframes skeleton-sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }
/* A sweeping placeholder is motion for its own sake once motion is
   unwelcome; the shape still communicates "loading". */
@media (prefers-reduced-motion: reduce) {
  .skeleton-row { animation: none; background: var(--surface-2); }
}

/* ============================================================ surfaces ===
   Every surface used the same rectangle, so nothing carried rank. These roles
   give a surface a job; a page uses two or three, never all.
     .surface-hero  .kpi-primary  .kpi  .metric-row  .chart-panel
     .insight  .empty-state  .data-table
   ======================================================================== */

/* Twelve identical boxes is a wall, not a hierarchy. A supporting metric
   belongs in an aligned label/value row: scannable, shared right edge, a
   fraction of the height. Used wherever a screen has >6 secondary figures. */
.metric-row {
  display: flex; align-items: baseline; gap: var(--sp-3);
  padding: 7px 0; border-block-end: 1px solid var(--border-subtle);
}
.metric-row:last-child { border-block-end: 0; }
.m-label { flex: 1 1 auto; min-width: 0; font-size: var(--fs-small); color: var(--text-secondary); }
.m-value {
  flex: none; font-size: var(--fs-small); font-weight: 600; color: var(--text-primary);
  font-variant-numeric: tabular-nums lining-nums;
}
.m-value.up { color: var(--profit); }
.m-value.down { color: var(--loss); }
/* Two columns once there is room, so a long list stops running down an
   otherwise empty panel. */
.metric-list.split { display: grid; gap: 0 var(--sp-6); }
@media (min-width: 900px) { .metric-list.split { grid-template-columns: 1fr 1fr; } }

/* A claim WITH the numbers behind it — not a paragraph in a box. */
.insight { display: flex; gap: var(--sp-3); padding-block: var(--sp-3); }
.insight + .insight { border-block-start: 1px solid var(--border-subtle); }
.insight-mark { flex: none; width: 3px; border-radius: 2px; background: var(--border-strong); }
.insight.up .insight-mark { background: var(--profit); }
.insight.down .insight-mark { background: var(--loss); }
.insight-body { min-width: 0; }
.insight-claim { font-size: var(--fs-small); color: var(--text-primary); }
.insight-evidence {
  font-size: var(--fs-caption); color: var(--text-muted);
  font-variant-numeric: tabular-nums lining-nums;
}

/* An empty state is a real state. Icon, title, one line, at most one action.
   No box around the mark: an icon in a tinted square is decoration. */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-6); text-align: center;
}
.empty-state-icon {
  width: 28px; height: 28px; color: var(--text-disabled);
  fill: none; stroke: currentColor; stroke-width: 1.25;
  stroke-linecap: round; stroke-linejoin: round;
}
.empty-state h2 { margin: 0; font-size: var(--fs-body); font-weight: 600; color: var(--text-primary); }
.empty-state p { margin: 0; max-width: 44ch; font-size: var(--fs-small); }
.empty-state button { margin-top: 6px; }

/* -- Stat tiles ----------------------------------------------------------- */
.stat-grid {
  display: grid; gap: 12px; margin: 14px 0;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.stat-grid-tight { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 10px 0; }
.stat-tile {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-label {
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.stat-tile .stat-value { font-size: 20px; color: var(--text-primary); }
.stat-tile .stat-value.small { font-size: 13px; }
/* Direction is carried by the sign in the figure itself; colour only
   reinforces it. */
.stat-value.up   { color: var(--profit); }
.stat-value.down { color: var(--loss); }

/* -- Data tables ---------------------------------------------------------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 12px;
  text-align: start;
  font-size: var(--fs-caption);
  font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--surface-1);
  border-block-end: 1px solid var(--border-strong);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: end; }
.data-table td {
  padding: 11px 12px;
  border-block-end: 1px solid var(--border-faint);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-block-end: 0; }
/* Flagged audit rows carry a rail as well as a tint, so the distinction is
   not colour alone. */
.data-table tr.row-flagged { background: var(--danger-soft); }
.data-table tr.row-flagged td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
html[dir="rtl"] .data-table tr.row-flagged td:first-child { box-shadow: inset -3px 0 0 var(--danger); }

/* -- Table toolbars and paging -------------------------------------------- */
.table-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 12px 0;
}
.table-tools input[type="search"] { flex: 1 1 220px; min-width: 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }
.pager button[disabled] { opacity: 0.45; cursor: not-allowed; }

/* -- Charts --------------------------------------------------------------- */
.spark { width: 100%; height: 180px; display: block; }
.spark-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-area { stroke: none; }
.spark-up   .spark-line { stroke: var(--series-3); }
.spark-up   .spark-area { fill: rgba(0, 163, 90, 0.10); }
.spark-down .spark-line { stroke: var(--series-1); }
.spark-down .spark-area { fill: rgba(0, 152, 163, 0.10); }
.chart-grid { stroke: var(--border-subtle); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* -- Chart frame: a plot plus the scales that make it readable ------------ */
.chart-frame-inner { display: flex; gap: var(--sp-3); align-items: stretch; }
.chart-plot { flex: 1 1 auto; min-width: 0; }
/* Value ticks: top, middle and bottom of the plot band, in reading order. */
.chart-y {
  display: flex; flex-direction: column; justify-content: space-between;
  flex: none; text-align: end;
  padding-block: 2px;
}
.chart-x {
  display: flex; justify-content: space-between;
  margin-block-start: var(--sp-2);
  /* The time axis belongs to the plot, which is pinned LTR. */
  direction: ltr;
}
.chart-x .chart-tick:only-child { margin-inline: auto; }
.chart-tick {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  line-height: 1.2;
  white-space: nowrap;
}
.chart-caption { margin-block-start: var(--sp-2); font-size: var(--fs-caption); color: var(--text-muted); }
@media (max-width: 720px) {
  .chart-y .chart-tick { font-size: 10px; }
}

.bar-row {
  display: flex; align-items: stretch; gap: 2px;
  height: 120px;
  position: relative;
  /* Plot geometry is locale-independent: a chart must not mirror under RTL
     or the time axis would run backwards. */
  direction: ltr;
}
/* The zero line is drawn once, across the whole series, at the height the
   data puts it — not assumed to be the floor of the box. */
.bar-row::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: var(--zero-at, 100%);
  height: 1px;
  background: var(--border-strong);
}
.bar-col { flex: 1 1 0; min-width: 2px; position: relative; }
.bar { position: absolute; inset-inline: 0; }
.bar-up   { background: var(--profit); border-radius: 2px 2px 0 0; }
.bar-down { background: var(--loss);   border-radius: 0 0 2px 2px; }

/* -- Alerts --------------------------------------------------------------- */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--border-strong);
  border-radius: var(--radius);
}
.alert-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert-rule { font-size: 13px; color: var(--text-primary); }
.alert-body { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.alert-action { font-size: 13px; color: var(--text-secondary); }
.alert-item p { margin: 6px 0 0; }

.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* -- MT5 account cards ---------------------------------------------------- */
.mt5-card {
  padding: 16px 18px;
  margin-bottom: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
}
.mt5-card-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.mt5-label { margin: 0; font-size: 16px; color: var(--text-primary); }
.mt5-card-head p { margin: 2px 0 0; }
.mt5-card .row-actions { margin-top: 12px; }

/* -- Settings forms ------------------------------------------------------- */
.settings-form .grid { gap: 16px; }
.field-toggle { justify-content: center; }
.settings-form .actions { margin-top: 18px; align-items: center; gap: 12px; }
.settings-form .danger { color: var(--danger); }

/* -- Sidebar count badges ------------------------------------------------- */
.count-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }

/* -- Responsive ----------------------------------------------------------- */
@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 8px; }
  .stat-tile { padding: 11px 12px; }
  .stat-tile .stat-value { font-size: 17px; }
  .table-tools { gap: 8px; }
  .table-tools input[type="search"] { flex-basis: 100%; }
  .table-tools select { flex: 1 1 auto; }
  .empty-state { padding: 32px 16px; }
  .bar-row { height: 92px; }
  .spark { height: 140px; }
  /* Trading tables keep their columns and scroll inside the card, rather
     than reflowing into an unreadable stack of wrapped numbers. */
  .data-table { min-width: 620px; }
  .btn-sm,
  .btn-primary,
  .actions > button,
  .btn-row > button,
  .link-button {
    min-height: var(--control-h-lg);
  }
  .data-table tbody td {
    min-block-size: var(--control-h-lg);
  }
}

/* =========================================================================
   COMMUNITY — the two-column reading surface

   Built from the tokens declared at the top of this file; no new colour is
   introduced. Everything below uses logical properties, so the whole surface
   mirrors under dir="rtl" without a single physical override.
   ========================================================================= */

.community-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--sp-4);
  align-items: start;
}
.community-main { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.community-rail { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }

/* The rail follows the reader down the feed, which is long. `top` clears the
   sticky topbar so a card never hides under it. */
@media (min-width: 1101px) {
  .community-rail { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); }
}

.rail-card { padding: var(--sp-4); }
.rail-card .card-head { margin-block-end: var(--sp-3); }
.rail-card .card-head h2 { font-size: var(--fs-card); }

/* -- Feed filters --------------------------------------------------------- */

.feed-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  margin-block-end: var(--sp-4);
}
.chip-row { display: contents; }
.chip-sep {
  inline-size: 1px; block-size: 20px;
  background: var(--border-strong);
  margin-inline: var(--sp-1);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: color var(--speed) var(--ease), background var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
}
.chip:hover { color: var(--text-primary); border-color: var(--border-strong); }
/* The selected chip is not signalled by colour alone: it also gains a border
   and a weight change, so the state survives a monochrome or CVD reading. */
.chip.is-on {
  color: var(--text-primary);
  font-weight: 600;
  background: var(--primary-soft);
  border-color: var(--primary-ring);
}
.chip-count {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: var(--fs-micro); color: var(--text-muted);
}
.chip-symbol { font-family: var(--mono); letter-spacing: 0.02em; }

/* -- The symbol tag on a post --------------------------------------------- */

.symbol-chip {
  margin-inline-start: auto;
  padding: 3px 10px;
  font-family: var(--mono);
  font-size: var(--fs-caption);
  font-variant-numeric: tabular-nums;
  color: var(--info);
  background: var(--info-soft);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  /* A ticker reads left-to-right in every locale. */
  direction: ltr;
}
.symbol-chip:hover { color: var(--text-primary); border-color: var(--info); }

/* -- Post actions --------------------------------------------------------- */

.post-action-strategy { text-decoration: none; }
.post-action-save.is-on { color: var(--vip); }

/* Highlight a post jumped to from the rail, so the reader can see where they
   landed. Fades on its own; no layout shift. */
.post-flash { animation: post-flash 1.2s var(--ease); }
@keyframes post-flash {
  from { box-shadow: 0 0 0 2px var(--primary-ring); }
  to   { box-shadow: 0 0 0 2px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .post-flash { animation: none; outline: 2px solid var(--primary-ring); }
}

/* -- Composer extras ------------------------------------------------------ */

.composer-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-block-start: var(--sp-2); }
.composer-meta input { flex: 1 1 200px; min-inline-size: 0; }
.composer-meta #cmPostSymbol { flex: 0 1 160px; font-family: var(--mono); }

/* -- Reels ---------------------------------------------------------------- */

.reel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.reel {
  position: relative;
  aspect-ratio: 9 / 16;
  padding: 0;
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  cursor: pointer;
}
.reel video { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; }
.reel-play {
  position: absolute; inset-block-start: 50%; inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  inline-size: 26px; block-size: 26px;
  display: grid; place-items: center;
  font-size: 11px; color: var(--text-primary);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 50%;
  pointer-events: none;
}
html[dir="rtl"] .reel-play { transform: translate(50%, -50%); }
.reel-author {
  position: absolute; inset-block-end: 0; inset-inline: 0;
  padding: 10px 6px 4px;
  font-size: var(--fs-micro);
  color: var(--text-primary);
  text-align: start;
  background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}

/* -- Rail lists (messages, suggestions) ----------------------------------- */

.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-row {
  inline-size: 100%;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px 10px;
  text-align: start;
  background: none;
  border: 0;
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background var(--speed) var(--ease);
}
.rail-row:hover { background: var(--surface-2); }
.rail-row-static { cursor: default; }
.rail-row-static:hover { background: none; }
.rail-row-text {
  display: flex; flex-direction: column; gap: 2px;
  min-inline-size: 0; flex: 1 1 auto;
}
.rail-row-text strong { font-size: var(--fs-small); color: var(--text-primary); }
/* A message preview is one line: the rail is context, not a reading surface. */
.rail-row-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-name {
  padding: 0; background: none; border: 0;
  font-size: var(--fs-small); font-weight: 600; color: var(--text-primary);
  text-align: start; cursor: pointer;
}
.rail-name:hover { color: var(--primary-hover); }
.btn-follow { flex: 0 0 auto; }

/* -- Responsive ----------------------------------------------------------- */

@media (max-width: 1100px) {
  /* The rail moves BELOW the feed rather than disappearing: on a narrow
     screen the messages and suggestions are still what a reader wants after
     the posts, and hiding them would remove function rather than adapt it. */
  .community-layout { grid-template-columns: minmax(0, 1fr); }
  .community-rail { flex-direction: row; flex-wrap: wrap; }
  .community-rail > .rail-card { flex: 1 1 280px; }
}
@media (max-width: 640px) {
  .community-rail { flex-direction: column; }
  .reel-grid { grid-template-columns: repeat(3, 1fr); }
  .feed-filters { gap: 6px; }
  .composer-meta input { flex-basis: 100%; }
}

/* =========================================================================
   TOURNAMENT
   =========================================================================
   Only what the tournament screens genuinely add. Cards, pills, stat tiles,
   subtabs, fields, checks and tables are the platform's existing components
   and are reused as they are — a second card style that drifts out of step
   with the first is a cost with no benefit.
   ========================================================================= */

/* -- The fifth pill tone --------------------------------------------------
   The grade scale needs FIVE distinguishable steps and the palette has four
   verdict colours. This is the orange between warning-yellow and danger-red,
   so مام ناوەند cannot be mistaken for باش at a glance. It is derived from the
   two existing tokens rather than being a new brand colour. */
.pill.mid {
  color: #f0a04a;
  background: rgba(240, 160, 74, 0.10);
  border-color: rgba(240, 160, 74, 0.28);
}

/* -- Countdown ------------------------------------------------------------
   Four cells, each a number over its unit. The digits are tabular so the
   seconds cell does not shuffle the row's width once a second — a countdown
   that jitters reads as broken. */
.countdown-host { min-height: 74px; }
.countdown {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  margin-block: var(--sp-2);
}
.countdown-cell {
  flex: 1 1 84px; min-width: 84px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--sp-3) var(--sp-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.countdown-value {
  font-size: 26px; font-weight: 700; line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.countdown-label {
  font-size: var(--fs-label); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted);
}

/* -- The reader's own row -------------------------------------------------
   A left border and a tinted background, never colour alone: the row also
   carries the word "you" as a pill, so the highlight is a convenience rather
   than the only way to find yourself. */
.data-table tr.row-you > td {
  background: var(--primary-soft);
}
/* border-inline-start, not an inset shadow on the left: in RTL the first cell
   is on the right, and a physically-anchored bar would draw down its inner
   edge instead of the row's start. */
.data-table tr.row-you > td:first-child {
  border-inline-start: 3px solid var(--primary);
}

.data-table tr.is-stale > td {
  background: var(--warning-soft);
}
.data-table tr.is-stale > td:first-child {
  border-inline-start: 3px solid var(--warning);
}

.tn-rank-table tbody td.num {
  font-variant-numeric: tabular-nums lining-nums;
  font-family: var(--font-numeric);
}

/* -- Small structural pieces --------------------------------------------- */
.card.sub {
  margin-block-start: var(--sp-4);
  background: var(--surface-2);
  box-shadow: none;
}
.card-actions {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  margin-block-start: var(--sp-4);
}
.section-title {
  font-size: var(--fs-small); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-block: var(--sp-4) var(--sp-2);
}
.form-block { margin-block-start: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
/* Numeric configuration inputs sit inside table cells, so they are sized to
   their content rather than stretching the column. */
.num-input { width: 100%; max-width: 130px; text-align: end; font-variant-numeric: tabular-nums; }
/* Rules text is authored with line breaks that carry meaning. */
.pre-wrap { white-space: pre-wrap; }
.rules > summary { cursor: pointer; color: var(--text-secondary); font-size: var(--fs-small); }
.rules[open] > summary { margin-block-end: var(--sp-2); }

@media (max-width: 640px) {
  .countdown-cell { flex-basis: calc(50% - var(--sp-2)); }
  .countdown-value { font-size: 22px; }
}

/* -- Labelled configuration fields ----------------------------------------
   Every tournament admin input carries a VISIBLE label bound to it by for/id.
   A box holding `15` that the reader has to decode from its column position is
   a box they will eventually get wrong, so the label travels with the input
   rather than living in a header far above it.

   Logical properties throughout: the tournament UI runs right-to-left in
   Sorani and Arabic, and a label pinned to the physical left would end up on
   the wrong side of its own input. */
.labeled-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.labeled-field-label {
  font-size: var(--fs-label);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.labeled-field .num-input { max-width: 140px; }
.labeled-field-suffix {
  font-size: var(--fs-caption);
  color: var(--text-muted);
}
/* Inside a table cell the label sits directly above its own input, so a row of
   thresholds and points reads as pairs rather than as a grid of bare numbers. */
.data-table .labeled-field { gap: 2px; }
.data-table .labeled-field-label { font-size: 10px; }

/* The category header carries its maximum as an editable field, so it needs to
   sit on the baseline with the heading rather than stretching the row. */
.card-head .labeled-field { flex: 0 0 auto; align-items: flex-start; }

@media (max-width: 640px) {
  .labeled-field .num-input { max-width: 100%; }
}

/* ==========================================================================
   TOURNAMENT — control bar, paused banner, profile links
   ==========================================================================

   Logical properties only, like everything above, so the Arabic and Sorani
   layouts mirror without a single RTL override.
   ========================================================================== */

/* A destructive button has to LOOK destructive, not merely be labelled one.
   `.btn.danger` above styles the full-size variant; this is the small one the
   tables and the control bar use. */
.btn-danger,
.btn-sm.btn-danger {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-soft);
}
.btn-danger:hover:not(:disabled),
.btn-sm.btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
}

/* Paused is a state the reader has to notice before they read any number on
   the screen, so it is a band across the card rather than a quiet pill. */
.tn-paused-banner {
  margin-block: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--warning-border, var(--danger-border));
  border-inline-start-width: 3px;
  border-radius: var(--radius-2, 8px);
  background: var(--warning-soft, var(--danger-soft));
  color: var(--text-primary);
  font-size: var(--fs-small);
}

/* The delete block is separated from Pause by a rule and a tinted well, so the
   two can never read as neighbouring options of the same kind. */
.tn-danger-zone {
  margin-block-start: var(--sp-5);
  padding: var(--sp-4);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-2, 8px);
  background: var(--danger-soft);
}
.tn-danger-title { color: var(--danger); }

/* A participant's name in the ranking opens their public profile. It is a
   BUTTON because it performs an action rather than navigating, and it is drawn
   as a link because that is what a reader expects to be able to click. */
.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  text-align: start;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  min-block-size: var(--control-h-lg);
}
.link-button:hover { color: var(--text-primary); }
.link-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* The Mode-3 explanation: a formula line and its four ordered steps. Logical
   properties only, so the Arabic and Sorani layouts mirror without an override. */
.formula {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--fs-small);
  letter-spacing: 0.02em;
}
.steps {
  margin-block: var(--sp-2);
  padding-inline-start: var(--sp-5);
  font-size: var(--fs-small);
}
.steps > li { margin-block-end: var(--sp-1); }

/* ==================================================== section visibility ===
   PARTICIPANT SECTION SWITCHES (System Settings).

   A real switch, built from a native checkbox so it stays keyboard-reachable
   and announces itself to assistive technology without any ARIA of its own.
   The visible state is ALSO spelled out in words beside it — colour alone is
   not a state a colour-blind administrator can read.

   Logical properties throughout (inline-start / inline-end), so the track and
   its knob mirror correctly in Sorani and Arabic without a second rule.
   ========================================================================= */

.vis-group { margin-block-start: var(--sp-4); }
.vis-group .section-sub { margin-block-end: var(--sp-2); }

.vis-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.vis-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-1);
  border-block-end: 1px solid var(--border);
}
.vis-row:last-child { border-block-end: 0; }
.vis-row:hover { background: var(--surface-2); }

.vis-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-small);
  color: var(--text-primary);
  cursor: pointer;
}

/* The switch itself: the checkbox is visually replaced but never removed from
   the accessibility tree or the tab order. */
.switch {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.switch input[type="checkbox"] {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  width: 100%; height: 100%;
  min-height: 0;
  margin: 0; padding: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-track {
  display: block;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background 140ms ease, border-color 140ms ease;
}
.switch-track::after {
  content: "";
  display: block;
  width: 16px; height: 16px;
  margin: 2px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 140ms ease, background 140ms ease;
}
.switch input:checked + .switch-track {
  background: var(--success-soft);
  border-color: var(--success-border);
}
.switch input:checked + .switch-track::after {
  background: var(--success);
  /* Logical: moves toward the inline end, so it mirrors in RTL. */
  transform: translateX(16px);
}
[dir="rtl"] .switch input:checked + .switch-track::after {
  transform: translateX(-16px);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--vip);
  outline-offset: 2px;
}

/* ========================================================= audit sections ===
   VISIBLE CATEGORY CHIPS, deliberately not a <select>.

   A reviewer must be able to see the shape of the history without opening a
   control: how many routine events, how many security findings. Each chip
   carries its own count, and the security chip picks up an alert border when
   it is non-empty — with the count still spelled out in digits, so the signal
   is never colour alone.
   ========================================================================= */

.audit-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-block-end: var(--sp-3);
}

.audit-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: var(--fs-small);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.audit-chip:hover { background: var(--surface-2); color: var(--text-primary); }
.audit-chip:focus-visible { outline: 2px solid var(--vip); outline-offset: 2px; }

.audit-chip.is-active {
  background: var(--accent-subtle);
  border-color: var(--focus-ring);
  color: var(--text-primary);
}

.audit-chip.is-alert { border-color: var(--danger-border); }
.audit-chip.is-alert .audit-chip-count { color: var(--danger); }

.audit-chip-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
}

/* ================================================= community spaces ======
   REELS, MESSAGES, PAGES AND ACCOUNT ANALYSIS.

   Four destinations that had no styles because they had no existence. Built
   from the same tokens as the rest of the platform — no new palette, no new
   type scale — and responsive by grid rather than by breakpoint gymnastics.

   Every wide surface (the analysis table, the monthly bars) scrolls inside its
   own container so the PAGE never scrolls horizontally.
   ========================================================================= */

/* -- reels ---------------------------------------------------------------- */
.reel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-4);
}
.reel-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.reel-media {
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 420px;
  object-fit: cover;
  border-radius: var(--radius-s);
  background: var(--surface-3);
}
.reel-media-empty { display: block; }
.reel-meta { display: flex; align-items: baseline; gap: var(--sp-2); }
.reel-author { flex: 1 1 auto; min-width: 0; }
.reel-body { margin: 0; font-size: var(--fs-small); color: var(--text-secondary); }

/* -- shared space lists --------------------------------------------------- */
.space-list { list-style: none; margin: var(--sp-4) 0 0; padding: 0; }
.space-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-block-end: 1px solid var(--border);
}
.space-row:last-child { border-block-end: 0; }
.space-row-main { flex: 1 1 auto; min-width: 0; }
.space-row-main p { margin: 2px 0 0; }

.space-create { margin-block-end: var(--sp-4); }

.space-composer {
  display: flex;
  gap: var(--sp-2);
  margin-block: var(--sp-3);
}
.space-composer input,
.space-composer textarea { flex: 1 1 auto; min-width: 0; }

.space-messages { list-style: none; margin: var(--sp-3) 0 0; padding: 0; }
.space-message {
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  margin-block-end: var(--sp-2);
  background: var(--surface-1);
}
.space-message p { margin: 4px 0; overflow-wrap: anywhere; }

/* -- pages ---------------------------------------------------------------- */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-4);
}
.page-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  align-items: flex-start;
  padding: var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.page-name { font-size: var(--fs-body); font-weight: 600; text-align: start; }

/* -- account analysis ----------------------------------------------------- */
.analysis-list { display: grid; gap: var(--sp-5); }

.analysis-card {
  padding: var(--sp-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  /* Without this the card inherits `min-width: auto` and the monthly-return
     row's min-content width (seven 48px columns) drags the whole report wider
     than the phone, giving the page a horizontal scrollbar. The row scrolls
     inside itself instead. */
  min-width: 0;
  max-width: 100%;
}
.analysis-card > * { min-width: 0; }
.analysis-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-3);
  margin-block-end: var(--sp-4);
  padding-block-end: var(--sp-3);
  border-block-end: 1px solid var(--border);
}
.analysis-id { display: flex; align-items: center; gap: var(--sp-2); }

.analysis-curve { width: 100%; height: 120px; display: block; }
.analysis-zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.analysis-line { fill: none; stroke-width: 2; }
.analysis-line.up { stroke: var(--success); }
.analysis-line.down { stroke: var(--danger); }

.monthly-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  min-height: 120px;
  overflow-x: auto;
  padding-block: var(--sp-2);
}
.monthly-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 48px;
}
/* The plot area every month shares. The zero line is drawn once at the height
   the data puts it, and bars hang from it in both directions. */
.monthly-plot { position: relative; width: 100%; height: 104px; }
.monthly-plot::before {
  content: "";
  position: absolute; inset-inline: 0;
  top: var(--zero-at, 100%);
  height: 1px;
  background: var(--border-strong);
}
.monthly-fill {
  position: absolute;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  width: 20px;
}
.monthly-fill.up   { background: var(--success); border-radius: 2px 2px 0 0; }
.monthly-fill.down { background: var(--danger);  border-radius: 0 0 2px 2px; }
.monthly-value { font-variant-numeric: tabular-nums lining-nums; }
.monthly-value.up   { color: var(--profit); }
.monthly-value.down { color: var(--loss); }

/* The plot half of a report chart frame. Pinned LTR so a percentage curve
   never runs backwards on an RTL page; only the ticks around it follow the
   reading direction. */
.analysis-plot { direction: ltr; width: 100%; min-width: 0; }
.analysis-plot > svg { display: block; width: 100%; }


@media (max-width: 640px) {
  .analysis-card { padding: var(--sp-3); }
  .analysis-head { gap: var(--sp-2); }
}

/* -- reels paging --------------------------------------------------------- */
.reel-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  margin-block-start: var(--sp-4);
}

/* -- profile cross-links -------------------------------------------------- */
.profile-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3);
  margin-block-end: var(--sp-4);
}
.profile-link-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: var(--sp-4);
  text-align: start;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.profile-link-tile:hover { background: var(--surface-2); border-color: var(--border-strong); }
.profile-link-tile:focus-visible { outline: 2px solid var(--vip); outline-offset: 2px; }
.profile-link-tile .stat-value { font-variant-numeric: tabular-nums; }

/* -- account analysis: polished card -------------------------------------- */
.analysis-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
}
.analysis-id { display: flex; align-items: center; gap: var(--sp-3); }
.analysis-avatar {
  width: 44px; height: 44px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-3);
}
.analysis-name { margin: 0; font-size: var(--fs-body); }
.analysis-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-block-start: 4px; }
.analysis-freshness {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: end;
}

/* Charts sit in their own frame so a wide series scrolls inside it rather
   than pushing the page sideways. */
.chart-frame { overflow-x: auto; padding-block: var(--sp-2); }
.analysis-dd { height: 90px; }
.analysis-dd-fill { fill: var(--danger-soft); stroke: none; }

/* win / loss / break-even */
.dist-bar {
  display: flex;
  height: 26px;
  border-radius: var(--radius-s);
  overflow: hidden;
  border: 1px solid var(--border);
}
.dist-seg {
  display: flex; align-items: center; justify-content: center;
  min-width: 0;
  color: #0b0d12;
  font-variant-numeric: tabular-nums;
}
.dist-seg.up { background: var(--success); }
.dist-seg.flat { background: var(--text-secondary); }
.dist-seg.down { background: var(--danger); }
.dist-label { font-weight: 600; }

/* instrument distribution (account analysis) */
.instrument-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.instrument-row { display: flex; align-items: center; gap: var(--sp-3); }
.instrument-name { flex: 0 0 90px; font-size: var(--fs-small); }
.instrument-track {
  flex: 1 1 auto;
  height: 8px;
  min-width: 0;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
/* Instrument share is data, not an action: it takes a chart series colour
   rather than the cobalt reserved for controls and selection. */
.instrument-fill { display: block; height: 100%; background: var(--series-2); }
.instrument-share { flex: 0 0 56px; text-align: end; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .analysis-head { flex-direction: column; }
  .analysis-freshness { align-items: flex-start; text-align: start; }
  .instrument-name { flex-basis: 70px; }
}

/* -- Dashboard Grid -- */
.dashboard-grid { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ==========================================================================
   LIVE FIGURES, STALE STANDING, NARROW TABLES
   ========================================================================== */

.kpi-value,
.hero-value,
.stat-tile .stat-value {
  min-inline-size: 8ch;
  display: inline-block;
  text-align: end;
}

.data-table td.num,
.data-table th.num {
  min-inline-size: 7ch;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-inline-size: 100%;
}

@media (max-width: 720px) {
  .data-table.has-sticky-start th:first-child,
  .data-table.has-sticky-start td:first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    background: var(--bg-surface);
    box-shadow: 8px 0 8px -8px var(--bg-overlay);
  }
  html[dir="rtl"] .data-table.has-sticky-start th:first-child,
  html[dir="rtl"] .data-table.has-sticky-start td:first-child {
    box-shadow: -8px 0 8px -8px var(--bg-overlay);
  }
  .data-table.has-sticky-start thead th:first-child {
    z-index: 2;
    background: var(--bg-surface-2);
  }
}

.is-stale .stat-value,
.is-stale .kpi-value,
.is-stale .num,
tr.is-stale td.num {
  opacity: 0.72;
}

.tn-stale {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-block-end: var(--sp-4);
  border-inline-start: 3px solid var(--warning);
}

.tn-stale strong {
  color: var(--warning);
}

.pill.status-PENDING_APPROVAL { border-style: dashed; }
.pill.status-WITHDRAWN,
.pill.status-ADMIN_REMOVED { background: var(--bg-surface-2); }
.pill.status-REJECTED { text-decoration: line-through; }

.icon-dir { display: inline-block; }
html[dir="rtl"] .icon-dir { transform: scaleX(-1); }


