/* ==========================================================
   Vapih FX — design system (base). Views add their own CSS
   files in /assets/css/*.css using ONLY these tokens.
   ========================================================== */

/* ---------- 1. tokens: scale (theme-independent) ---------- */
:root {
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  /* spacing scale (4px base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;
  --gap: 16px;
  --card-pad: 18px;
  --kpi-pad: 14px 16px;

  /* type scale */
  --fs-2xs: 10.5px; --fs-xs: 11.5px; --fs-sm: 12.5px; --fs: 13.5px; --fs-md: 14.5px;
  --fs-lg: 17px; --fs-xl: 20px; --fs-kpi: 22px; --fs-hero: 26px;

  /* radii */
  --r-xs: 6px; --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;

  /* controls */
  --h-ctl: 38px; --h-ctl-sm: 30px; --h-ctl-xs: 24px; --h-input: 40px;

  --side-w: 232px;
  --top-h: 66px;
  --nav-h: 62px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: .15s; --t: .25s;
}

/* ---------- 2. tokens: dark (also the no-attribute fallback) ---------- */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #080b11;
  --bg-2: #0b0f17;
  --panel: #10151f;
  --panel-2: #151b28;
  --panel-3: #1b2232;
  --line: #1e2636;
  --line-2: #2a3448;
  --text: #e8edf6;
  --text-2: #b7c1d3;
  --muted: #8592aa;          /* AA on --panel / --panel-2 */
  --dim: #67738c;            /* decorative / large text only */
  --accent: #6d8bff;
  --accent-2: #8f7bff;
  --accent-strong: #5068ea;  /* solid fill behind --on-accent */
  --accent-bg: rgba(109, 139, 255, .13);
  --accent-line: rgba(109, 139, 255, .45);
  --up: #19d18d;
  --up-strong: #19d18d;
  --up-bg: rgba(25, 209, 141, .12);
  --down: #ff5468;
  --down-strong: #e23a52;
  --down-bg: rgba(255, 84, 104, .12);
  --warn: #ffb547;
  --warn-bg: rgba(255, 181, 71, .13);
  --info: #3fc3ff;
  --info-bg: rgba(63, 195, 255, .12);
  --on-accent: #ffffff;
  --on-up: #03140d;
  --on-down: #ffffff;
  --knob: #ffffff;
  --overlay: rgba(3, 5, 9, .62);
  --shadow: 0 18px 50px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .3);
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, .025);
  --shadow-hover: 0 10px 30px -14px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .04);
  --glow-accent: 0 6px 22px rgba(109, 139, 255, .35);
  --glow-up: rgba(25, 209, 141, .55);
  --glass: rgba(14, 18, 27, .74);
  --grid: rgba(255, 255, 255, .04);
  --hover: rgba(255, 255, 255, .035);
  --focus: rgba(109, 139, 255, .55);
  --sheen: rgba(255, 255, 255, .05);
  --hero-1: rgba(109, 139, 255, .16);
  --hero-2: rgba(25, 209, 141, .10);
  --hero-3: rgba(143, 123, 255, .14);
  --edge-1: rgba(109, 139, 255, .38);
  --edge-2: rgba(25, 209, 141, .26);
  /* chart palette (for chart.js; mirrors semantic tokens) */
  --chart-up: var(--up);
  --chart-down: var(--down);
  --chart-grid: var(--grid);
  --chart-text: var(--text-2);
  --chart-cross: rgba(133, 146, 170, .55);
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f8;
  --bg-2: #eceff5;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --panel-3: #edf0f6;
  --line: #e2e6ee;
  --line-2: #d0d7e3;
  --text: #0f1626;
  --text-2: #344058;
  --muted: #5b6880;          /* ≥ 4.5:1 on white and --panel-2 */
  --dim: #76829a;
  --accent: #3d5ef0;
  --accent-2: #6d4fe8;
  --accent-strong: #3d5ef0;
  --accent-bg: rgba(61, 94, 240, .09);
  --accent-line: rgba(61, 94, 240, .4);
  --up: #06875c;             /* AA text on white */
  --up-strong: #06875c;
  --up-bg: rgba(6, 135, 92, .09);
  --down: #d6293f;
  --down-strong: #d6293f;
  --down-bg: rgba(214, 41, 63, .08);
  --warn: #a86400;
  --warn-bg: rgba(217, 138, 0, .11);
  --info: #0877b3;
  --info-bg: rgba(8, 119, 179, .09);
  --on-accent: #ffffff;
  --on-up: #ffffff;
  --on-down: #ffffff;
  --knob: #ffffff;
  --overlay: rgba(15, 22, 38, .38);
  --shadow: 0 20px 50px -16px rgba(16, 24, 40, .22), 0 2px 6px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 4px rgba(16, 24, 40, .08);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-hover: 0 12px 28px -14px rgba(16, 24, 40, .22), 0 1px 2px rgba(16, 24, 40, .05);
  --glow-accent: 0 6px 18px rgba(61, 94, 240, .28);
  --glow-up: rgba(6, 135, 92, .45);
  --glass: rgba(255, 255, 255, .8);
  --grid: rgba(15, 22, 38, .055);
  --hover: rgba(15, 22, 38, .03);
  --focus: rgba(61, 94, 240, .5);
  --sheen: rgba(255, 255, 255, .7);
  --hero-1: rgba(61, 94, 240, .10);
  --hero-2: rgba(6, 135, 92, .07);
  --hero-3: rgba(109, 79, 232, .08);
  --edge-1: rgba(61, 94, 240, .3);
  --edge-2: rgba(6, 135, 92, .2);
  --chart-cross: rgba(91, 104, 128, .5);
}
/* only used if no data-theme is present at all (JS normally sets it) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f2f4f8; --bg-2: #eceff5; --panel: #ffffff; --panel-2: #f6f8fb; --panel-3: #edf0f6;
    --line: #e2e6ee; --line-2: #d0d7e3; --text: #0f1626; --text-2: #344058; --muted: #5b6880; --dim: #76829a;
    --accent: #3d5ef0; --accent-strong: #3d5ef0; --accent-bg: rgba(61, 94, 240, .09);
    --up: #06875c; --up-strong: #06875c; --up-bg: rgba(6, 135, 92, .09);
    --down: #d6293f; --down-strong: #d6293f; --down-bg: rgba(214, 41, 63, .08);
    --warn: #a86400; --warn-bg: rgba(217, 138, 0, .11); --info: #0877b3; --on-up: #ffffff;
    --glass: rgba(255, 255, 255, .8); --grid: rgba(15, 22, 38, .055); --hover: rgba(15, 22, 38, .03);
    --shadow-card: 0 1px 2px rgba(16, 24, 40, .04); --overlay: rgba(15, 22, 38, .38);
  }
}

/* ---------- 3. reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.005em; }
p { margin: 0; }
img, svg { max-width: 100%; }
::selection { background: var(--accent-bg); color: var(--text); }
::placeholder { color: var(--dim); opacity: 1; }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--dim); }
::-webkit-scrollbar-track { background: transparent; }

/* focus: keyboard-only ring everywhere */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-xs); }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible, .nav button:focus-visible,
.search-trigger:focus-visible, .chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.input:focus-visible, .field input:focus-visible, .field select:focus-visible, select.input:focus-visible { outline: none; }

.ic, svg.ic { width: 18px; height: 18px; flex: none; }
button svg, .nav svg { width: 20px; height: 20px; flex: none; }

/* numbers: always LTR, tabular */
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums slashed-zero; font-feature-settings: 'tnum' 1, 'zero' 1; direction: ltr; unicode-bidi: isolate; letter-spacing: -.02em; }
.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.warn { color: var(--warn) !important; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.ltr { direction: ltr; unicode-bidi: isolate; }
.truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- 4. layout shell ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  background: var(--bg-2);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; padding: 4px 8px; direction: ltr; justify-content: flex-end; letter-spacing: -.01em; }
.brand b { background: linear-gradient(90deg, var(--accent), var(--up)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--up)); color: var(--on-accent); box-shadow: var(--glow-accent); }
.brand-mark svg { width: 18px; height: 18px; }
.brand.big { font-size: 26px; justify-content: center; }
.brand.big .brand-mark { width: 46px; height: 46px; border-radius: 14px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 10px 12px; border: 0; border-radius: var(--r);
  background: transparent; color: var(--muted); font-weight: 500; text-align: start; position: relative;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.active { background: var(--accent-bg); color: var(--text); }
.nav button.active::before { content: ''; position: absolute; inset-inline-start: -14px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 10px var(--accent-line); }
.nav button.active svg { color: var(--accent); }
.badge { margin-inline-start: auto; font-style: normal; font-family: var(--mono); font-size: 11px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent-strong); color: var(--on-accent); display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.badge:empty { display: none; }
.side-foot { margin-top: auto; display: flex; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; overflow-x: clip; }
.top {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; gap: 16px; padding: 0 24px; min-width: 0;
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.top-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-title h1 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.env-pill { font: 600 10px/1 var(--mono); letter-spacing: .08em; padding: 5px 8px; border-radius: var(--r-xs); background: var(--warn-bg); color: var(--warn); flex: none; }
.env-pill.live { background: var(--down-bg); color: var(--down); }
.env-pill.mock { background: var(--accent-bg); color: var(--accent); }
.search-trigger {
  flex: 1; max-width: 420px; min-width: 0; margin-inline-start: auto; display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  transition: border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.search-trigger:hover { border-color: var(--line-2); color: var(--text-2); box-shadow: var(--shadow-card); }
.search-trigger span { flex: 1; text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd { font: 500 11px var(--mono); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; background: var(--panel-2); color: var(--muted); direction: ltr; unicode-bidi: isolate; }
.top-stats { display: flex; align-items: center; gap: 20px; min-width: 0; }
.tstat { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.tstat span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.tstat b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); padding: 6px 10px; border-radius: var(--r-pill); background: var(--panel); border: 1px solid var(--line); white-space: nowrap; flex: none; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.conn.live i { background: var(--up); box-shadow: 0 0 0 0 var(--glow-up); animation: pulse 2s infinite; }
.conn.poll i { background: var(--warn); }
.conn.mock i { background: var(--accent); }
.conn.connecting i { background: var(--info); animation: blink 1s infinite; }
.conn.off i { background: var(--down); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--glow-up); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes blink { 50% { opacity: .3; } }

.view { display: none; padding: 22px 24px 40px; min-width: 0; animation: viewIn .35s var(--ease-out); }
.view.active { display: block; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 5. grid helpers ---------- */
.grid { display: grid; gap: var(--gap); }
.grid > * { min-width: 0; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: var(--gap); }

/* ---------- 6. card ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--card-pad); min-width: 0; position: relative;
  box-shadow: var(--shadow-card);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), translate var(--t) var(--ease);
}
.card:hover { border-color: var(--line-2); }
.card.kpi:hover { box-shadow: var(--shadow-hover); translate: 0 -2px; }
.card-h { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; margin-bottom: 14px; min-height: 28px; min-width: 0; }
.card-h h3 { font-size: var(--fs-md); font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-h h3 > span { overflow: hidden; text-overflow: ellipsis; }
.card-h h3 .ic { color: var(--accent); width: 17px; height: 17px; }
.card-h .sub { font-size: 12px; color: var(--muted); min-width: 0; }
.card-h .actions { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.card.flush { padding: 0; }
.card.flush .card-h { padding: 16px var(--card-pad) 0; }
.card.glow::after { content: ''; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; background: linear-gradient(135deg, var(--edge-1), transparent 40%, transparent 60%, var(--edge-2)); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; padding: 1px; }

/* ---------- 7. KPI ---------- */
.kpi { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card.kpi { padding: var(--kpi-pad); overflow: hidden; }
.card.kpi::before { content: ''; position: absolute; inset: 0 0 auto; height: 1px; background: linear-gradient(90deg, transparent, var(--sheen), transparent); pointer-events: none; }
.kpi-l { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-v { font: 600 var(--fs-kpi)/1.15 var(--mono); letter-spacing: -.03em; direction: ltr; text-align: right; unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: var(--r-xs); }
.kpi-s { font-size: 12px; color: var(--muted); min-width: 0; }
.meter { height: 6px; border-radius: 6px; background: var(--panel-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .5s var(--ease); }
.meter.up > i { background: var(--up); } .meter.down > i { background: var(--down); } .meter.warn > i { background: var(--warn); }

/* ---------- 8. buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h-ctl); padding: 0 16px; border-radius: var(--r); border: 1px solid var(--line);
  font-weight: 600; font-size: var(--fs); white-space: nowrap; line-height: 1;
  transition: transform .08s, filter var(--t-fast), background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
  background: var(--panel-2); color: var(--text);
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: var(--line-2); background: var(--panel-3); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.btn-primary { background: var(--accent-strong); color: var(--on-accent); border-color: transparent; box-shadow: 0 1px 0 var(--sheen) inset; }
.btn-primary:hover { background: var(--accent-strong); border-color: transparent; filter: brightness(1.08); box-shadow: var(--glow-accent); }
.btn-up { background: var(--up-strong); color: var(--on-up); border-color: transparent; }
.btn-down, .btn-danger { background: var(--down-strong); color: var(--on-down); border-color: transparent; }
.btn-up:hover, .btn-down:hover, .btn-danger:hover { border-color: transparent; filter: brightness(1.08); }
.btn-up:hover { background: var(--up-strong); } .btn-down:hover, .btn-danger:hover { background: var(--down-strong); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: var(--h-ctl-sm); padding: 0 11px; font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 6px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-xs { height: var(--h-ctl-xs); padding: 0 8px; font-size: var(--fs-xs); border-radius: var(--r-xs); gap: 4px; }
.btn-xs svg { width: 13px; height: 13px; }
.btn-block { width: 100%; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--text); border-inline-end-color: transparent; border-bottom-color: transparent; animation: spin .7s linear infinite; }
.btn-primary.busy::after { border-color: var(--on-accent) var(--on-accent) transparent transparent; }
.btn-up.busy::after { border-color: var(--on-up) var(--on-up) transparent transparent; }
.btn-down.busy::after, .btn-danger.busy::after { border-color: var(--on-down) var(--on-down) transparent transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); padding: 0; transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast); }
.icon-btn:hover { color: var(--text); border-color: var(--line-2); background: var(--panel-2); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.sm { width: 28px; height: 28px; border-radius: var(--r-xs); }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.active { color: var(--warn); }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-sm); background: var(--panel-2); border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; padding: 5px 10px; min-height: 26px; border-radius: var(--r-xs); font-size: var(--fs-sm); color: var(--muted); font-weight: 500; white-space: nowrap; transition: color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast); flex: none; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.active { background: var(--panel-3); box-shadow: inset 0 1px 0 var(--sheen), 0 1px 3px rgba(0, 0, 0, .35); }

/* chips / tags */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.45; background: var(--panel-3); color: var(--text-2); white-space: nowrap; max-width: 100%; }
.chip.up { background: var(--up-bg); } .chip.down { background: var(--down-bg); } .chip.warn { background: var(--warn-bg); } .chip.accent { background: var(--accent-bg); color: var(--accent); }
.chip svg { width: 12px; height: 12px; }
button.chip { border: 1px solid transparent; cursor: pointer; min-height: 28px; }
.dir { font: 700 10.5px/1 var(--mono); padding: 4px 7px; border-radius: 5px; letter-spacing: .04em; display: inline-block; }
.dir.BUY { background: var(--up-bg); color: var(--up); }
.dir.SELL { background: var(--down-bg); color: var(--down); }

/* ---------- 9. forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, .field input, .field select, select.input, textarea.input {
  height: var(--h-input); padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel-2);
  outline: none; transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast); width: 100%; min-width: 0;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:hover, .field input:hover, .field select:hover { border-color: var(--line-2); }
.input:focus, .field input:focus, .field select:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); background: var(--panel); }
.input:disabled, .field input:disabled { opacity: .6; cursor: not-allowed; }
.field input[type="checkbox"], .field input[type="radio"], .field input[type="range"] { height: auto; width: auto; padding: 0; box-shadow: none; }
input.num, .input.num { text-align: left; }
select.input, .field select { padding-inline-end: 28px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; min-height: 24px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin: 0; }
.toggle { position: relative; width: 36px; height: 20px; flex: none; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle i { position: absolute; inset: 0; border-radius: 20px; background: var(--line-2); transition: background .2s; cursor: pointer; }
.toggle i::after { content: ''; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s var(--ease); }
.toggle input:checked + i { background: var(--accent-strong); }
.toggle input:checked + i::after { transform: translateX(-16px); }
[dir="ltr"] .toggle input:checked + i::after { transform: translateX(16px); }
.toggle input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); overflow: hidden; height: var(--h-input); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.stepper button { width: 38px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; }
.stepper button:hover { background: var(--panel-3); color: var(--text); }
.stepper button svg { width: 16px; height: 16px; }
.stepper input { flex: 1; min-width: 0; border: 0; background: transparent; text-align: center; outline: none; font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; direction: ltr; }

/* ---------- 10. tables ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
.t th { text-align: start; font-weight: 500; font-size: var(--fs-xs); color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); box-shadow: inset 0 -1px 0 var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1; background: var(--panel); }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background .12s; }
.t tbody tr:hover { background: var(--hover); }
/* numbers: LTR glyphs, right-aligned in the RTL table */
.t .num, .t th.num, .t td.num { text-align: right; }
.t .clickable { cursor: pointer; }
.mkt-name { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.mkt-name b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28ch; }
.mkt-name small { font-size: 11px; color: var(--dim); direction: ltr; unicode-bidi: isolate; text-align: right; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* price flash — smooth tinted fade */
.flash-up, .flash-down { border-radius: var(--r-xs); }
.flash-up { animation: fUp .9s var(--ease-out); }
.flash-down { animation: fDown .9s var(--ease-out); }
@keyframes fUp { 0% { background-color: var(--up-bg); color: var(--up); box-shadow: 0 0 0 2px var(--up-bg); } 100% { background-color: transparent; box-shadow: 0 0 0 2px transparent; } }
@keyframes fDown { 0% { background-color: var(--down-bg); color: var(--down); box-shadow: 0 0 0 2px var(--down-bg); } 100% { background-color: transparent; box-shadow: 0 0 0 2px transparent; } }

/* ---------- 11. empty / skeleton ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 34px 16px; color: var(--muted); text-align: center; }
.empty svg { width: 34px; height: 34px; color: var(--dim); }
.empty b, .empty h3, .empty h4 { color: var(--text-2); }
.skel { display: flex; flex-direction: column; gap: 10px; }
.skel i { display: block; height: 14px; border-radius: var(--r-xs); background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-3) 40%, var(--panel-2) 80%); background-size: 220% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.skel i:nth-child(2n) { width: 75%; }
.skel i:nth-child(3n) { width: 55%; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

/* ---------- 12. modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: var(--overlay); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); opacity: 0; transition: opacity .2s; }
.modal-wrap.in { opacity: 1; }
.modal { width: min(460px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--shadow); transform: translateY(10px) scale(.98); transition: transform var(--t) var(--ease-out); }
.modal.wide { width: min(760px, 100%); }
.modal-wrap.in .modal { transform: none; }
.modal-h { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.modal-h h3 { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-x { flex: none; }
.modal-b { padding: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.confirm p { color: var(--text-2); line-height: 1.7; }
.confirm-details { margin-top: 14px; padding: 12px 14px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); display: grid; gap: 8px; font-size: 13px; }
.kv { display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
.kv > span:first-child { color: var(--muted); }
.kv > :last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* actions.js ticket: readable text on solid active buttons in both themes */
.modal .ac-pxbtn.sell.active { background: var(--down-strong); border-color: var(--down-strong); color: var(--on-down); }
.modal .ac-pxbtn.buy.active { background: var(--up-strong); border-color: var(--up-strong); color: var(--on-up); }
.modal .ac-pxbtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- 13. toasts ---------- */
.toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 36px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line-2); box-shadow: var(--shadow); transform: translateY(12px); opacity: 0; transition: transform var(--t) var(--ease-out), opacity var(--t); border-inline-start: 3px solid var(--accent); }
.toast.in { transform: none; opacity: 1; }
.toast > svg { color: var(--accent); margin-top: 2px; }
.toast > div { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.toast b { display: block; margin-bottom: 2px; }
.toast p { color: var(--text-2); }
.toast-x { border: 0; background: none; color: var(--dim); padding: 4px; margin: -4px; border-radius: var(--r-xs); }
.toast-x:hover { color: var(--text); }
.toast-x svg { width: 14px; height: 14px; }
.toast-success, .toast-up { border-inline-start-color: var(--up); } .toast-success > svg, .toast-up > svg { color: var(--up); }
.toast-error, .toast-down { border-inline-start-color: var(--down); } .toast-error > svg, .toast-down > svg { color: var(--down); }
.toast-warn { border-inline-start-color: var(--warn); } .toast-warn > svg { color: var(--warn); }

/* ---------- 14. palette ---------- */
.palette { position: fixed; inset: 0; z-index: 150; background: var(--overlay); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.palette-box { width: min(620px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--shadow); overflow: hidden; animation: viewIn .2s var(--ease-out); }
.palette-in { display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.palette-in svg { color: var(--muted); }
.palette-in input { flex: 1; min-width: 0; height: 58px; border: 0; background: transparent; outline: none; font-size: 16px; }
.palette-list { max-height: 50vh; overflow: auto; overscroll-behavior: contain; padding: 8px; }
.palette-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }

/* ---------- 15. login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; background: var(--bg); }
.login-bg { position: absolute; inset: -20%; background:
  radial-gradient(600px 400px at 20% 30%, var(--hero-1), transparent 60%),
  radial-gradient(500px 400px at 80% 70%, var(--hero-2), transparent 60%),
  radial-gradient(400px 300px at 60% 10%, var(--hero-3), transparent 60%);
  filter: blur(20px); animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate(4%, -3%) rotate(6deg); } }
.login-card { position: relative; width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 32px 28px; border-radius: var(--r-xl); background: var(--glass); border: 1px solid var(--line-2); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: var(--shadow); text-align: center; }
.login-card .field { text-align: start; }
.login-card .btn { height: 44px; }
.err { color: var(--down); font-size: 13px; min-height: 18px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.fatal { max-width: 520px; margin: 15vh auto; padding: 24px; text-align: center; }
.fatal p { color: var(--muted); margin-top: 10px; }

/* ---------- 16. responsive ---------- */
/* tablet */
@media (max-width: 1280px) {
  .g-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top { gap: 12px; padding: 0 20px; }
  .top-stats { gap: 14px; }
  .search-trigger { max-width: 320px; }
  .view { padding: 20px 20px 36px; }
}
@media (max-width: 1100px) {
  :root { --side-w: 76px; }
  .side { padding: 18px 10px; }
  .nav button span, .brand-txt { display: none; }
  .nav button { justify-content: center; min-height: 46px; }
  .nav button.active::before { inset-inline-start: -10px; }
  .badge { position: absolute; top: 4px; inset-inline-end: 6px; }
  .side-foot { flex-direction: column; align-items: center; }
  .brand { justify-content: center; padding: 4px 0; }
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-trigger kbd { display: none; }
}
@media (max-width: 900px) and (min-width: 761px) {
  .search-trigger { max-width: 44px; padding: 0; justify-content: center; flex: none; }
  .search-trigger span { display: none; }
}
/* mobile */
@media (max-width: 760px) {
  :root { --gap: 12px; --top-h: 56px; --card-pad: 14px; --kpi-pad: 12px; --fs-kpi: 18px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; top: auto; bottom: 0; inset-inline: 0; height: auto; z-index: 40; flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); padding-inline: max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-right)); border: 0; border-top: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4); }
  .side .brand, .side-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; gap: 2px; }
  .nav button { flex-direction: column; gap: 3px; padding: 6px 2px; min-height: 52px; font-size: 10.5px; flex: 1; min-width: 0; justify-content: center; border-radius: var(--r); }
  .nav button span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .nav button svg { width: 22px; height: 22px; }
  .nav button.active { background: transparent; color: var(--accent); }
  .nav button.active svg { filter: drop-shadow(0 2px 6px var(--accent-line)); }
  .nav button.active::before { display: block; inset-inline-start: 30%; inset-inline-end: 30%; top: -4px; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .badge { top: 3px; inset-inline-end: calc(50% - 22px); position: absolute; }
  .main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .top { padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); gap: 10px; }
  .search-trigger { width: 40px; max-width: 40px; padding: 0; justify-content: center; flex: none; margin-inline-start: auto; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .top-title h1 { font-size: 16px; }
  .env-pill, .hide-sm, .conn span { display: none; }
  .conn { padding: 8px; }
  .top-stats { gap: 12px; }
  .tstat b { font-size: 13.5px; }
  .tstat span { font-size: 10.5px; }
  .view { padding: 14px 16px 28px; }
  .g-2, .g-3, .g-4 { grid-template-columns: minmax(0, 1fr); }
  .g-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2, .span-3 { grid-column: auto; }
  .card { border-radius: var(--r); }
  .card.kpi:hover { translate: none; }
  .mkt-name b { max-width: 18ch; }
  .modal-wrap { place-items: end center; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); transform: translateY(24px); }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; margin-inline: -18px; padding-inline: 18px; }
  .modal-actions .btn { flex: 1; }
  .toasts { bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); inset-inline: 12px; width: auto; }
  .palette { padding-top: 8vh; }
}
@media (max-width: 380px) {
  .top-stats .tstat:nth-child(2) { display: none; }
}
/* touch: comfortable tap targets */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-sm { height: 36px; min-height: 36px; }
  .btn-xs { height: 32px; min-height: 32px; padding: 0 10px; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn.sm { width: 36px; height: 36px; }
  .seg button { min-height: 34px; padding-inline: 12px; }
  .check { min-height: 40px; }
  .check input { width: 20px; height: 20px; }
  .stepper button { width: 44px; }
  .toast-x { padding: 10px; margin: -10px; }
  .card:hover { border-color: var(--line); }
  .card.kpi:hover { translate: none; box-shadow: var(--shadow-card); }
}

/* ---------- 17. motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .flash-up, .flash-down, .ac-up, .ac-dn { animation: none !important; }
  .skel i { animation: none !important; background: var(--panel-3); }
  .login-bg { animation: none !important; }
  .card.kpi:hover { translate: none; }
  /* keep loading spinners meaningful, just slower */
  .btn.busy::after, .pl-spin, .mk-spin { animation-duration: 1.4s !important; animation-iteration-count: infinite !important; }
}

/* ---------- 18. print ---------- */
@media print {
  :root, [data-theme] {
    --bg: #fff; --bg-2: #fff; --panel: #fff; --panel-2: #fff; --panel-3: #f2f2f2;
    --line: #d9d9d9; --line-2: #bfbfbf; --text: #000; --text-2: #222; --muted: #444; --dim: #666;
    --shadow: none; --shadow-sm: none; --shadow-card: none; --glass: #fff;
  }
  body { background: #fff; color: #000; overflow: visible; }
  .side, .top .search-trigger, .conn, .toasts, .palette, .modal-wrap, .login,
  .btn, .icon-btn, .seg, .card-h .actions { display: none !important; }
  .app { display: block; }
  .main { overflow: visible; padding: 0; }
  .top { position: static; backdrop-filter: none; height: auto; padding: 0 0 12px; border-bottom: 1px solid #ccc; }
  .view { display: none !important; padding: 12px 0; animation: none; }
  .view.active { display: block !important; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  .table-wrap, .ps-tw, .mk-tw, .ov-pos-wrap { max-height: none !important; overflow: visible !important; }
  .t th { position: static; }
  * { animation: none !important; transition: none !important; }
}
