/* MacroTrust AI — dashboard styles
   Palette: oil-black surfaces, gold identity accent, green/red strictly
   semantic (direction & outcome). Type: Space Grotesk (English UI),
   El Messiri (Arabic UI + Arabic content), IBM Plex Mono (all numerals). */

:root {
  --bg: #131310;
  --surface: #1b1b16;
  --surface-2: #21211a;
  --line: #2d2d24;
  --line-strong: #3a3a2e;
  --text: #eae8dc;
  --muted: #97958a;
  --faint: #6d6b60;
  --gold: #d9a92f;
  --gold-soft: rgba(217, 169, 47, 0.14);
  --long: #56b286;
  --long-soft: rgba(86, 178, 134, 0.14);
  --short: #e06060;
  --short-soft: rgba(224, 96, 96, 0.13);
  --radius: 6px;
  --font-ui: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  --font-ar: 'El Messiri', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

html[lang='ar'] { --font-ui: var(--font-ar); }

/* Language-tagged content keeps its own face on either UI language
   (e.g. the bilingual report blocks). Zero-specificity so .num/mono
   still wins inside. */
:where([lang='ar'], [lang='ar'] *) { font-family: var(--font-ar); }
:where([lang='en'], [lang='en'] *) { font-family: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--gold); }

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- Shell ---------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  border-inline-end: 1px solid var(--line);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  width: 11px; height: 11px;
  background: var(--gold);
  display: inline-block;
  transform: translateY(1px) rotate(45deg);
}
.brand-name { font-weight: 700; letter-spacing: 0.02em; font-size: 16px; }
.brand-sub { color: var(--faint); font-size: 12px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  border-inline-start: 2px solid transparent;
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active {
  color: var(--text);
  background: var(--surface);
  border-inline-start-color: var(--gold);
}

.sidebar-foot {
  margin-top: auto;
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.5;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.main { flex: 1; min-width: 0; padding: 32px 40px 64px; max-width: 1160px; }

/* ---- Page header ------------------------------------------------------ */

.page-head { margin-bottom: 26px; }
.eyebrow {
  display: flex; align-items: center; gap: 10px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.eyebrow::after { content: ''; height: 1px; width: 42px; background: var(--gold); opacity: 0.5; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

.head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---- Flash ------------------------------------------------------------ */

.flash {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 20px;
  border: 1px solid;
}
.flash-ok { background: var(--long-soft); border-color: rgba(86,178,134,.4); color: #a9d9c2; }
.flash-err { background: var(--short-soft); border-color: rgba(224,96,96,.4); color: #efb0b0; }

/* ---- Cards & tables ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.card .card-desc { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: start;
  color: var(--faint);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong);
}
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--surface-2); }

/* ---- Chips ------------------------------------------------------------- */

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip-long { color: var(--long); background: var(--long-soft); }
.chip-short { color: var(--short); background: var(--short-soft); }
.chip-pending { color: var(--gold); border-color: rgba(217,169,47,.45); }
.chip-active { color: #131310; background: var(--gold); }
.chip-closed-win { color: var(--long); background: var(--long-soft); }
.chip-closed-loss { color: var(--short); background: var(--short-soft); }
.chip-closed { color: var(--muted); border-color: var(--line-strong); }
.chip-expired { color: var(--faint); border-color: var(--line); }

.r-pos { color: var(--long); }
.r-neg { color: var(--short); }

/* ---- Buttons & forms ----------------------------------------------------- */

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #131310; font-weight: 600; }
.btn-gold:hover { background: #e6ba45; color: #131310; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }

.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

label.field { display: block; margin-bottom: 14px; }
label.field .lab { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
label.field .help { display: block; color: var(--faint); font-size: 12px; margin-top: 4px; }

input[type='text'], input[type='password'], input[type='number'], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 11px;
  font-family: var(--font-ui);
  font-size: 14px;
}
textarea { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; min-height: 200px; }
input::placeholder { color: var(--faint); }

.secret-state { font-size: 11.5px; margin-inline-start: 8px; }
.secret-state.on { color: var(--long); }
.secret-state.off { color: var(--faint); }

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle .track {
  width: 38px; height: 21px; border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  transition: background 120ms ease;
  flex-shrink: 0;
}
.toggle .track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--muted);
  transition: transform 120ms ease, background 120ms ease;
}
.toggle input:checked + .track { background: var(--gold); }
.toggle input:checked + .track::after { transform: translateX(17px); background: #131310; }
.toggle input:focus-visible + .track { outline: 2px solid var(--gold); outline-offset: 2px; }

.inline-form { display: inline; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- Stat tiles ----------------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile .t-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.tile .t-value { font-family: var(--font-mono); font-size: 26px; font-weight: 500; line-height: 1.1; }
.tile .t-note { color: var(--faint); font-size: 11px; margin-top: 6px; }

/* ---- Trade detail ----------------------------------------------------------- */

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }

.report-block {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.9;
  padding: 4px 2px;
}
.report-block[dir='rtl'] { font-size: 15px; }
.report-divider { border: none; border-top: 1px dashed var(--line-strong); margin: 16px 0; }

/* Price ladder — SL/entry/TPs plotted proportionally to real distances */
.ladder { position: relative; height: 300px; margin: 10px 6px 10px 10px; }
.ladder .rail { position: absolute; inset-inline-start: 7px; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.lvl { position: absolute; inset-inline-start: 0; display: flex; align-items: center; gap: 10px; transform: translateY(-50%); width: 100%; }
.lvl .dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid; background: var(--surface); flex-shrink: 0; }
.lvl.tp .dot { border-color: var(--long); }
.lvl.entry .dot { border-color: var(--gold); background: var(--gold); }
.lvl.sl .dot { border-color: var(--short); }
.lvl .lvl-lab { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; width: 44px; }
.lvl.tp .lvl-lab { color: var(--long); }
.lvl.entry .lvl-lab { color: var(--gold); }
.lvl.sl .lvl-lab { color: var(--short); }
.lvl .lvl-price { font-family: var(--font-mono); font-size: 13px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }

.crit { margin-bottom: 12px; }
.crit .crit-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.crit .bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.crit .bar > span { display: block; height: 100%; background: var(--gold); }
.crit .crit-note { color: var(--faint); font-size: 12px; margin-top: 3px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border-bottom: none; }
.timeline .tl-time { font-family: var(--font-mono); color: var(--faint); font-size: 12px; white-space: nowrap; }

/* ---- Settings ------------------------------------------------------------------ */

.copyblock {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  margin: 6px 0 14px;
  position: relative;
}
.copy-wrap { position: relative; }
.copy-wrap .btn-copy { position: absolute; top: 12px; inset-inline-end: 8px; }

/* ---- Auth pages ------------------------------------------------------------------- */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 380px; max-width: 100%; }
.auth-card .brand { justify-content: center; margin-bottom: 22px; }

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

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 14px 18px; gap: 18px; }
  .sidebar .nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .main { padding: 20px 16px 48px; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Language switch & RTL refinements ---------------------------------- */

.lang-switch { display: flex; gap: 8px; align-items: center; color: var(--faint); font-size: 13px; }
.lang-switch a { color: var(--muted); }
.lang-switch a:hover { color: var(--gold); }
.lang-switch a.active { color: var(--gold); font-weight: 600; }

.save-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 14px 0;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  z-index: 5;
}

/* Code/URLs stay left-to-right whatever the UI language */
.copyblock { direction: ltr; text-align: left; }

/* Numerals & timestamps render LTR inside RTL text */
[dir='rtl'] .num,
[dir='rtl'] .tl-time { direction: ltr; unicode-bidi: isolate; }

/* Letter-spacing breaks Arabic letter joining — disable it in RTL */
[dir='rtl'] .eyebrow,
[dir='rtl'] .chip,
[dir='rtl'] table.data th,
[dir='rtl'] .lvl .lvl-lab { letter-spacing: 0; }

/* Toggle knob follows the reading direction */
.toggle .track::after { left: auto; inset-inline-start: 3px; }
[dir='rtl'] .toggle input:checked + .track::after { transform: translateX(-17px); }

/* El Messiri sits a touch small — give Arabic UI a little more air */
html[lang='ar'] body { font-size: 15.5px; line-height: 1.7; }
