/* ==========================================================================
   KURDOGRAPHY — DESIGN SYSTEM: THE EXAMINATION ROOM
   Authority: docs/ui-design-plan.md and docs/ui-banned-audit.md.

   A bright, clinical room with instruments in it. Light is the material:
   a luminous cool-white ground, white cards, ink text and hairlines. One
   loud colour, Signal Yellow, always means attention (act / active / yours /
   just changed). Profit and loss are teal and vermilion, on the blue–yellow
   axis, and every use is backed by a sign or a word. One family, Archivo,
   variable in weight and width: wide for verdicts, condensed for labels,
   tabular for figures. Vazirmatn carries Arabic script.

   Every token name that existed before still exists (scripts read some by
   name); values are new, and new roles sit beside them. Light values below
   are native; theme-appearance.css re-values the same names for dark.
   ========================================================================== */

:root {
  color-scheme: light;

  /* -- Ground and surfaces --------------------------------------------- */
  --bg-base:        #F3F8F6;   /* Lab White: the luminous ground            */
  --bg-surface:     #FFFFFF;   /* a card                                    */
  --bg-surface-2:   #EAF0EE;   /* a recessed well inside a card             */
  --bg-elevated:    #FFFFFF;   /* popovers, menus                           */
  --bg-overlay:     rgba(16, 35, 58, 0.58);

  --border-subtle:  #E1E8E6;
  --border-default: #CDD7D9;   /* the hairline                              */
  --border-strong:  #9FAEB8;

  /* -- Ink ---------------------------------------------------------------- */
  --text-primary:   #10233A;   /* Ink                                       */
  --text-secondary: #35485E;
  --text-muted:     #5B6B85;   /* 5.0:1 on the ground                       */
  --text-disabled:  #9AA8B8;
  --text-inverse:   #F3F8F6;

  /* -- Action ---------------------------------------------------------------
     `--accent` / `--primary` is the colour of an actionable THING in text
     form — a link, an outline, the active label. It is ink, because yellow
     cannot be read as text. The yellow is a FILL: primary buttons, the
     active mark, the reader's own row, focus. Ink sits on it at 11:1. */
  --accent:         #10233A;
  --accent-hover:   #1F3A5C;
  --accent-subtle:  rgba(255, 214, 10, 0.30);
  --focus-ring:     #10233A;
  --action-fill:    #FFD60A;   /* Signal Yellow                             */
  --action-fill-hover: #FFC800;
  --action-ink:     #10233A;

  /* -- Verdicts -------------------------------------------------------------
     Text forms clear 4.5:1 on white; the -fill forms are for rails, marks and
     bars where a stronger value reads better and no text sits on them. */
  --success:        #0A7D6D;   /* Teal, text                                */
  --success-fill:   #0B9E8A;
  --critical:       #C4361C;   /* Vermilion, text                           */
  --critical-fill:  #E5432A;
  --warning:        #A35400;   /* Amber, text                               */
  --warning-fill:   #F5B841;
  --info:           #2B5C8A;
  --pending:        #A35400;
  --verified:       #0A7D6D;
  --disabled:       #9AA8B8;

  --profit-subtle:  rgba(11, 158, 138, 0.13);
  --loss-subtle:    rgba(229, 67, 42, 0.12);

  /* -- Legacy aliases, mapped to the roles above ---------------------------- */
  --plane:          var(--bg-base);
  --surface-0:      var(--bg-surface-2);
  --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);
  --on-primary:     var(--action-ink);
  --danger-fill:    var(--critical-fill);
  --danger:         var(--critical);
  --danger-soft:    var(--loss-subtle);
  --danger-border:  rgba(229, 67, 42, 0.40);
  --success-soft:   var(--profit-subtle);
  --success-border: rgba(11, 158, 138, 0.40);
  --warning-soft:   rgba(245, 184, 65, 0.22);
  --warning-border: rgba(163, 84, 0, 0.35);
  --info-soft:      rgba(43, 92, 138, 0.10);
  --info-border:    rgba(43, 92, 138, 0.35);

  --ai:             #5B6B85;   /* machine-written content is marked neutral, by a glyph */
  --ai-soft:        rgba(91, 107, 133, 0.10);
  --ai-border:      rgba(91, 107, 133, 0.35);
  --good:           var(--success);
  --vip:            var(--verified);

  /* -- Chart series: flat, away from the verdict pair ----------------------- */
  --series-1:       #1C3E66;   /* equity                                    */
  --series-2:       #7B8CA8;   /* balance                                   */
  --series-3:       #2B6CB0;   /* buy                                       */
  --series-4:       #8A6D00;
  --series-5:       #5E6F3A;
  --series-6:       #B84C9A;   /* sell                                      */
  --buy:            var(--series-3);
  --sell:           var(--series-6);
  --series-equity:  var(--series-1);
  --series-balance: var(--series-2);
  --zero-line:      #A33A2C;
  --grid:           var(--border-subtle);
  --axis:           var(--border-strong);

  /* -- Scorecard bands ------------------------------------------------------ */
  --band-critical:          var(--critical);
  --band-weak:              #B85C00;
  --band-needs_improvement: var(--warning);
  --band-good:              #4F8A1C;
  --band-excellent:         var(--success);

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

  /* -- Typography ----------------------------------------------------------- */
  --font-ui-latin: "TC Inter", Inter, "TC Archivo", Archivo, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-ui-arabic-script: "TC Vazirmatn", Vazirmatn, "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --font: var(--font-ui-latin), var(--font-ui-arabic-script);
  --font-display: var(--font-ui-latin), var(--font-ui-arabic-script);
  --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 Vazirmatn. */
  --font-numeric: "TC Inter", var(--font-ui-latin);

  /* Inter has no width axis. Stretching it synthesises a slanted/condensed
     Latin face; Vazirmatn ignores font-stretch. Keep every role at 100%. */
  --wdth-display:   100%;
  --wdth-title:     100%;
  --wdth-section:   100%;
  --wdth-ui:        100%;
  --wdth-label:     100%;
  --wdth-dense:     100%;

  --fs-hero:    88px;
  --fs-display: 44px;
  --fs-title:   32px;
  --fs-section: 20px;
  --fs-card:    15px;
  --fs-body:    14px;
  --fs-small:   13px;
  --fs-caption: 12px;
  --fs-label:   12px;
  --fs-micro:   11px;
  --fs-figure:  32px;

  --lh-tight:   1.1;
  --lh-body:    1.5;

  /* -- Spacing scale (names kept; every layout reads them) ------------------ */
  --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;
  --sp-16: 64px;
  --sp-24: 96px;

  /* -- Radius: instruments, not bubbles ------------------------------------- */
  --radius-xs: 2px;
  --radius-s:  2px;
  --radius:    2px;
  --radius-l:  4px;
  --radius-pill: 2px;

  /* -- Elevation: a hairline first, a soft ink cast only for floating things - */
  --shadow-1: none;
  --shadow-2: 0 1px 0 rgba(16, 35, 58, 0.06), 0 12px 32px -14px rgba(16, 35, 58, 0.28);
  --shadow-3: 0 2px 0 rgba(16, 35, 58, 0.06), 0 24px 56px -20px rgba(16, 35, 58, 0.36);
  --ring: 0 0 0 2px var(--focus-ring);
  --hairline: 1px solid var(--border-default);

  /* -- Controls ------------------------------------------------------------- */
  --control-h:    36px;
  --control-h-sm: 30px;
  --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:          248px;
  --sidebar-w-collapsed: 64px;
  --rail-w:             200px;
  --content-max:        100%;
  --topbar-h:           52px;

  /* -- Motion ----------------------------------------------------------------
     Three durations and three eases. Answering an action is quick (--speed);
     something entering the page takes --speed-enter; a verdict stamps with
     --ease-stamp. prefers-reduced-motion sets all three durations to 0. */
  --speed:       140ms;
  --speed-slow:  220ms;
  --speed-enter: 320ms;
  --ease:          cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-stamp:    cubic-bezier(0.34, 1.4, 0.64, 1);
}

: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);
  --font-display: var(--font-ui-arabic-script), var(--font-ui-latin);
}

@media (prefers-reduced-motion: reduce) {
  :root { --speed: 0ms; --speed-slow: 0ms; --speed-enter: 0ms; }
}

[hidden] { display: none !important; }

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

html { font-synthesis: none; }

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);
  font-style: normal;
  font-stretch: var(--wdth-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
html[dir="rtl"] :is(h1, h2, h3, h4) { letter-spacing: 0; font-stretch: 100%; }
h1, h2, h3, h4, h5, h6, p, span, em {
  font-style: normal !important;
}

h1 { font-size: var(--fs-display); font-weight: 800; font-stretch: var(--wdth-display); }
h2 { font-size: var(--fs-title); font-stretch: var(--wdth-title); }
h3 { font-size: var(--fs-section); font-weight: 650; font-stretch: var(--wdth-section); }
h4 { font-size: var(--fs-card); font-weight: 600; font-stretch: var(--wdth-section); }

p { margin: 0; }

a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--speed) var(--ease), color var(--speed) var(--ease);
}
a:hover {
  color: var(--primary-hover);
  text-decoration-thickness: 2px;
  text-decoration-color: var(--action-fill);
}

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

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

/* One focus treatment everywhere: an ink outline with a yellow halo, so it is
   visible on white, on yellow and on ink. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--accent-subtle);
  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 a
   leading minus or currency sign strands on the wrong side of the run.
   text-align:end then lines the decimals up inside that LTR box. */
html[dir="rtl"] :is(.num, .kpi-value, .stat-value, .m-value, .mono) {
  direction: ltr;
  text-align: end;
}

/* The block box direction needs goes ONLY to non-table elements: a table cell
   given display:inline-block leaves the column model and the header drifts
   away from its data (test/rtl-layout.js asserts this). */
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); }

/* A label is a short line in sentence case, set slightly condensed so it reads
   as a label by shape rather than by shouting. Never tracked caps. */
.label{
  font-size: var(--fs-label);
  font-weight: 600;
  font-stretch: var(--wdth-label);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
.label.vip, .eyebrow.vip { color: var(--text-primary); }
html[dir="rtl"] .label { letter-spacing: 0; text-transform: none; font-stretch: 100%; }

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

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

.card.vip { border-color: var(--text-primary); border-inline-start-width: 4px; }

.card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-block-end: var(--sp-5);
}
.card-head:empty { display: none; }
.card-head > h2, .card-head > h3 { font-size: var(--fs-section); margin: 0; }
/* Subtitle always occupies the line under the title, never the tools row.
   Direct-child order keeps existing markup working without a wrapper. */
.card-head > p {
  order: 3;
  flex-basis: 100%;
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-secondary);
}
.card-head .spacer { flex: 1 1 auto; order: 1; }
.card-head > select,
.card-head > button,
.card-head > a,
.card-head > input,
.card-head > .search-control,
.card-head > .range-pair,
.card-head > .card-head-tools {
  order: 2;
}
.card-head-copy {
  flex: 1 1 12rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-head-copy h2,
.card-head-copy h3 { margin: 0; font-size: var(--fs-section); }
.card-head-copy p {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-secondary);
}
.card-head-tools,
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  flex: 0 1 auto;
  margin-inline-start: auto;
}
.card-head-tools p { margin: 0; }

.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: 650;
  color: var(--action-ink);
  background: var(--action-fill);
  border: 1px solid var(--action-ink);
  border-radius: var(--control-radius);
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  transition: background var(--speed) var(--ease),
              border-color var(--speed) var(--ease),
              color var(--speed) var(--ease),
              transform var(--speed) var(--ease);
}
/* Hover fills from the reading-start edge: the fill is a transform, and the
   origin mirrors in RTL so the sweep still starts where reading starts. */
.btn::before {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background: var(--action-fill-hover);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform var(--speed-slow) var(--ease-out-expo);
}
html[dir="rtl"] .btn::before { transform-origin: 100% 50%; }
.btn:hover:not(:disabled)::before { transform: scaleX(1); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.ghost, .btn.secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--text-primary);
}
.btn.ghost::before, .btn.secondary::before { background: var(--accent-subtle); }
.btn.ghost:hover:not(:disabled), .btn.secondary:hover:not(:disabled) {
  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(--critical-fill);
  border-color: var(--critical);
  color: #FFFFFF;
}
.btn.danger::before { background: var(--critical); }
.btn.danger:hover:not(:disabled) { background: var(--critical-fill); border-color: var(--critical-fill); }

.btn.success {
  background: var(--success-fill);
  border-color: var(--success);
  color: #FFFFFF;
}
.btn.success::before { background: var(--success); }
.btn.success:hover:not(:disabled) { background: var(--success-fill); border-color: var(--success-fill); }

.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-1);
  border: var(--control-border) solid var(--border-strong);
  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: none;
}
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(--text-primary);
}
/* 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: 0;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle), 0 0 0 1px var(--text-primary);
  background: var(--surface-1);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--text-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);
}
textarea {
  height: auto; min-height: 96px; padding-block: 11px;
  resize: vertical; line-height: var(--lh-body);
}

input[type="number"] { font-family: var(--font-numeric); font-variant-numeric: tabular-nums lining-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;
}
/* The caret is drawn on the physical LEFT in RTL, which is the inline END,
   so the 32px reserved for it stays on padding-inline-end (the logical rule
   above already puts it there). Swapping the paddings here, as the old rule
   did, put the room on the wrong side and let a Latin value run under the
   caret. Only the background position needs flipping. */
html[dir="rtl"] select {
  background-position: left 9px center, left 14px center;
}

.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(--text-primary);
  cursor: pointer;
}

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

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

.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 1px;
  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);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
}
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: var(--fs-label);
  font-weight: 600;
  font-stretch: var(--wdth-label);
  letter-spacing: 0;
  text-transform: none;
  text-align: start;
  padding: var(--sp-3) var(--sp-4);
  white-space: nowrap;
  border-block-end: 1px solid var(--text-primary);
  box-shadow: none;
}
html[dir="rtl"] thead th { letter-spacing: 0; text-transform: none; font-stretch: 100%; }
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-4);
  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(--action-fill);
  font-weight: 600;
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-block-end: -2px;
  inset-inline: 0;
  height: 3px;
  background: var(--action-fill);
}

/* =========================================================== 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-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.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: var(--bg-overlay);
  animation: tc-fade var(--speed) var(--ease);
}
.modal {
  width: min(540px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface-3);
  border: 1px solid var(--text-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  padding: var(--sp-8);
  animation: tc-rise var(--speed-enter) var(--ease-out-expo);
  position: relative;
}
.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-inverse);
  background: var(--text-primary);
  border: 0;
  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-inverse);
  background: var(--text-primary);
  border: 0;
  border-inline-start: 4px solid var(--action-fill);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: tc-slide-in var(--speed-enter) var(--ease-stamp);
}
@keyframes tc-slide-in { from { opacity: 0; transform: translateY(14px); } }

/* ============================================================== 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);
  min-width: 0;
}
.kpi-label {
  font-size: var(--fs-label);
  font-weight: 600;
  font-stretch: var(--wdth-label);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
html[dir="rtl"] .kpi-label { letter-spacing: 0; text-transform: none; font-stretch: 100%; }
.kpi-value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.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-1);
  border-color: var(--text-primary);
  border-inline-start-width: 4px;
}
.kpi-primary .kpi-value { font-size: var(--fs-figure); font-weight: 700; }
@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: 0;
  border: 2px solid var(--plane);
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

@media (max-width: 720px) {
  :root { --fs-hero: 44px; --fs-display: 36px; --fs-title: 26px; --fs-section: 18px; --fs-figure: 28px; --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-surface);
  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: 750; font-stretch: var(--wdth-title); letter-spacing: -0.02em; white-space: nowrap; }
.sidebar-brand-text span {
  font-size: var(--fs-micro); color: var(--text-muted); font-weight: 500;
  font-stretch: var(--wdth-label); letter-spacing: 0; white-space: nowrap;
}
html[dir="rtl"] .sidebar-brand-text :is(strong, span) { letter-spacing: 0; font-stretch: 100%; }

.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: var(--fs-micro); font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; color: var(--text-muted);
  white-space: nowrap;
}
html[dir="rtl"] .sidebar-group { letter-spacing: 0; font-stretch: 100%; }
.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(--accent-subtle);
  color: var(--text-primary);
  font-weight: 650;
  border-block-end: 0;
}
/* The active mark: a yellow rail on the reading-start edge. motion-app.js
   slides a single shared mark between items; this static one is the no-JS
   and reduced-motion truth. */
.sidebar .tab[aria-selected="true"]::before {
  content: "";
  position: absolute;
  inset-inline-start: 0; inset-block: 4px;
  width: 4px; border-radius: 0;
  background: var(--action-fill);
}

/* 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(--text-primary); }
.sidebar-label {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

/* 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(--text-primary); color: var(--text-inverse);
  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-inverse); background: var(--text-primary);
  border: 0; 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: var(--bg-overlay);
  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: var(--fs-micro); font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; color: var(--text-muted);
}
html[dir="rtl"] .section-rail-title { letter-spacing: 0; font-stretch: 100%; }
.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(--text-primary);
  background: var(--accent-subtle);
  border-inline-start-color: var(--action-fill);
  font-weight: 650;
}
.section-anchor { scroll-margin-block-start: calc(var(--topbar-h) + var(--sp-5)); }
#sec-performance,
#sec-volume,
#sec-symbols,
#sec-sessions,
#sec-risk {
  min-height: calc(100dvh - var(--topbar-h) - 72px);
}

/* ==========================================================================
   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: var(--fs-micro); font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; color: var(--text-muted);
}
html[dir="rtl"] .donut-total-label { letter-spacing: 0; font-stretch: 100%; }

.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(92vw, 320px);
    /* overflow:hidden here clips RTL labels during the slide; the scroll
       pane already clips its own list. */
    overflow: visible;
    transform: translate3d(-102%, 0, 0);
    transition: transform var(--speed) var(--ease);
    box-shadow: var(--shadow-3);
    padding-block-end: env(safe-area-inset-bottom, 0px);
  }
  html[dir="rtl"] .sidebar {
    width: min(94vw, 340px);
    transform: translate3d(102%, 0, 0);
  }
  /* translate3d(0,0,0), not `none`: `none` is not interpolable with a
     translate, so some mobile browsers leave the rail off-screen or paint
     the panel without its text. The RTL selector must beat
     html[dir="rtl"] .sidebar. */
  .app-shell.drawer-open .sidebar,
  html[dir="rtl"] .app-shell.drawer-open .sidebar {
    transform: translate3d(0, 0, 0);
  }
  .sidebar-toggle { display: none; }
  .sidebar .tab {
    min-height: 44px;
    padding: 10px 12px;
  }
  /* `display: revert` is ignored on WebViews that do not implement it, so
     the collapsed `display: none` would stay and the open menu would show
     icons with no words. Named values only. */
  .app-shell.is-collapsed .sidebar-label { display: block; }
  .app-shell.is-collapsed .sidebar-brand-text,
  .app-shell.is-collapsed .sidebar-user-id { display: flex; }
  .app-shell.is-collapsed .sidebar-group { display: block; }
  .app-shell.is-collapsed .tab .count { display: inline-grid; }
  .app-shell.is-collapsed .sidebar-home span:not(.sidebar-home-ico) { display: inline; }
  .app-shell.is-collapsed .sidebar .tab { justify-content: flex-start; padding-inline: 12px; }
  .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 */

/* -- 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(--buy);  background: color-mix(in srgb, var(--buy) 10%, transparent);  border-color: color-mix(in srgb, var(--buy) 45%, transparent); }
.pill.sell { color: var(--sell); background: color-mix(in srgb, var(--sell) 10%, transparent); border-color: color-mix(in srgb, var(--sell) 45%, transparent); }

/* -- 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); }
.m-value.neutral { color: var(--text-secondary); }
.m-value.warn-value { color: var(--warning); }
/* 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: 4px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-label {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; text-transform: none;
}
html[dir="rtl"] .stat-label { font-stretch: 100%; }
.stat-tile .stat-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; 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: 8px 12px;
  text-align: start;
  font-size: var(--fs-caption);
  font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; text-transform: none;
  color: var(--text-muted);
  background: var(--surface-1);
  border-block-end: 1px solid var(--text-primary);
  white-space: nowrap;
}
html[dir="rtl"] .data-table th { font-stretch: 100%; }
.data-table th.num, .data-table td.num { text-align: end; }
.data-table td {
  padding: 10px 12px;
  border-block-end: 1px solid var(--border-faint);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.data-table td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.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: var(--profit-subtle); }
.spark-down .spark-line { stroke: var(--series-1); }
.spark-down .spark-area { fill: var(--loss-subtle); }
.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: 1px 6px;
  font-size: var(--fs-caption);
  font-stretch: var(--wdth-label);
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
}

/* -- MT5 account cards ---------------------------------------------------- */
.mt5-card {
  padding: 16px 18px;
  margin-bottom: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.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, 740px) 320px;
  justify-content: center;
  gap: var(--sp-4);
  align-items: start;
  max-inline-size: 1100px;
  margin-inline: auto;
}
.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; }

.community-home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.community-home-header .page-sub {
  margin: 4px 0 0;
  max-inline-size: 42rem;
  color: var(--text-secondary);
  font-size: var(--fs-small);
}
.community-header-tools {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1 1 280px;
  max-inline-size: 520px;
}
.cm-search-wrap { position: relative; flex: 1 1 auto; min-inline-size: 0; }
.cm-search-results {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline: 0;
  z-index: 20;
  max-block-size: min(70vh, 420px);
  overflow: auto;
  padding: var(--sp-2);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md, 0 8px 24px color-mix(in srgb, var(--text-primary) 12%, transparent));
}
.cm-search-section { padding: var(--sp-2) var(--sp-2) 0; }
.cm-search-section h3 {
  margin: 0 0 6px;
  font-size: var(--fs-micro);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.cm-search-row {
  inline-size: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px 10px;
  text-align: start;
  background: none;
  border: 0;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--text-primary);
}
.cm-search-row:hover, .cm-search-row:focus-visible { background: var(--surface-2); }
.cm-search-recent { color: var(--text-secondary); font-size: var(--fs-caption); }

.composer-collapsed {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
}
.composer-collapsed:hover { border-color: var(--border-strong); }
.composer-collapsed-prompt {
  flex: 1;
  text-align: start;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
}
.composer-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cm-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: end center;
  background: color-mix(in srgb, var(--text-primary) 28%, transparent);
  padding: var(--sp-3);
}
.cm-sheet {
  inline-size: min(560px, 100%);
  max-block-size: min(92vh, 820px);
  overflow: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
}
@media (min-width: 721px) {
  .cm-sheet-backdrop { place-items: center; }
}
.composer-idea-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  margin-block-start: var(--sp-2);
}
.composer-idea-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--fs-caption);
  color: var(--text-secondary);
}
.composer-idea-grid input, .composer-idea-grid select { font-family: var(--mono); }
/* The six ways a trade idea opens (owner request, 2026-10-01): a row a side, a
   column a kind (market, limit, stop), so three keys across even at 375px. A
   pending kind has a dashed edge and a ring in its corner until chosen, then a
   filled dot: it reads as "waits for a price". */
.dir-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.dir-toggle button {
  position: relative;
  min-inline-size: 0;
  min-block-size: 40px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-s);
  padding: 6px 4px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.dir-toggle button.is-pending:not(.is-on) { border-style: dashed; }
.dir-toggle button.is-pending::after {
  content: '';
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  inline-size: 6px;
  block-size: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  opacity: 0.55;
}
.dir-toggle button.is-pending.is-on::after { background: currentColor; opacity: 1; }
.dir-toggle button.is-on[data-dir="BUY"] {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-soft);
}
.dir-toggle button.is-on[data-dir="SELL"] {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}
/* Under the keys: where a pending entry belongs, the reward for the risk, and a
   refusal, each in its own line. */
.idea-hint, .idea-ratio, .idea-error {
  margin: 8px 0 0;
  font-size: var(--fs-caption);
  line-height: 1.5;
}
.idea-hint { color: var(--text-secondary); }
.idea-ratio { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; color: var(--text-secondary); }
.idea-ratio b { color: var(--text-primary); font-family: var(--mono); unicode-bidi: isolate; }
.idea-error { color: var(--danger); font-weight: 600; }
.idea-hint[hidden], .idea-ratio[hidden], .idea-error[hidden] { display: none; }

.post-menu { margin-inline-start: auto; position: relative; }
.post-menu-btn {
  background: none;
  border: 0;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-s);
}
.post-menu-btn:hover, .post-menu-btn:focus-visible { background: var(--surface-2); color: var(--text-primary); }
.post-menu-list {
  position: absolute;
  inset-inline-end: 0;
  inset-block-start: 100%;
  z-index: 8;
  min-inline-size: 160px;
  padding: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.post-menu-list button, .post-menu-list a {
  display: block;
  inline-size: 100%;
  text-align: start;
  background: none;
  border: 0;
  padding: 8px 10px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 6px;
  text-decoration: none;
}
.post-menu-list button:hover, .post-menu-list a:hover { background: var(--surface-2); }

.trust-badges { display: inline-flex; gap: 4px; align-items: center; margin-inline-start: 6px; }
.trust-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-2);
}
.trust-badge.is-email { color: var(--info); border-color: var(--info-border); background: var(--info-soft); }
.trust-badge.is-account { color: var(--text-primary); }
.trust-badge.is-performance { color: var(--vip); border-color: var(--vip); }
.trust-badge.is-execution { color: var(--success); border-color: var(--success); background: var(--success-soft); }

.idea-card {
  margin-block: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.idea-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-block-end: 8px;
}
.idea-dir {
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
}
/* Arabic-script letters join; spacing between them breaks the joins, so the
   longer Limit and Stop words in Sorani and Arabic keep none (as every label). */
html[dir="rtl"] .idea-dir { letter-spacing: 0; }
.idea-dir.is-buy { color: var(--success); border-color: var(--success); background: var(--success-soft); }
.idea-dir.is-sell { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
/* A pending idea (limit, stop) has the dashed edge its key in the composer has. */
.idea-dir.is-pending { border-style: dashed; }
/* On a profile tile the word shares a small square: it wraps rather than spills. */
.ig-tile-idea .idea-dir {
  max-inline-size: 100%;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}
.idea-levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}
.idea-levels dt { font-size: var(--fs-micro); color: var(--text-muted); font-family: var(--font-ui); }
.idea-levels dd { margin: 0; font-size: var(--fs-small); color: var(--text-primary); }
.idea-status {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-secondary);
}
.idea-verify {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-block-start: 8px;
}
.idea-updates { margin-block-start: 10px; padding-inline-start: 14px; }
.idea-updates li { font-size: var(--fs-caption); color: var(--text-secondary); }

.cm-notif-wrap { position: relative; }
.share-list { display: flex; flex-direction: column; gap: 6px; max-block-size: 240px; overflow: auto; }
.reel-author {
  padding: 0; background: none; border: 0; font-weight: 600; cursor: pointer;
  color: var(--text-primary);
}
.reel-card .post-actions { flex-wrap: wrap; }
.cm-msg-back { display: none; }

.comment.is-reply { margin-inline-start: 36px; }
.comment-edited { color: var(--text-muted); font-size: var(--fs-micro); margin-inline-start: 6px; }
.post-edited { color: var(--text-muted); font-size: var(--fs-micro); margin-inline-start: 6px; }
.feed-more { display: flex; justify-content: center; padding-block: var(--sp-4); }
.feed-skeleton .post { min-block-size: 88px; background: var(--surface-2); }
.discover-extra { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); margin-block-end: var(--sp-5); }
.discover-heading { font-size: var(--fs-card); margin: var(--sp-4) 0 var(--sp-3); }
.community-feed-card { padding: 0; overflow: hidden; }
.community-feed-card .composer, .community-feed-card .composer-collapsed { border: 0; border-radius: 0; }

html[dir="rtl"] .idea-levels { text-align: start; }
html[lang="ckb"] .community-layout,
html[lang="ckb"] #panel-community,
html[lang="ar"] .community-layout,
html[lang="ar"] #panel-community {
  font-weight: 400;
}
html[lang="ckb"] #panel-community h1,
html[lang="ckb"] #panel-community h2,
html[lang="ar"] #panel-community h1,
html[lang="ar"] #panel-community h2 { font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .cm-sheet, .composer-collapsed { transition: none; }
}

/* -- 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: var(--bg-overlay);
  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, var(--bg-overlay), 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) {
  .community-layout { grid-template-columns: minmax(0, 740px); }
  .community-rail { display: none; }
}
@media (max-width: 640px) {
  .feed-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-block-end: 4px;
  }
  .chip-sep { display: none; }
  .composer-meta input { flex-basis: 100%; }
  .community-header-tools { inline-size: 100%; }
  .community-home-header { flex-wrap: wrap; }
  .messenger.is-open .conversation-list { display: none; }
  .messenger:not(.is-open) .conversation-pane { display: none; }
  .reel-grid { grid-template-columns: 1fr; }
  .cm-msg-back { display: inline-flex; }
}

/* TOURNAMENT Only what the tournament screens genuinely add. Cards, pills, stat tiles, */

/* -- 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: var(--warning);
  background: var(--warning-soft);
  border-color: var(--warning-border);
}

/* -- 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-4) var(--sp-2);
  background: var(--surface-1);
  border: 1px solid var(--text-primary);
  border-radius: var(--radius-s);
}
.countdown-value {
  font-size: var(--fs-figure); font-weight: 750; line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.countdown-label {
  font-size: var(--fs-label); font-weight: 600; font-stretch: var(--wdth-label);
  letter-spacing: 0; text-transform: none;
  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(--accent-subtle);
}
/* 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: 4px solid var(--action-fill);
}

/* Stale is a rail and a word, not a wash: with every row stale (the worker
   asleep) a full-row tint would drown the reader's own row. */
.data-table tr.is-stale > td {
  background: transparent;
}
.data-table tr.is-stale > td:first-child {
  border-inline-start: 4px solid var(--warning-fill);
}

.tn-rank-table tbody td.num {
  font-variant-numeric: tabular-nums lining-nums;
  font-family: var(--font-numeric);
}
/* THE DOCKET. The rank is the biggest thing on the row, set in the wide
   voice; the name is the second; the score is tabular. The reader's own
   row keeps its yellow rail. Nothing here changes what a cell contains. */
.tn-rank-table tbody td:first-child.num {
  font-size: 26px; font-weight: 800; font-stretch: var(--wdth-display);
  letter-spacing: -0.03em; line-height: 1; color: var(--text-primary);
  width: 4.5ch; padding-block: 8px;
}
.tn-rank-table tbody tr:first-child td:first-child.num { color: var(--action-ink); }
.tn-rank-table tbody tr:first-child td:first-child.num::after {
  content: ""; display: block; height: 3px; background: var(--action-fill); margin-block-start: 3px;
}
.tn-rank-table tbody td:nth-child(2) .link-button { font-weight: 700; font-size: var(--fs-card); }
.tn-rank-table tbody td:nth-child(3).num { font-size: var(--fs-card); font-weight: 650; color: var(--text-primary); }
.tn-rank-table tbody td { padding-block: 10px; }
.tn-rank-table tbody tr.is-unranked td:first-child.num { color: var(--text-muted); font-size: 18px; }
.tn-rank-table tbody tr.is-unranked:first-child td:first-child.num::after { display: none; }
/* Disqualified: a vermilion frame, a struck rank, the reason underneath. */
.card.tn-dq { border: 2px solid var(--critical-fill); }
.card.tn-dq .card-head h3 { color: var(--critical); }
.card.tn-dq .card-head h3::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-inline-end: 8px;
  background: var(--critical-fill); vertical-align: 1px;
}
.card.tn-dq .tn-rank-table tbody td:first-child.num { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: var(--critical-fill); }
.card.tn-exited { border-style: dashed; }
.card.tn-exited .link-button { color: var(--text-secondary); }

/* -- 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: 650; font-stretch: var(--wdth-section);
  text-transform: none; letter-spacing: 0;
  color: var(--text-primary);
  margin-block: var(--sp-4) var(--sp-2);
  padding-block-end: 4px;
  border-block-end: 1px solid var(--border);
}
.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. */
.labeled-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.labeled-field-label {
  font-size: var(--fs-label);
  color: var(--text-muted);
  font-weight: 600; font-stretch: var(--wdth-label);
  text-transform: none;
  letter-spacing: 0;
  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(--critical);
  border-color: var(--critical);
  background: var(--surface-1);
}
.btn-danger:hover:not(:disabled),
.btn-sm.btn-danger:hover:not(:disabled) {
  background: var(--critical-fill); border-color: var(--critical-fill); color: #FFFFFF;
}

/* 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-inline-start-width: 4px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--text-primary);
  font-size: var(--fs-small);
  font-weight: 600;
}

/* 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: 2px solid var(--critical-fill);
  border-radius: var(--radius);
  background: var(--loss-subtle);
}
.tn-danger-title { color: var(--critical); font-stretch: var(--wdth-title); }

/* 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;
  font-weight: 600;
  text-align: start;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  cursor: pointer;
  min-block-size: var(--control-h-lg);
}
.link-button:hover { text-decoration-color: var(--action-fill); text-decoration-thickness: 2px; }
.link-button:focus-visible {
  outline: 2px solid var(--focus-ring);
  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-numeric);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: var(--fs-small);
  letter-spacing: 0;
  padding: var(--sp-2) var(--sp-3);
  border-inline-start: 2px solid var(--text-primary);
  background: var(--surface-2);
}
.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). */

.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>. */

.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. */

/* -- 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: var(--text-inverse);
  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); }


