* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Default = Liquid Market (overridable by [data-theme] on <body>) */
  --ios-accent:       #ffb800;
  --ios-positive:     #00ed75;
  --ios-negative:     #ff1745;
  --ios-warning:      #ffb800;
  --ios-text:         #ffffff;
  --ios-text-2:       rgba(255,255,255,0.62);
  --ios-text-3:       rgba(255,255,255,0.55);
  --ios-text-4:       rgba(255,255,255,0.38);
  --ios-bg:           #020203;
  --ios-card-bg:      #070a0f;
  --ios-card-fill:    #111827;
  --ios-card-stroke:  rgba(148, 163, 184, 0.20);
  /* Bar palette (matches iOS remainingBarColor + tray app) */
  --bar-100: #4ade80;
  --bar-95:  #6ee84f;
  --bar-90:  #b5e853;
  --bar-80:  #ffb020;
  --bar-70:  #ff7a18;
  --bar-low: #ff304d;
  --bar-inactive: #777777;
}

body[data-theme="electric"] {
  --ios-accent:       #b8ff3d;
  --ios-positive:     #06f6c5;
  --ios-negative:     #ff4d6d;
  --ios-warning:      #b8ff3d;
  --ios-text:         #f2fffb;
  --ios-text-2:       rgba(242, 255, 251, 0.66);
  --ios-text-3:       rgba(242, 255, 251, 0.52);
  --ios-text-4:       rgba(242, 255, 251, 0.38);
  --ios-bg:           #010304;
  --ios-card-bg:      #041016;
  --ios-card-fill:    #0b1f2a;
  --ios-card-stroke:  rgba(6, 246, 197, 0.22);
}

body[data-theme="cobalt"] {
  --ios-accent:       #7c3aed;
  --ios-positive:     #22d3ee;
  --ios-negative:     #f472b6;
  --ios-warning:      #fbbf24;
  --ios-text:         #f4edff;
  --ios-text-2:       rgba(244, 237, 255, 0.66);
  --ios-text-3:       rgba(244, 237, 255, 0.52);
  --ios-text-4:       rgba(244, 237, 255, 0.38);
  --ios-bg:           #020203;
  --ios-card-bg:      #090616;
  --ios-card-fill:    #1b1432;
  --ios-card-stroke:  rgba(124, 58, 237, 0.24);
}

body[data-theme="coral"] {
  --ios-accent:       #ff7a18;
  --ios-positive:     #ffd166;
  --ios-negative:     #ff4d6d;
  --ios-warning:      #ffd166;
  --ios-text:         #fff7ed;
  --ios-text-2:       rgba(255, 247, 237, 0.66);
  --ios-text-3:       rgba(255, 247, 237, 0.52);
  --ios-text-4:       rgba(255, 247, 237, 0.38);
  --ios-bg:           #020203;
  --ios-card-bg:      #0f0608;
  --ios-card-fill:    #271317;
  --ios-card-stroke:  rgba(255, 122, 24, 0.24);
}

body[data-theme="spearmint"] {
  --ios-accent:       #7ddfca;
  --ios-positive:     #a7f3d0;
  --ios-negative:     #fb7185;
  --ios-warning:      #f5c542;
  --ios-text:         #f0fff9;
  --ios-text-2:       rgba(240, 255, 249, 0.66);
  --ios-text-3:       rgba(240, 255, 249, 0.52);
  --ios-text-4:       rgba(240, 255, 249, 0.38);
  --ios-bg:           #020302;
  --ios-card-bg:      #07110f;
  --ios-card-fill:    #15352e;
  --ios-card-stroke:  rgba(125, 223, 202, 0.22);
}

body[data-theme="cloud"] {
  /* พื้นสว่าง: accent ฟ้าเข้มขึ้น + positive เป็นเขียวเข้ม (เดิม #0ea5e9 ฟ้าอ่อน
     ซ้ำ accent คอนทราสต์ ~2.9:1 อ่านยาก) → เขียว #047857 ~5.9:1 อ่านชัด */
  --ios-accent:       #0284c7;
  --ios-positive:     #047857;
  --ios-negative:     #e11d48;
  --ios-warning:      #f59e0b;
  --ios-text:         #0f172a;
  --ios-text-2:       rgba(15, 23, 42, 0.68);
  --ios-text-3:       rgba(15, 23, 42, 0.54);
  --ios-text-4:       rgba(15, 23, 42, 0.40);
  --ios-bg:           #f8fafc;
  --ios-card-bg:      #ffffff;
  --ios-card-fill:    #eef2f7;
  --ios-card-stroke:  #cbd5e1;
}

body[data-theme="cloud"] {
  color-scheme: light;
}

body[data-theme="cloud"] .row .value,
body[data-theme="cloud"] .history-table td,
body[data-theme="cloud"] .detail-status-value,
body[data-theme="cloud"] .config-section h3,
body[data-theme="cloud"] .config-header h2,
body[data-theme="cloud"] .theme-name,
body[data-theme="cloud"] .trash-row-id,
body[data-theme="cloud"] .currency-row-id,
body[data-theme="cloud"] .account-main,
body[data-theme="cloud"] .money-primary,
body[data-theme="cloud"] .hero-stat .val,
body[data-theme="cloud"] .status-preview strong,
body[data-theme="cloud"] .config-note strong {
  color: var(--ios-text);
}

body[data-theme="cloud"] .config-note,
body[data-theme="cloud"] .status-preview span,
body[data-theme="cloud"] .trash-note,
body[data-theme="cloud"] .trash-hint,
body[data-theme="cloud"] .broker,
body[data-theme="cloud"] .row .label,
body[data-theme="cloud"] .account-sub-meta {
  color: var(--ios-text-2);
}

body[data-theme="cloud"] .sort-select,
body[data-theme="cloud"] .config-input,
body[data-theme="cloud"] .login-card input,
body[data-theme="cloud"] input[type="number"],
body[data-theme="cloud"] input[type="text"],
body[data-theme="cloud"] input[type="password"] {
  background: #ffffff;
  border-color: #cbd5e1;
  color: var(--ios-text);
}

body[data-theme="cloud"] .hero-divider,
body[data-theme="cloud"] .card-header,
body[data-theme="cloud"] .section-divider {
  border-color: rgba(15, 23, 42, 0.14);
}

body[data-theme="cloud"] .hero-divider {
  background: rgba(15, 23, 42, 0.12);
}

body[data-theme="cloud"] .hero-stat,
body[data-theme="cloud"] .detail-section,
body[data-theme="cloud"] .status-preview,
body[data-theme="cloud"] .trash-row,
body[data-theme="cloud"] .theme-option {
  background: rgba(15, 23, 42, 0.04);
}

body[data-theme="cloud"] .close-btn,
body[data-theme="cloud"] .logout-btn,
body[data-theme="cloud"] .icon-btn {
  color: var(--ios-text);
}

/* cloud: พื้นจาง up/down เดิมเป็น neon green (0,237,117) ดูแปลกบนพื้นขาว
   → ปรับเป็นโทนเดียวกับสี positive/negative ใหม่ ให้กลมกลืน */
body[data-theme="cloud"] .hero-pct.up,
body[data-theme="cloud"] .lot-leg.green {
  background: rgba(4, 120, 87, 0.12);
}
body[data-theme="cloud"] .hero-pct.down,
body[data-theme="cloud"] .lot-leg.red {
  background: rgba(225, 29, 72, 0.10);
}
body[data-theme="cloud"] .lot-leg.green { border-color: rgba(4, 120, 87, 0.30); }
body[data-theme="cloud"] .lot-leg.red { border-color: rgba(225, 29, 72, 0.30); }
body[data-theme="cloud"] .hero-card.tone-positive {
  border-color: rgba(4, 120, 87, 0.35);
  background: linear-gradient(135deg, rgba(4, 120, 87, 0.08), rgba(4, 120, 87, 0.02) 60%), var(--ios-card-bg);
}
body[data-theme="cloud"] .hero-card.tone-negative {
  border-color: rgba(225, 29, 72, 0.35);
  background: linear-gradient(135deg, rgba(225, 29, 72, 0.07), rgba(225, 29, 72, 0.02) 60%), var(--ios-card-bg);
}

body[data-theme="burgundy"] {
  --ios-accent:       #f5c542;
  --ios-positive:     #c084fc;
  --ios-negative:     #ff4d6d;
  --ios-warning:      #f5c542;
  --ios-text:         #fff2f6;
  --ios-text-2:       rgba(255, 242, 246, 0.66);
  --ios-text-3:       rgba(255, 242, 246, 0.52);
  --ios-text-4:       rgba(255, 242, 246, 0.38);
  --ios-bg:           #020203;
  --ios-card-bg:      #12070d;
  --ios-card-fill:    #2b1622;
  --ios-card-stroke:  rgba(245, 197, 66, 0.24);
}

body[data-theme="graphite"] {
  --ios-accent:       #e5e7eb;
  --ios-positive:     #94a3b8;
  --ios-negative:     #ef4444;
  --ios-warning:      #ffffff;
  --ios-text:         #ffffff;
  --ios-text-2:       rgba(255, 255, 255, 0.66);
  --ios-text-3:       rgba(255, 255, 255, 0.52);
  --ios-text-4:       rgba(255, 255, 255, 0.38);
  --ios-bg:           #000000;
  --ios-card-bg:      #070707;
  --ios-card-fill:    #111111;
  --ios-card-stroke:  #2a2a2a;
}

body {
  /* Segoe UI Variable on Windows + SF Pro on macOS — both keep small text crisp.
     Tabular nums align numeric columns without forcing a monospaced font. */
  font-family: "Segoe UI Variable Display", "Segoe UI Variable", "Segoe UI",
               -apple-system, "SF Pro Display", "Inter", "Helvetica Neue", Arial, sans-serif;
  background: var(--ios-bg);
  color: var(--ios-text);
  min-height: 100vh;
  padding: 12px;
  font-size: 14px;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-variant-numeric: tabular-nums lining-nums;
}

/* Numeric / tabular content keeps tnum on; reset elsewhere if a child explicitly
   wants proportional digits. Headlines stay light to medium weight (500..600) — at
   small sizes 700+ looks bloomy on Windows. */

.container { max-width: 1400px; margin: 0 auto; }

/* ---------- Portfolio hero card (replaces the Realtime Floating P/L chart) ---------- */
.portfolio-hero {
  margin-bottom: 16px;
}
.portfolio-hero .hero-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--ios-text-2);
}
.portfolio-hero .hero-eyebrow { text-transform: uppercase; }
.portfolio-hero .hero-count   { color: var(--ios-text-3); }

.hero-card {
  box-sizing: border-box;
  padding: clamp(16px, 2.5vw, 22px) clamp(18px, 2.8vw, 26px);
  border-radius: 14px;
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  transition: border-color 250ms ease, background 250ms ease;
}
.hero-card.tone-positive {
  border-color: rgba(0, 237, 117, 0.45);
  background: linear-gradient(135deg, rgba(0, 237, 117, 0.16), rgba(0, 237, 117, 0.04) 60%), var(--ios-card-bg);
}
.hero-card.tone-negative {
  border-color: rgba(255, 23, 69, 0.50);
  background: linear-gradient(135deg, rgba(255, 23, 69, 0.16), rgba(255, 23, 69, 0.04) 60%), var(--ios-card-bg);
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.hero-today { min-width: 0; }
.hero-label {
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--ios-text-3);
  text-transform: uppercase;
}
.hero-value {
  font-size: clamp(34px, 5.6vw, 56px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.5px;
  color: var(--ios-text);
  margin-top: 4px;
  white-space: nowrap;
}
.hero-pct {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px 5px;
  border-radius: 999px;
  font-size: clamp(12px, 1.6vw, 14px);
  font-weight: 600;
  letter-spacing: 0.2px;
}
.hero-pct.up   { color: var(--ios-positive); background: rgba(0, 237, 117, 0.14); }
.hero-pct.down { color: var(--ios-negative); background: rgba(255, 23, 69, 0.14); }

.hero-trend {
  margin: 2px 0 12px;
}
.hero-trend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: clamp(9px, 1.2vw, 11px);
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--ios-text-4);
}
.hero-trend-value {
  color: var(--ios-text-3);
  letter-spacing: 0.1px;
  white-space: nowrap;
}
.hero-trend-value.green { color: var(--ios-positive); }
.hero-trend-value.red   { color: var(--ios-negative); }
.hero-spark-wrap {
  position: relative;
  height: 44px;
  min-width: 0;
}
.hero-sparkline {
  display: block;
  width: 100%;
  height: 44px;
}

.hero-dd-slot { display: flex; }
.hero-dd {
  align-self: flex-start;
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.hero-dd.warn { color: var(--bar-80); background: rgba(255, 176, 32, 0.15); border: 1px solid rgba(255, 176, 32, 0.40); }
.hero-dd.bad  { color: var(--ios-negative); background: rgba(255, 23, 69, 0.15); border: 1px solid rgba(255, 23, 69, 0.40); }
/* PEAKED — ฟื้นแล้วแต่เคยถึงวันนี้ แสดงแบบหรี่ ไม่ใช่สีแดง */
.hero-dd.peaked { color: var(--ios-text-2); background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.14); font-weight: 500; }

/* Active DD alert banner — โชว์บนสุดของ dashboard เฉพาะตอนมีบัญชี "กำลัง" DD */
.alert-banner {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 600;
}
.alert-banner.show { display: flex; }
.alert-banner.critical { background: rgba(255, 23, 69, 0.12); border: 1px solid rgba(255, 23, 69, 0.45); color: var(--ios-negative); }
.alert-banner.warning  { background: rgba(255, 176, 32, 0.12); border: 1px solid rgba(255, 176, 32, 0.42); color: var(--bar-80); }
.alert-banner-label { font-size: 0.9rem; letter-spacing: 0.3px; }
.alert-banner-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.alert-chip {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid;
}
.alert-chip.crit { color: var(--ios-negative); border-color: rgba(255, 23, 69, 0.5); background: rgba(255, 23, 69, 0.10); }
.alert-chip.warn { color: var(--bar-80); border-color: rgba(255, 176, 32, 0.5); background: rgba(255, 176, 32, 0.10); }
.alert-chip:hover { filter: brightness(1.25); }

.hero-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.10);
  margin: 12px 0;
}

.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.hero-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  min-width: 0;
}
.hero-stat .lab {
  font-size: clamp(10px, 1.3vw, 12px);
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--ios-text-3);
}
.hero-stat .val {
  font-size: clamp(15px, 1.9vw, 20px);
  font-weight: 500;
  line-height: 1.1;
  color: var(--ios-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hero-stat .val.green { color: var(--ios-positive); }
.hero-stat .val.red   { color: var(--ios-negative); }
.hero-value.green { color: var(--ios-positive); }
.hero-value.red   { color: var(--ios-negative); }

.hero-updated {
  margin-top: 10px;
  font-size: clamp(10px, 1.3vw, 12px);
  color: var(--ios-text-4);
  letter-spacing: 0.3px;
}

@media (max-width: 700px) {
  .hero-stats { grid-template-columns: 1fr; gap: 6px; }
  .hero-top { flex-wrap: wrap; }
  .hero-trend-head { align-items: flex-start; flex-direction: column; gap: 3px; }
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

h1 {
  color: var(--ios-text);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.1;
}

.brand-title-center {
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
}

.brand-mark-lg {
  width: 74px;
  height: 74px;
  border-radius: 18px;
}

.status-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--ios-text-2);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

.badge {
  background: rgba(0, 237, 117, 0.15);
  color: var(--ios-positive);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}


.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px 0 16px;
  padding: 10px 12px;
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  color: var(--ios-text-2);
  flex-wrap: wrap;
}

.toolbar label {
  color: var(--ios-accent);
  font-weight: 600;
}

.sort-select {
  min-width: 240px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-card-fill);
  color: #fff;
  font-family: inherit;
}

.sort-select:focus {
  outline: none;
  border-color: var(--ios-accent);
}

.sort-note {
  font-size: 0.8rem;
  color: var(--ios-text-3);
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.account-card {
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.account-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 184, 0, 0.55);
}

.account-card.offline { opacity: 0.55; border-color: rgba(255, 255, 255, 0.10); }
.account-card.emergency { border-color: rgba(255, 23, 69, 0.55); box-shadow: 0 0 16px rgba(255, 23, 69, 0.18); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #444;
}

.account-id {
  font-weight: bold;
  color: var(--ios-accent);
  font-size: 1.05rem;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  background: var(--ios-positive);
  box-shadow: 0 0 6px var(--ios-positive);
}
.online-dot.offline { background: #666; box-shadow: none; }

.broker { color: var(--ios-text-2); font-size: 0.8rem; }

.row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.9rem;
}

.row .label { color: var(--ios-text-2); }
.row .value { color: #fff; font-weight: 500; }
.value.green { color: var(--ios-positive); }
.value.red { color: var(--ios-negative); }

/* Profit/Loss colors */
.green, .money-primary.green, .money-muted.green { color: var(--ios-positive) !important; }
.red, .money-primary.red, .money-muted.red { color: var(--ios-negative) !important; }

/* Chart range selector */
.dashboard-title-row { align-items: center; }
.range-selector { margin-left: auto; }
.value.gold { color: var(--ios-accent); }

.section-divider {
  border-top: 1px dashed #333;
  margin: 8px 0;
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: bold;
}
.status-pill.trading      { background: rgba(0, 237, 117, 0.14);  color: var(--ios-positive); border: 1px solid rgba(0, 237, 117, 0.40); }
.status-pill.stopped      { background: rgba(255, 23, 69, 0.14);  color: var(--ios-negative); border: 1px solid rgba(255, 23, 69, 0.45); }
.status-pill.out-of-hours { background: rgba(255, 176, 32, 0.14); color: var(--bar-80);       border: 1px solid rgba(255, 176, 32, 0.40); }
.status-pill.emergency    { background: rgba(255, 23, 69, 0.20);  color: var(--ios-negative); border: 1px solid rgba(255, 23, 69, 0.60); }

.detail-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 2px;
  border-radius: 999px;
  vertical-align: middle;
  box-shadow: 0 0 0 0 currentColor;
  animation: account-status-pulse 2.6s ease-in-out infinite;
}
.detail-status-dot.running {
  color: var(--ios-positive);
  background: var(--ios-positive);
}
.detail-status-dot.stopped {
  color: var(--ios-negative);
  background: var(--ios-negative);
}

.loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ios-text-3);
  padding: 40px;
}

/* Modal Detail View */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 700px;
  position: relative;
  margin: 20px 0;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--ios-card-fill);
  color: #fff;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}

.detail-section {
  margin: 16px 0;
  padding: 12px;
  background: var(--ios-card-fill);
  border-radius: 6px;
}

.detail-section h3 {
  color: var(--ios-accent);
  margin-bottom: 8px;
  font-size: 1rem;
  border-bottom: 1px dashed #444;
  padding-bottom: 4px;
}

.btn-group {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.btn-group.action-stack {
  flex-direction: column;
  gap: 10px;
}

.ea-action-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.ea-action-status.running {
  color: var(--ios-positive);
  background: rgba(0, 237, 117, 0.10);
  border: 1px solid rgba(0, 237, 117, 0.34);
}
.ea-action-status.stopped {
  color: var(--ios-negative);
  background: rgba(255, 23, 69, 0.10);
  border: 1px solid rgba(255, 23, 69, 0.34);
}
.ea-action-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent);
}

.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-weight: bold;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.btn-current:disabled {
  opacity: 1;
  cursor: default;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.22), 0 0 0 2px rgba(255,255,255,0.05);
}

.btn-stop { background: var(--ios-negative); color: #fff; }
.btn-stop:hover:not(:disabled) { filter: brightness(1.12); }

.btn-resume { background: var(--ios-positive); color: #07110b; }
.btn-resume:hover:not(:disabled) { filter: brightness(1.12); }
.btn-stop.btn-action-pulse { --pulse-color: var(--ios-negative); }
.btn-resume.btn-action-pulse { --pulse-color: var(--ios-positive); }
.btn-primary-action {
  flex: none;
  min-height: 48px;
  border-radius: 10px;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.btn-action-pulse {
  animation: action-button-pulse 2.6s ease-in-out infinite;
}

@keyframes action-button-pulse {
  0%, 100% {
    background: color-mix(in srgb, var(--pulse-color, currentColor) 58%, #111 42%);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pulse-color, currentColor) 30%, transparent);
  }
  50% {
    background: color-mix(in srgb, var(--pulse-color, currentColor) 94%, #111 6%);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pulse-color, currentColor) 68%, transparent),
                0 0 12px color-mix(in srgb, var(--pulse-color, currentColor) 32%, transparent);
  }
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ios-card-bg);
  color: #fff;
  padding: 12px 24px;
  border-radius: 6px;
  border: 1px solid var(--ios-accent);
  z-index: 200;
  animation: slideUp 0.3s;
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.85rem;
}

.history-table th,
.history-table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid #2a2a2a;
}
.history-table th {
  color: var(--ios-accent);
  border-bottom: 1px solid #555;
}
.history-table td:first-child,
.history-table th:first-child {
  text-align: left;
}


.history-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.history-table .history-date {
  white-space: nowrap;
}

@media (max-width: 600px) {
  .history-table-wrap {
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .history-table {
    display: table;
    width: max-content;
    min-width: 440px;
    table-layout: auto;
    font-size: 0.74rem;
  }

  .history-table thead {
    display: table-header-group;
  }

  .history-table tbody {
    display: table-row-group;
  }

  .history-table tr {
    display: table-row;
  }

  .history-table th,
  .history-table td {
    display: table-cell;
    width: auto;
    padding: 6px 8px;
    text-align: right;
    white-space: nowrap;
    overflow: visible;
  }

  .history-table th:first-child,
  .history-table td:first-child {
    text-align: left;
  }

  .history-table td::before {
    content: none;
  }

  .history-table.order-book {
    min-width: 760px;
  }

  .history-table.order-book tr.order-book-extra {
    display: none;
  }

  .history-table-wrap.show-mobile-orders .history-table.order-book tr.order-book-extra {
    display: table-row;
  }
}

@media (max-width: 380px) {
  .history-table {
    font-size: 0.7rem;
  }

  .history-table th,
  .history-table td {
    padding: 5px 7px;
  }
}


.legend-bar {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: -4px 0 16px;
  padding: 10px 12px;
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 8px;
  color: #cfcfcf;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  vertical-align: -1px;
}
.legend-green { background: #22c55e; box-shadow: 0 0 8px rgba(34, 197, 94, 0.75); }
.legend-yellow { background: #eab308; box-shadow: 0 0 8px rgba(234, 179, 8, 0.75); }
.legend-red { background: #ef4444; box-shadow: 0 0 8px rgba(239, 68, 68, 0.75); }

.account-card.tone-positive {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(26, 26, 26, 0.96) 58%);
  border-color: rgba(34, 197, 94, 0.55);
}
.account-card.tone-warning {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.16), rgba(26, 26, 26, 0.96) 58%);
  border-color: rgba(234, 179, 8, 0.55);
}
.account-card.tone-danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.17), rgba(26, 26, 26, 0.96) 58%);
  border-color: rgba(239, 68, 68, 0.60);
}
.account-card.tone-positive:hover { border-color: #22c55e; }
.account-card.tone-warning:hover { border-color: #eab308; }
.account-card.tone-danger:hover { border-color: #ef4444; }

.config-view { margin-top: 4px; }
.config-card {
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 12px;
  padding: 18px;
}
.config-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 1px dashed #444;
  margin-bottom: 16px;
}
.config-header h2 { color: var(--ios-accent); font-size: 1.25rem; }
.config-header p { color: var(--ios-text-2); margin-top: 4px; line-height: 1.45; }
.config-section {
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.config-section h3 {
  color: var(--ios-accent);
  margin-bottom: 12px;
  font-size: 1rem;
}
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.config-field span {
  display: block;
  color: #e0e0e0;
  margin-bottom: 6px;
}
.config-field input,
.config-field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-card-bg);
  color: #fff;
  font-family: inherit;
}
.config-field input:focus,
.config-field select:focus {
  outline: none;
  border-color: var(--ios-accent);
}
.config-field small {
  display: block;
  color: var(--ios-text-3);
  margin-top: 6px;
  line-height: 1.4;
}
.status-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.status-preview {
  border-radius: 10px;
  padding: 14px;
  border: 1px solid var(--ios-card-stroke);
}
.status-preview strong { display: block; margin-bottom: 5px; }
.status-preview span { color: #cfcfcf; font-size: 0.85rem; line-height: 1.45; }
.preview-green { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.45); color: var(--ios-positive); }
.preview-yellow { background: rgba(234, 179, 8, 0.12); border-color: rgba(234, 179, 8, 0.45); color: var(--ios-accent); }
.preview-red { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.45); color: var(--ios-negative); }
.config-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}
.config-actions .login-btn { margin-top: 0; max-width: 240px; }
.btn-secondary {
  padding: 13px 16px;
  border-radius: 6px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-card-fill);
  color: #fff;
  font-family: inherit;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--ios-accent); }

@media (max-width: 600px) {
  body { padding: 8px; font-size: 13px; }
  h1 { font-size: 1.15rem; }
  .toolbar, .config-header, .config-actions { align-items: stretch; flex-direction: column; }
  .sort-select { width: 100%; min-width: 0; }
  .config-actions .login-btn { max-width: none; }
  .account-grid { grid-template-columns: 1fr; }
  .modal-content { padding: 16px; }
  .btn { padding: 16px 12px; }
}

.hidden { display: none !important; }

.login-screen {
  min-height: calc(100vh - 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.6);
}

.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
}

.login-note {
  color: var(--ios-text-2);
  text-align: center;
  line-height: 1.45;
  margin-bottom: 20px;
}

.login-card label {
  display: block;
  color: var(--ios-accent);
  margin: 12px 0 6px;
  font-size: 0.9rem;
}

.login-card input {
  width: 100%;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-card-fill);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
}

.login-card input:focus {
  outline: none;
  border-color: var(--ios-accent);
}

.login-btn {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--ios-accent);
  color: #111;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms ease, transform 100ms ease;
}
.login-btn:hover { background: #ffc933; }
.login-btn:active { transform: translateY(1px); }

.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  min-height: 20px;
  color: var(--ios-negative);
  text-align: center;
  margin-top: 12px;
  font-size: 0.9rem;
}

.login-info {
  color: var(--ios-text-3);
  font-size: 0.8rem;
  margin-top: 4px;
}

.logout-btn {
  background: var(--ios-card-fill);
  color: #fff;
  border: 1px solid var(--ios-card-stroke);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: inherit;
  cursor: pointer;
}

.logout-btn:hover {
  border-color: var(--ios-accent);
}

/* =====================
   Multi-account dashboard chart + portfolio table
   Settings-theme dashboard style
   ===================== */
.floating-dashboard,
.portfolio-panel {
  background: var(--ios-card-bg);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 18px 45px rgba(0,0,0,0.28), inset 0 0 0 1px rgba(255,255,255,0.015);
  transition: border-color 200ms ease, background 200ms ease;
}

.floating-dashboard:hover,
.portfolio-panel:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.dashboard-title-row,
.portfolio-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}

.dashboard-title-row h2,
.portfolio-head h2 {
  color: var(--ios-accent);
  font-size: 1.12rem;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dashboard-title-row h2::before { content: '⚙'; font-size: 0.95rem; }
.portfolio-head h2::before { content: '💼'; font-size: 0.95rem; }

.dashboard-title-row h2 span,
.portfolio-head p {
  color: var(--ios-text-2);
}

.dashboard-title-row p,
.portfolio-head p {
  margin-top: 3px;
  color: var(--ios-text-2);
  font-size: 0.82rem;
}

.range-selector button,
.status-filter {
  border: 0;
  border-radius: 7px;
  color: #fff;
  font-family: inherit;
  font-weight: 700;
}

.range-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-card-bg);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

.range-selector button {
  min-width: 44px;
  padding: 8px 10px;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  border: 1px solid transparent;
}

.range-selector button:hover {
  background: var(--ios-card-fill);
  border-color: var(--ios-card-stroke);
}

.range-selector button.active {
  color: #111;
  background: var(--ios-accent);
  border-color: var(--ios-accent);
  box-shadow: none;
}

.status-filter {
  padding: 11px 18px;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  cursor: default;
}

.chart-wrap {
  width: 100%;
  height: 330px;
  position: relative;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  overflow: hidden;
}

#floatingChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  padding-top: 10px;
  color: #cfcfcf;
  font-size: 0.88rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.chart-legend-line {
  width: 24px;
  height: 4px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: none;
}

.portfolio-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  background: var(--ios-card-fill);
}

.portfolio-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.portfolio-table th,
.portfolio-table td {
  padding: 15px 18px;
  border-bottom: 1px solid #242424;
  text-align: right;
  vertical-align: middle;
}

.portfolio-table th:first-child,
.portfolio-table td:first-child {
  text-align: left;
}

.portfolio-table th {
  color: #cfcfcf;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.015);
}

.portfolio-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.portfolio-table tbody tr:hover {
  background: rgba(255, 184, 0, 0.055);
}

.portfolio-table tbody tr:last-child td {
  border-bottom: 0;
}

.account-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-cell.no-avatar { gap: 0; }

.account-main {
  color: var(--ios-accent);
  font-weight: 800;
  font-size: 1rem;
}

.account-sub {
  color: var(--ios-text-2);
  font-size: 0.78rem;
  margin-top: 2px;
}

/* แยกกลุ่มโบรคด้วยสายตา: แถบสีซ้ายแถว + พื้นหลังจาง ๆ สีโบรค (--broker-color ตั้งบน <tr>) */
.portfolio-table tbody tr.broker-row {
  /* เลิกย้อมพื้นทั้งแถว ใช้แถบสีโบรกด้านซ้าย (td:first-child) แทน
     เพื่อให้สีเขียว/แดงของ P/L เด่นและคอนทราสต์ดีขึ้น */
  background: transparent;
}
.portfolio-table tbody tr.broker-row:hover {
  background: rgba(255, 255, 255, 0.03);
}
.portfolio-table tbody tr.broker-row td:first-child {
  box-shadow: inset 3px 0 0 var(--broker-color);
}
.portfolio-table tbody tr.broker-row.inactive-row {
  background: transparent;
}

/* ชิปชื่อโบรค — อ่านชื่อพร้อมเห็นสีในตัวเดียว */
.broker-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--broker-color);
  background: color-mix(in srgb, var(--broker-color) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--broker-color) 34%, transparent);
  margin-right: 7px;
  vertical-align: middle;
}
.account-sub-meta { vertical-align: middle; }
/* ป้าย "ตลาดปิด" — online แต่ไม่มี tick (วันหยุด) แยกจาก OFFLINE */
.market-closed-tag {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
  color: #9fb4cc;
  background: rgba(120, 150, 200, 0.14);
  border: 1px solid rgba(120, 150, 200, 0.32);
}

.mini-bar {
  width: 190px;
  height: 7px;
  background: var(--ios-card-stroke);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.mini-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  box-shadow: none;
}

.money-primary {
  color: #f4f4f4;
  font-weight: 800;
  font-size: 1rem;
}

.money-muted {
  color: var(--ios-text-2);
  font-size: 0.78rem;
  margin-top: 3px;
}

/* ตัวเลขการเงิน: หลักพัน/ทศนิยมตรงกันทุกแถว สแกนเร็ว */
.money-primary,
.money-muted {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ลูกศรทิศทางหน้าเลข (+▲ / −▼) — อ่านทิศทางได้โดยไม่พึ่งสีอย่างเดียว */
.sign-arrow {
  font-size: 0.72em;
  margin-right: 1px;
  vertical-align: baseline;
}

/* คอลัมน์ Lot บรรทัดที่สอง: แยกล็อต buy(▲)/sell(▼) เป็นชิปเล็ก ๆ
   ใช้ภาษาดีไซน์เดียวกับ .broker-chip (พื้นจาง+ขอบบาง) ให้ดูเรียบหรู */
.lot-split {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  margin-top: 5px;
  white-space: nowrap;
}
/* จัดคอลัมน์ตัวเลขทั้งหมดให้กึ่งกลาง → สมดุลทั้งตาราง + ขา buy/sell อยู่กลางใต้เลข LOT
   (Account ไม่ใช่ .num จึงยังชิดซ้าย) */
.portfolio-table th.num,
.portfolio-table td.num { text-align: center; }
.lot-leg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1.5px 7px;
  border-radius: 7px;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  white-space: nowrap;
  border: 1px solid transparent;
}
.lot-leg.green {
  background: color-mix(in srgb, var(--ios-positive) 13%, transparent);
  border-color: color-mix(in srgb, var(--ios-positive) 30%, transparent);
}
.lot-leg.red {
  background: color-mix(in srgb, var(--ios-negative) 13%, transparent);
  border-color: color-mix(in srgb, var(--ios-negative) 30%, transparent);
}
.lot-leg.neutral {
  background: rgba(255, 255, 255, 0.045);
  border-color: rgba(255, 255, 255, 0.09);
}
.lot-leg .lot-dir {
  font-size: 0.82em;
  opacity: 0.85;
}
/* บรรทัด 2 คอลัมน์ Lot: lot ที่ปิด (realized) วันนี้ — ชิปเทาเรียบ */
.lot-closed {
  display: inline-block;
  margin-top: 5px;
  padding: 1.5px 8px;
  border-radius: 7px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ios-text-3);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* คำกำกับเล็กใต้หัวคอลัมน์ Floating ("/ Bal") */
.sort-header .th-sub {
  color: var(--ios-text-4);
  font-weight: 600;
  font-size: 0.82em;
  margin-left: 4px;
  letter-spacing: 0;
  text-transform: none;
}

.actions-cell {
  color: var(--ios-text-2);
  letter-spacing: 0.5em;
  white-space: nowrap;
}

.table-footer {
  padding: 13px 18px;
  color: var(--ios-text-2);
  border-top: 1px solid #242424;
}

@media (max-width: 800px) {
  .floating-dashboard, .portfolio-panel { padding: 14px; }
  .dashboard-title-row, .portfolio-head { flex-direction: column; }
  .chart-wrap { height: 280px; }
}

.config-note {
  color: #aeb3d8;
  line-height: 1.55;
  margin: -2px 0 12px;
}
.config-note strong { color: #f4f4ff; }
.bar-rule-table {
  border: 1px solid rgba(130, 150, 255, 0.14);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(5, 8, 12, 0.38);
}
.bar-rule-head,
.bar-rule-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 110px minmax(180px, 1.4fr);
  gap: 12px;
  align-items: center;
  padding: 11px 13px;
  border-bottom: 1px solid rgba(130, 150, 255, 0.10);
}
.bar-rule-head {
  color: #c8c8db;
  font-size: 0.76rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.02);
}
.bar-rule-row:last-child { border-bottom: 0; }
.bar-rule-row input[type="color"] {
  width: 64px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}
.preview-example { grid-column: 1 / -1; }
.sample-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(105, 116, 150, 0.22);
  overflow: hidden;
  margin-top: 10px;
}
.sample-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}
.bar-pct {
  color: #cfd2ff;
  margin-left: 8px;
  font-size: 0.72rem;
}

@media (max-width: 600px) {
  .bar-rule-head, .bar-rule-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

/* Dashboard table revision: remove Equity and Floating columns, move online next to account */
.compact-portfolio-table {
  min-width: 760px;
}

.account-main-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.account-online {
  display: inline-flex;
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  box-shadow: 0 0 0 0 currentColor;
  animation: account-status-pulse 2.6s ease-in-out infinite;
}

.account-online.running,
.account-online.trading {
  color: var(--ios-positive);
  background: var(--ios-positive);
}

.account-online.stopped,
.account-online.emergency,
.account-online.inactive {
  color: var(--ios-negative);
  background: var(--ios-negative);
}

.account-online.unknown {
  color: var(--ios-positive);
  background: var(--ios-positive);
}

.account-online.online-green {
  color: var(--ios-positive);
  background: var(--ios-positive);
}

.account-online.offline-gray {
  color: var(--ios-negative);
  background: var(--ios-negative);
}

@keyframes account-status-pulse {
  0%, 100% {
    opacity: 0.55;
    transform: scale(0.88);
    box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 34%, transparent);
  }
  50% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 0%, transparent);
  }
}

/* Fix: account utilization percent placed to the right of the bar */
.account-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  width: 260px;
  max-width: 100%;
}
.account-bar-row .mini-bar {
  margin-top: 0;
  flex: 1 1 auto;
  width: auto;
  min-width: 120px;
}
.account-bar-row .bar-pct {
  margin-left: 0;
  min-width: 58px;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

/* Responsive dashboard + mobile friendly chart tooltip */
.floating-dashboard,
.portfolio-panel {
  width: 100%;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 142px;
  padding: 9px 11px;
  border: 1px solid var(--ios-accent);
  border-radius: 9px;
  background: rgba(8, 8, 8, 0.94);
  color: #f5f5f5;
  box-shadow: 0 8px 20px rgba(0,0,0,0.42);
  pointer-events: none;
  font-size: 0.78rem;
  line-height: 1.35;
  backdrop-filter: blur(4px);
}

.chart-tooltip.hidden { display: none; }

.chart-touch-marker {
  position: absolute;
  z-index: 4;
  width: 16px;
  height: 16px;
  border: 2px solid #6ee84f;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  background: rgba(8, 8, 8, 0.72);
  animation: chartTouchPulse 1.25s ease-out infinite;
}

.chart-touch-marker span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: #6ee84f;
}

.chart-touch-marker.hidden { display: none; }

@keyframes chartTouchPulse {
  0% { transform: translate(-50%, -50%) scale(0.92); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1.20); opacity: 0.86; }
  100% { transform: translate(-50%, -50%) scale(0.92); opacity: 1; }
}

.tip-id {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  font-weight: 800;
  margin-bottom: 3px;
}

.tip-color {
  width: 18px;
  height: 4px;
  border-radius: 999px;
  display: inline-block;
}

.tip-value {
  font-size: 0.95rem;
  font-weight: 900;
  margin-bottom: 2px;
}

.tip-time { color: #cfcfcf; }

@media (min-width: 1200px) {
  .container { max-width: 1500px; }
  .chart-wrap { height: clamp(330px, 32vh, 430px); }
}

@media (max-width: 900px) {
  :root { --dashboard-layout-width: 100%; /* mobile */ }
  body { padding: 8px; font-size: 13px; }
  .container { max-width: 100%; }
  header {
    padding: 12px;
    align-items: flex-start;
  }
  h1 { font-size: 1.12rem; }
  .status-bar {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }
  .dashboard-title-row,
  .portfolio-head {
    align-items: stretch;
    gap: 10px;
  }
  .range-selector {
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }
  .range-selector button {
    width: 100%;
    padding: 9px 8px;
  }
  .chart-wrap { height: clamp(260px, 48vh, 350px); }
  .chart-legend {
    justify-content: flex-start;
    gap: 10px 14px;
    font-size: 0.78rem;
    max-height: 74px;
    overflow-y: auto;
  }
  .chart-legend-line {
    width: 18px;
    height: 3px;
  }
}

@media (max-width: 520px) {
  body { padding: 6px; }
  .floating-dashboard,
  .portfolio-panel { padding: 10px; }
  .chart-wrap {
    height: 300px;
    border-radius: 8px;
  }
  .chart-tooltip {
    min-width: 126px;
    font-size: 0.72rem;
    padding: 8px 9px;
  }
  .tip-value { font-size: 0.86rem; }
  .portfolio-table th,
  .portfolio-table td { padding: 11px 12px; }
  .compact-portfolio-table { min-width: 690px; }
}


/* Icon-only header buttons */
.logout-btn.icon-btn {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  border-radius: 10px;
  color: var(--ios-text);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--ios-card-fill) 88%, white 12%), var(--ios-card-fill));
  border-color: color-mix(in srgb, var(--ios-card-stroke) 72%, var(--ios-accent) 28%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.025);
}

.logout-btn.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logout-btn.icon-btn:hover {
  color: var(--ios-accent);
  border-color: var(--ios-accent);
  transform: translateY(-1px);
  box-shadow: 0 0 14px color-mix(in srgb, var(--ios-accent) 28%, transparent),
              inset 0 0 0 1px color-mix(in srgb, var(--ios-accent) 16%, transparent);
}

@media (max-width: 520px) {
  header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 10px;
    padding: 12px;
  }
  header > div:first-child {
    min-width: 0;
  }
  header .brand-title {
    font-size: 1.12rem;
  }
  header .brand-mark {
    width: 34px;
    height: 34px;
  }
  header .status-bar {
    display: contents;
  }
  header #lastUpdate {
    grid-column: 1;
    grid-row: 2;
    font-size: 0.76rem;
  }
  .header-actions {
    grid-column: 2;
    grid-row: 1 / 3;
    gap: 6px;
    margin-left: 0;
  }
  .logout-btn.icon-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }
}

/* Portfolio Tracking compact layout: closer columns, easier to read on desktop + mobile */
.portfolio-panel {
  padding: 16px 18px;
}

.portfolio-head {
  align-items: center;
  margin-bottom: 10px;
}

.portfolio-head > div {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.portfolio-head h2 {
  margin: 0;
  white-space: nowrap;
}

.portfolio-head p {
  margin: 0;
  text-align: right;
  white-space: nowrap;
  font-size: 0.74rem;
  letter-spacing: 0.05em;
}

.portfolio-table-wrap {
  overflow-x: visible;
}

.portfolio-table,
.compact-portfolio-table {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}

.portfolio-table th,
.portfolio-table td {
  padding: 13px 14px;
}

.portfolio-table th:nth-child(1),
.portfolio-table td:nth-child(1) { width: 36%; }
.portfolio-table th:nth-child(2),
.portfolio-table td:nth-child(2) { width: 24%; }
.portfolio-table th:nth-child(3),
.portfolio-table td:nth-child(3) { width: 18%; }
.portfolio-table th:nth-child(4),
.portfolio-table td:nth-child(4) { width: 22%; }

.account-cell.no-avatar > div {
  width: 100%;
  min-width: 0;
}

.account-main-row {
  gap: 8px;
  line-height: 1.2;
}

.account-bar-row {
  width: min(220px, 100%);
  gap: 7px;
}

.account-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money-primary {
  line-height: 1.15;
}

.money-muted {
  line-height: 1.2;
}

@media (max-width: 700px) {
  .portfolio-panel {
    padding: 12px;
  }

  .portfolio-head > div {
    align-items: flex-end;
    gap: 8px;
  }

  .portfolio-head h2 {
    font-size: 1rem;
  }

  .portfolio-head p {
    font-size: 0.56rem;
    letter-spacing: 0.03em;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 10px 8px;
  }

  .portfolio-table th {
    font-size: 0.58rem;
    letter-spacing: 0.04em;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 34%; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 25%; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 18%; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 23%; }

  .account-main {
    font-size: 0.86rem;
  }

  .account-online {
    font-size: 0.55rem;
  }

  .account-sub {
    font-size: 0.58rem;
  }

  .account-bar-row {
    width: 100%;
    gap: 5px;
    margin-top: 5px;
  }

  .account-bar-row .mini-bar {
    min-width: 42px;
    height: 5px;
  }

  .account-bar-row .bar-pct {
    min-width: 35px;
    font-size: 0.52rem;
  }

  .money-primary {
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .money-muted {
    font-size: 0.56rem;
    white-space: nowrap;
  }

  .table-footer {
    padding: 9px 8px;
    font-size: 0.58rem;
  }
}

@media (max-width: 420px) {
  .portfolio-panel {
    padding: 10px;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 9px 5px;
  }

  .portfolio-head h2 {
    font-size: 0.92rem;
  }

  .portfolio-head p {
    font-size: 0.5rem;
  }

  .account-main {
    font-size: 0.78rem;
  }

  .account-online {
    display: block;
    margin-top: 2px;
  }

  .account-main-row {
    display: block;
  }

  .account-sub {
    display: none;
  }

  .money-primary {
    font-size: 0.72rem;
  }

  .money-muted {
    font-size: 0.51rem;
  }
}

/* Mobile Portfolio readability: enlarge Balance and Lot numbers only. */
@media (max-width: 700px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 30%; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 25%; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 16%; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 13%; }
  .portfolio-table th:nth-child(5),
  .portfolio-table td:nth-child(5) { width: 16%; }

  .portfolio-table td:nth-child(2) .money-primary,
  .portfolio-table td:nth-child(4) .money-primary {
    font-size: 1.02rem;
    font-weight: 900;
    letter-spacing: -0.02em;
  }

  .portfolio-table td:nth-child(2) .money-muted {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: -0.01em;
  }
}

@media (max-width: 420px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 28%; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 27%; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 15%; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 14%; }
  .portfolio-table th:nth-child(5),
  .portfolio-table td:nth-child(5) { width: 16%; }

  .portfolio-table td:nth-child(2) .money-primary,
  .portfolio-table td:nth-child(4) .money-primary {
    font-size: 0.96rem;
  }

  .portfolio-table td:nth-child(2) .money-muted {
    font-size: 0.68rem;
  }
}


/* Clickable sort headers */
.sort-header {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.sort-header:hover,
.sort-header.active {
  color: var(--ios-accent);
}
.sort-header span {
  font-size: 0.7rem;
  opacity: 0.9;
}

/* Portfolio Tracking desktop spacing tweak: keep the same table data, but pull columns closer together on wide PC screens. */
@media (min-width: 901px) {
  .portfolio-head,
  .portfolio-table-wrap {
    max-width: 1080px;
    margin-left: auto;
    margin-right: auto;
  }

  .portfolio-table,
  .compact-portfolio-table {
    width: 100%;
    table-layout: fixed;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 40%; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 22%; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 18%; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 20%; }
}
/* Equal center layout: make chart and Portfolio Tracking use the same inner width */
:root {
  --dashboard-content-max: 1400px;
  --dashboard-layout-width: 100%;
}

.container {
  width: min(var(--dashboard-layout-width), 100%);
  max-width: var(--dashboard-content-max);
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 1200px) {
  .container {
    max-width: var(--dashboard-content-max);
  }
}

@media (min-width: 901px) {
  .floating-dashboard,
  .portfolio-panel {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  .portfolio-head,
  .portfolio-table-wrap {
    width: 100%;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }
}


/* Layout size slider setting */
.layout-config-section {
  margin-top: 18px;
}

.layout-size-control {
  display: grid;
  grid-template-columns: auto 1fr auto 72px;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 184, 0, 0.18);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
}

.layout-size-control input[type=range] {
  width: 100%;
  accent-color: var(--ios-accent);
}

.layout-size-control strong {
  color: var(--ios-accent);
  text-align: right;
  font-size: 0.95rem;
}

.layout-step-btn {
  min-width: 42px;
  height: 38px;
  padding: 0 10px;
  font-size: 1.25rem;
  line-height: 1;
}

@media (max-width: 600px) {
  .layout-size-control {
    grid-template-columns: auto 1fr auto;
  }

  .layout-size-control strong {
    grid-column: 1 / -1;
    text-align: center;
  }
}


/* Inactive row styling — used inline alongside active rows now that the
   Active/Inactive tabs were removed. Each row decides its own state from the
   online flag, so styling targets `.inactive-row` directly. */

.neutral,
.inactive-mode,
.inactive-mode .green,
.inactive-mode .red,
.inactive-mode .gold,
.inactive-mode .money-primary,
.inactive-mode .money-muted,
.inactive-mode .account-main,
.inactive-mode .bar-pct,
.inactive-mode .value,
.inactive-mode .label,
.inactive-mode .history-date {
  color: var(--ios-text-3) !important;
}

.inactive-mode .portfolio-table,
.portfolio-table.inactive-mode,
.inactive-mode .detail-section,
.inactive-row {
  border-color: var(--ios-card-stroke) !important;
}

.inactive-row,
.inactive-mode tr {
  filter: grayscale(1);
  opacity: 0.78;
}

.inactive-mode .mini-bar span {
  background: #777 !important;
}

.status-pill.inactive {
  color: var(--ios-text-2) !important;
  border-color: var(--ios-card-stroke) !important;
  background: var(--ios-card-fill) !important;
}

.inactive-mode .btn,
.inactive-mode .btn-stop,
.inactive-mode .btn-resume {
  filter: grayscale(1);
}

/* Header Active / Inactive tabs were removed — block intentionally left blank
   to keep diff minimal; remove on next major cleanup. */

/* Mobile portfolio update: show Floating as main Balance value and allow horizontal scroll */
.portfolio-table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.portfolio-table,
.compact-portfolio-table {
  min-width: 760px;
}

@media (max-width: 700px) {
  .portfolio-table-wrap {
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .portfolio-table,
  .compact-portfolio-table {
    min-width: 690px;
    table-layout: fixed;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 42%; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 24%; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 17%; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 17%; }
}

@media (max-width: 420px) {
  .portfolio-table,
  .compact-portfolio-table {
    min-width: 660px;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 10px 8px;
  }
}

/* Mobile Portfolio: keep ACCOUNT + BALANCE visible first, with Profit/Max DD reachable by horizontal scroll */
@media (max-width: 700px) {
  .portfolio-table-wrap {
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .portfolio-table,
  .compact-portfolio-table {
    min-width: 560px !important;
    table-layout: fixed !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 42% !important; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 28% !important; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 15% !important; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 15% !important; }

  .account-bar-row {
    width: 100% !important;
    max-width: 180px !important;
  }

  .account-bar-row .mini-bar {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }

  .money-primary,
  .money-muted {
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  .portfolio-table,
  .compact-portfolio-table {
    min-width: 520px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 40% !important; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 30% !important; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 15% !important; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 15% !important; }

  .account-bar-row {
    max-width: 155px !important;
  }

  .account-bar-row .bar-pct {
    min-width: 32px !important;
    font-size: 0.5rem !important;
  }

  .money-primary {
    font-size: 0.68rem !important;
  }

  .money-muted {
    font-size: 0.49rem !important;
  }
}


/* Mobile readability update v5: widen Portfolio Tracking area and make Balance easier to read */
@media (max-width: 700px) {
  body {
    padding: 3px !important;
  }

  .container {
    width: 100% !important;
    max-width: none !important;
  }

  .floating-dashboard,
  .portfolio-panel {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .portfolio-panel {
    padding: 12px 8px 14px !important;
    border-radius: 20px !important;
  }

  .portfolio-head {
    padding-inline: 2px !important;
  }

  .portfolio-head h2 {
    font-size: 1.08rem !important;
  }

  .portfolio-table-wrap {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .portfolio-table,
  .compact-portfolio-table {
    min-width: 470px !important;
    width: 470px !important;
    table-layout: fixed !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 12px 8px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 45% !important; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 35% !important; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 10% !important; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 10% !important; }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    text-align: left !important;
  }

  .account-main {
    font-size: 0.94rem !important;
    line-height: 1.15 !important;
  }

  .account-online {
    font-size: 0.62rem !important;
  }

  .account-sub {
    display: none !important;
  }

  .account-main-row {
    gap: 4px !important;
  }

  .account-bar-row {
    width: 100% !important;
    max-width: 128px !important;
    gap: 6px !important;
  }

  .account-bar-row .mini-bar {
    min-width: 0 !important;
    height: 8px !important;
    flex: 1 1 auto !important;
  }

  .account-bar-row .bar-pct {
    min-width: 42px !important;
    font-size: 0.62rem !important;
  }

  .money-primary,
  .money-muted {
    display: block !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }

  .money-primary {
    font-size: 0.98rem !important;
    line-height: 1.1 !important;
  }

  .money-muted {
    font-size: 0.72rem !important;
    line-height: 1.15 !important;
  }

  .table-footer {
    padding: 10px 8px !important;
    font-size: 0.74rem !important;
  }
}

@media (max-width: 420px) {
  body {
    padding: 2px !important;
  }

  .portfolio-panel {
    padding: 11px 6px 13px !important;
  }

  .portfolio-head h2 {
    font-size: 1rem !important;
  }

  .portfolio-table,
  .compact-portfolio-table {
    min-width: 450px !important;
    width: 450px !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 11px 6px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) { width: 46% !important; }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) { width: 34% !important; }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3) { width: 10% !important; }
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) { width: 10% !important; }

  .account-main {
    font-size: 0.9rem !important;
  }

  .account-bar-row {
    max-width: 118px !important;
  }

  .account-bar-row .bar-pct {
    min-width: 40px !important;
    font-size: 0.58rem !important;
  }

  .money-primary {
    font-size: 0.9rem !important;
  }

  .money-muted {
    font-size: 0.68rem !important;
  }
}


/* Mobile option A v6: show ACCOUNT + BALANCE fully without horizontal scrolling */
@media (max-width: 700px) {
  body {
    padding: 4px !important;
  }

  .container {
    width: 100% !important;
    max-width: none !important;
  }

  .portfolio-panel {
    width: 100% !important;
    max-width: none !important;
    padding: 12px 8px 14px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 18px !important;
  }

  .portfolio-table-wrap {
    width: 100% !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
  }

  .portfolio-table,
  .compact-portfolio-table {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    table-layout: fixed !important;
  }

  /* Keep only Account and Balance visible on mobile. Profit and Max DD remain on desktop. */
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3),
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    display: none !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 58% !important;
    max-width: 58% !important;
    text-align: left !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 42% !important;
    max-width: 42% !important;
    text-align: right !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 13px 8px !important;
    vertical-align: middle !important;
  }

  .portfolio-table th {
    font-size: 0.72rem !important;
    letter-spacing: 0.05em !important;
  }

  .portfolio-head h2 {
    font-size: 1.08rem !important;
  }

  .account-main {
    font-size: 0.98rem !important;
    line-height: 1.12 !important;
    letter-spacing: 0.03em !important;
  }

  .account-online {
    display: block !important;
    margin-top: 3px !important;
    font-size: 0.62rem !important;
  }

  .account-sub {
    display: none !important;
  }

  .account-main-row {
    display: block !important;
  }

  .account-bar-row {
    width: 100% !important;
    max-width: 100% !important;
    gap: 6px !important;
    margin-top: 9px !important;
  }

  .account-bar-row .mini-bar {
    min-width: 0 !important;
    height: 9px !important;
    flex: 1 1 auto !important;
  }

  .account-bar-row .bar-pct {
    min-width: 45px !important;
    font-size: 0.62rem !important;
    text-align: right !important;
  }

  .money-primary,
  .money-muted {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
    text-align: right !important;
  }

  .money-primary {
    font-size: 0.98rem !important;
    line-height: 1.12 !important;
    letter-spacing: 0.01em !important;
  }

  .money-muted {
    font-size: 0.72rem !important;
    line-height: 1.18 !important;
    margin-top: 5px !important;
    opacity: 0.85 !important;
  }

  .table-footer {
    padding: 11px 8px !important;
    font-size: 0.72rem !important;
  }
}

@media (max-width: 420px) {
  body {
    padding: 3px !important;
  }

  .portfolio-panel {
    padding: 11px 6px 13px !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 12px 6px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 56% !important;
    max-width: 56% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 44% !important;
    max-width: 44% !important;
  }

  .account-main {
    font-size: 0.9rem !important;
  }

  .account-online {
    font-size: 0.58rem !important;
  }

  .account-bar-row .bar-pct {
    min-width: 42px !important;
    font-size: 0.56rem !important;
  }

  .money-primary {
    font-size: 0.88rem !important;
  }

  .money-muted {
    font-size: 0.65rem !important;
  }
}

/* v8: make mobile BALANCE numbers fill the cell, based on stable v6 layout */
@media (max-width: 700px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 50% !important;
    max-width: 50% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 50% !important;
    max-width: 50% !important;
    padding-left: 4px !important;
    padding-right: 4px !important;
    text-align: right !important;
    vertical-align: middle !important;
  }

  .portfolio-table td:nth-child(2) .money-primary {
    font-size: clamp(1.28rem, 6.4vw, 1.78rem) !important;
    line-height: 1.02 !important;
    font-weight: 900 !important;
    letter-spacing: -0.045em !important;
    width: 100% !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    text-align: right !important;
  }

  .portfolio-table td:nth-child(2) .money-muted {
    font-size: clamp(0.76rem, 3.4vw, 0.96rem) !important;
    line-height: 1.08 !important;
    font-weight: 700 !important;
    letter-spacing: -0.035em !important;
    margin-top: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    text-align: right !important;
  }
}

@media (max-width: 420px) {
  .portfolio-table th,
  .portfolio-table td {
    padding-top: 13px !important;
    padding-bottom: 13px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 49% !important;
    max-width: 49% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 51% !important;
    max-width: 51% !important;
  }

  .portfolio-table td:nth-child(2) .money-primary {
    font-size: clamp(1.22rem, 6.7vw, 1.55rem) !important;
    letter-spacing: -0.055em !important;
  }

  .portfolio-table td:nth-child(2) .money-muted {
    font-size: clamp(0.72rem, 3.5vw, 0.86rem) !important;
    letter-spacing: -0.045em !important;
  }
}

/* Portfolio Total Lots update: add Total Lots as a first-page Dashboard Portfolio column. */
.portfolio-table,
.compact-portfolio-table {
  min-width: 860px;
}

.portfolio-table th:nth-child(1),
.portfolio-table td:nth-child(1) { width: 34% !important; }
.portfolio-table th:nth-child(2),
.portfolio-table td:nth-child(2) { width: 21% !important; }
.portfolio-table th:nth-child(3),
.portfolio-table td:nth-child(3) { width: 16% !important; }
.portfolio-table th:nth-child(4),
.portfolio-table td:nth-child(4) { width: 13% !important; }
.portfolio-table th:nth-child(5),
.portfolio-table td:nth-child(5) { width: 16% !important; }

@media (max-width: 700px) {
  .portfolio-table,
  .compact-portfolio-table {
    min-width: 860px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 48% !important;
    max-width: 48% !important;
  }
  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 52% !important;
    max-width: 52% !important;
  }
  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3),
  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4),
  .portfolio-table th:nth-child(5),
  .portfolio-table td:nth-child(5) {
    display: none !important;
  }
}

/* Mobile Dashboard Portfolio fix: show Account + Balance + Total Lots on first screen. */
@media (max-width: 700px) {
  .portfolio-table,
  .compact-portfolio-table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding: 10px 5px !important;
    vertical-align: middle !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    display: table-cell !important;
    width: 42% !important;
    max-width: 42% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    display: table-cell !important;
    width: 35% !important;
    max-width: 35% !important;
    text-align: left !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    display: table-cell !important;
    width: 23% !important;
    max-width: 23% !important;
    text-align: right !important;
  }

  .portfolio-table th:nth-child(3),
  .portfolio-table td:nth-child(3),
  .portfolio-table th:nth-child(5),
  .portfolio-table td:nth-child(5) {
    display: none !important;
  }

  .portfolio-table th:nth-child(4) .sortable,
  .portfolio-table td:nth-child(4) .money-primary,
  .portfolio-table td:nth-child(4) .money-muted {
    text-align: right !important;
  }

  .account-cell,
  .account-cell.no-avatar > div {
    min-width: 0 !important;
  }

  .account-main-row {
    flex-wrap: wrap !important;
    gap: 3px !important;
  }

  .account-main {
    font-size: 0.82rem !important;
    letter-spacing: -0.03em !important;
  }

  .account-online {
    font-size: 0.48rem !important;
    padding: 2px 4px !important;
  }

  .account-bar-row {
    max-width: 105px !important;
    gap: 4px !important;
  }

  .account-bar-row .bar-pct {
    min-width: 34px !important;
    font-size: 0.52rem !important;
  }

  .portfolio-table td:nth-child(2) .money-primary,
  .portfolio-table td:nth-child(4) .money-primary {
    font-size: 0.76rem !important;
    letter-spacing: -0.05em !important;
  }

  .portfolio-table td:nth-child(2) .money-muted,
  .portfolio-table td:nth-child(4) .money-muted {
    font-size: 0.58rem !important;
    letter-spacing: -0.04em !important;
  }
}

@media (max-width: 380px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 40% !important;
    max-width: 40% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 36% !important;
    max-width: 36% !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 24% !important;
    max-width: 24% !important;
  }
}

/* Mobile Dashboard Portfolio v10: make Balance and Lot numbers fill their cells. */
@media (max-width: 700px) {
  .portfolio-table-wrap {
    padding-left: 0 !important;
    padding-right: 0 !important;
    overflow-x: hidden !important;
  }

  .portfolio-table,
  .compact-portfolio-table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding-left: 2px !important;
    padding-right: 2px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 30% !important;
    max-width: 30% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 46% !important;
    max-width: 46% !important;
    text-align: right !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 24% !important;
    max-width: 24% !important;
    text-align: right !important;
  }

  .portfolio-table th:nth-child(2) .sortable,
  .portfolio-table th:nth-child(4) .sortable {
    justify-content: flex-end !important;
    width: 100% !important;
    font-size: 0.62rem !important;
    letter-spacing: -0.04em !important;
  }

  .portfolio-table td:nth-child(2) .money-primary,
  .portfolio-table td:nth-child(4) .money-primary {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    font-size: clamp(17px, 4.9vw, 22px) !important;
    line-height: 1.02 !important;
    font-weight: 900 !important;
    letter-spacing: -0.095em !important;
    text-align: right !important;
    white-space: nowrap !important;
    overflow: visible !important;
  }

  .portfolio-table td:nth-child(2) .money-muted,
  .portfolio-table td:nth-child(4) .money-muted {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    font-size: clamp(12px, 3.5vw, 15px) !important;
    line-height: 1.05 !important;
    font-weight: 800 !important;
    letter-spacing: -0.075em !important;
    text-align: right !important;
    white-space: nowrap !important;
    overflow: visible !important;
  }

  .account-main {
    font-size: 0.72rem !important;
    letter-spacing: -0.06em !important;
  }

  .account-online {
    font-size: 0.42rem !important;
    padding: 1px 3px !important;
  }

  .account-bar-row {
    max-width: 82px !important;
  }

  .account-bar-row .bar-pct {
    min-width: 28px !important;
    font-size: 0.46rem !important;
  }
}

@media (max-width: 380px) {
  .portfolio-table th,
  .portfolio-table td {
    padding-left: 1px !important;
    padding-right: 1px !important;
  }

  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 28% !important;
    max-width: 28% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 48% !important;
    max-width: 48% !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 24% !important;
    max-width: 24% !important;
  }

  .portfolio-table td:nth-child(2) .money-primary,
  .portfolio-table td:nth-child(4) .money-primary {
    font-size: clamp(16px, 5.2vw, 20px) !important;
    letter-spacing: -0.1em !important;
  }
}

/* Mobile Dashboard Portfolio v11: hide monitoring text and enlarge Account number, bar, and percent. */
@media (max-width: 700px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 34% !important;
    max-width: 34% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 43% !important;
    max-width: 43% !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 23% !important;
    max-width: 23% !important;
  }

  .account-main-row {
    display: block !important;
    width: 100% !important;
  }

  .account-main {
    display: block !important;
    width: 100% !important;
    font-size: clamp(15px, 4.5vw, 19px) !important;
    line-height: 1.02 !important;
    font-weight: 900 !important;
    letter-spacing: -0.07em !important;
    white-space: nowrap !important;
  }

  .account-online {
    display: none !important;
  }

  .account-bar-row {
    width: 100% !important;
    max-width: 100% !important;
    gap: 4px !important;
    margin-top: 7px !important;
  }

  .account-bar-row .mini-bar {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    height: 11px !important;
    margin-top: 0 !important;
  }

  .account-bar-row .bar-pct {
    flex: 0 0 auto !important;
    min-width: 34px !important;
    font-size: clamp(10px, 3vw, 13px) !important;
    line-height: 1 !important;
    font-weight: 900 !important;
    letter-spacing: -0.055em !important;
    text-align: right !important;
  }
}

@media (max-width: 380px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 34% !important;
    max-width: 34% !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 42% !important;
    max-width: 42% !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 24% !important;
    max-width: 24% !important;
  }

  .account-main {
    font-size: clamp(14px, 4.8vw, 17px) !important;
  }

  .account-bar-row .mini-bar {
    height: 10px !important;
  }

  .account-bar-row .bar-pct {
    min-width: 32px !important;
    font-size: clamp(9px, 3vw, 12px) !important;
  }
}


/* Currency setlist (Settings → สกุลเงินบัญชี) */
.currency-account-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

/* Alert config grid (Settings → เกณฑ์แจ้งเตือน) */
.alert-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.alert-config-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.alert-config-grid label > span:first-child {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ios-text-1);
}
.alert-config-grid .config-input {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--ios-card-stroke);
  background: var(--ios-bg);
  color: var(--ios-text-1);
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
}
.alert-config-grid .config-hint {
  font-size: 0.75rem;
  color: var(--ios-text-2);
}
.currency-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.currency-row:hover { border-color: rgba(255,255,255,0.22); background: var(--ios-card-bg); }
.currency-row-meta { display: flex; flex-direction: column; min-width: 0; }
.currency-row-id {
  color: var(--ios-accent);
  font-weight: 600;
  font-size: 0.95rem;
  font-feature-settings: "tnum" 1;
}
.currency-row-broker {
  color: var(--ios-text-3);
  font-size: 0.78rem;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.currency-toggle { display: inline-flex; align-items: center; gap: 8px; }
.currency-checkbox { width: 18px; height: 18px; accent-color: var(--ios-accent); cursor: pointer; }
.currency-pill {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.6px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #cfcfcf;
  background: rgba(255, 184, 0, 0.10);
  border: 1px solid rgba(255, 184, 0, 0.32);
  white-space: nowrap;
}
.currency-checkbox:checked + .currency-pill {
  color: var(--ios-accent);
  background: rgba(255, 184, 0, 0.18);
  border-color: rgba(255, 184, 0, 0.55);
}

/* ปุ่มเฟือง active ตอนอยู่หน้า Settings (toggle กลับ dashboard) */
.icon-btn.active {
  color: var(--ios-accent);
  background: rgba(255, 184, 0, 0.18);
  border-color: rgba(255, 184, 0, 0.55);
}

/* ---------- Settings: auto-save indicator ---------- */
.config-header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.save-indicator {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ios-text-2);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--ios-card-stroke);
  white-space: nowrap;
  transition: color 150ms ease, border-color 150ms ease;
}
.save-indicator.saving { color: var(--ios-accent);   border-color: rgba(255,184,0,0.40); }
.save-indicator.saved  { color: var(--ios-positive); border-color: rgba(0,237,117,0.40); }
.save-indicator.error  { color: var(--ios-negative); border-color: rgba(255,23,69,0.45); }

/* ---------- Settings: scope tag ---------- */
.config-scope-tag {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
  color: var(--ios-text-2);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
}
.config-scope-tag.scope-server {
  color: #7fd0ff;
  background: rgba(56,189,248,0.12);
  border-color: rgba(56,189,248,0.34);
}

/* ---------- Settings: collapsible advanced (details) ---------- */
.config-advanced { margin-top: 12px; }
.config-advanced > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ios-text-2);
  padding: 8px 10px;
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  list-style: none;
  user-select: none;
  transition: color 150ms ease, border-color 150ms ease;
}
.config-advanced > summary::-webkit-details-marker { display: none; }
.config-advanced > summary::before { content: "▸ "; color: var(--ios-text-3); }
.config-advanced[open] > summary::before { content: "▾ "; }
.config-advanced > summary:hover { color: var(--ios-text-1); border-color: rgba(255,255,255,0.22); }
.config-advanced[open] > summary { color: var(--ios-text-1); margin-bottom: 12px; }

/* ---------- Settings: merged account row (USD/Cent + delete) ---------- */
.account-manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
  margin-bottom: 8px;
  transition: border-color 150ms ease, background 150ms ease;
}
.account-manage-row:hover { border-color: rgba(255,255,255,0.22); }
.account-manage-row .currency-row-meta { flex: 1; min-width: 0; }
.acc-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}
.acc-dot.online  { background: var(--ios-positive); box-shadow: 0 0 6px rgba(0,237,117,0.6); }
.acc-dot.offline { background: #777; }
.acc-delete-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ios-text-3);
  font-size: 1rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 150ms ease, color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.acc-delete-btn:hover {
  opacity: 1;
  color: var(--ios-negative);
  background: rgba(255,23,69,0.10);
  border-color: rgba(255,23,69,0.40);
}

/* ---------- Settings: invalid alert input ---------- */
.config-input.input-invalid {
  border-color: var(--ios-negative) !important;
  background: rgba(255,23,69,0.08);
}
.config-hint.hint-error { color: var(--ios-negative); font-weight: 600; }


/* Theme picker (Settings) */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.theme-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.theme-option:hover { border-color: rgba(255,255,255,0.22); transform: translateY(-1px); }
.theme-option input[type=radio] {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid #555;
  margin: 0;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.theme-option input[type=radio]:checked {
  border-color: var(--ios-accent);
}
.theme-option input[type=radio]:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 999px;
  background: var(--ios-accent);
}
.theme-option:has(input:checked) {
  border-color: var(--ios-accent);
  background: color-mix(in srgb, var(--ios-accent) 9%, transparent);
}
.theme-preview {
  display: inline-flex;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  flex-shrink: 0;
}
.theme-preview--liquid    { background: #020203; }
.theme-preview--electric  { background: #041016; }
.theme-preview--cobalt    { background: #090616; }
.theme-preview--coral     { background: #0f0608; }
.theme-preview--spearmint { background: #07110f; }
.theme-preview--cloud     { background: #f8fafc; }
.theme-preview--burgundy  { background: #12070d; }
.theme-preview--graphite  { background: #000000; }
.theme-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
}
.theme-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: #e5e5e5;
}

/* ============================
   Trash Modal — deleted accounts list
   Compact iOS-style row with right-aligned auto-width Restore button.
   ============================ */
.trash-title {
  color: var(--ios-accent);
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.trash-title .trash-count {
  color: var(--ios-text-3);
  font-size: 0.7em;
  font-weight: 500;
  margin-left: 6px;
}
.trash-note {
  color: var(--ios-text-2);
  font-size: 0.86rem;
  line-height: 1.5;
}
.trash-hint {
  color: var(--ios-text-4);
  font-size: 0.82rem;
  line-height: 1.5;
}
.trash-error {
  color: var(--ios-negative);
  margin-top: 8px;
}
.trash-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.trash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: var(--ios-card-fill);
  border: 1px solid var(--ios-card-stroke);
  border-radius: 10px;
}
.trash-row-meta {
  min-width: 0;
  flex: 1;
}
.trash-row-id {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ios-text);
  letter-spacing: 0.1px;
}
.trash-row-time {
  color: var(--ios-text-3);
  font-size: 0.78rem;
  margin-top: 2px;
}
.trash-row-note {
  color: var(--ios-text-3);
  font-size: 0.78rem;
  margin-top: 2px;
}
.trash-row-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid rgba(0, 237, 117, 0.45);
  background: rgba(0, 237, 117, 0.14);
  color: var(--ios-positive);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease, transform 100ms ease;
}
.trash-row-btn:hover {
  background: rgba(0, 237, 117, 0.22);
  border-color: rgba(0, 237, 117, 0.65);
}
.trash-row-btn:active { transform: translateY(1px); }

@media (max-width: 700px) {
  .portfolio-table th:nth-child(1),
  .portfolio-table td:nth-child(1) {
    width: 48% !important;
    max-width: 48% !important;
    padding-left: 8px !important;
  }

  .portfolio-table th:nth-child(2),
  .portfolio-table td:nth-child(2) {
    width: 32% !important;
    max-width: 32% !important;
  }

  .portfolio-table th:nth-child(4),
  .portfolio-table td:nth-child(4) {
    width: 20% !important;
    max-width: 20% !important;
    padding-right: 8px !important;
  }

  /* Keep the account status indicator beside the account id on mobile only. */
  .account-main-row {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
  }

  .account-main-row .account-main {
    display: inline !important;
    width: auto !important;
    min-width: 0 !important;
  }

  .account-main-row .account-online.status-dot {
    display: inline-flex !important;
    width: 10px !important;
    height: 10px !important;
    min-width: 10px !important;
    min-height: 10px !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 999px !important;
  }

  .account-cell.no-avatar > div {
    width: 100% !important;
    min-width: 0 !important;
  }

  .account-sub {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    margin-top: 4px !important;
    width: 100% !important;
    overflow: hidden !important;
    white-space: nowrap !important;
  }

  .broker-chip {
    display: inline-block !important;
    max-width: 118px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    vertical-align: middle !important;
  }

  .account-sub-meta {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: 96px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

/* ============================================================
   มือถือ: แปลงตาราง Portfolio → การ์ดต่อบัญชี (1 บัญชี = 1 การ์ด)
   วางท้ายไฟล์ + scope 2 คลาส (.portfolio-table.compact-portfolio-table)
   เพื่อชนะกฎ display:none/width ของคอลัมน์เดิมที่เป็น !important
   ============================================================ */
@media (max-width: 600px) {
  .portfolio-table.compact-portfolio-table {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    border: 0 !important;
  }
  .portfolio-table.compact-portfolio-table thead { display: none !important; }
  .portfolio-table.compact-portfolio-table tbody { display: block !important; }

  /* แต่ละแถว = การ์ด */
  .portfolio-table.compact-portfolio-table tbody tr.broker-row {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    background: var(--ios-card-fill) !important;
    border: 1px solid var(--ios-card-stroke) !important;
    border-left: 3px solid var(--broker-color) !important;
    border-radius: 14px !important;
    padding: 12px 14px !important;
    margin-bottom: 11px !important;
  }
  .portfolio-table.compact-portfolio-table tbody tr.broker-row.inactive-row { opacity: 0.6; }

  /* ทุกเซลล์เป็นบล็อก + โชว์คอลัมน์ที่เคยซ่อน (Profit/Max DD) กลับมา */
  .portfolio-table.compact-portfolio-table tbody tr td {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    border: none !important;
    position: relative !important;
    padding: 6px 0 6px 96px !important;
    text-align: right !important;
    box-shadow: none !important;
  }

  /* ป้ายชื่อค่าด้านซ้าย (Floating / Profit / Lot / Max DD) */
  .portfolio-table.compact-portfolio-table tbody tr td[data-label]::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ios-text-4);
    font-weight: 700;
    text-align: left;
  }

  /* เซลล์แรก (Account) = หัวการ์ด เต็มความกว้าง ไม่มีป้าย */
  .portfolio-table.compact-portfolio-table tbody tr td:first-child {
    padding: 0 0 9px 0 !important;
    margin-bottom: 8px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07) !important;
    text-align: left !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td .money-primary {
    font-size: 0.98rem !important;
    font-weight: 800 !important;
  }
  .portfolio-table.compact-portfolio-table tbody tr td .money-muted {
    font-size: 0.72rem !important;
    margin-top: 1px !important;
  }

  /* แถบ %คงเหลือในหัวการ์ดให้กว้างเต็ม */
  .portfolio-table.compact-portfolio-table tbody tr td:first-child .account-bar-row { width: 100% !important; }
  .portfolio-table.compact-portfolio-table tbody tr td:first-child .mini-bar { width: auto !important; flex: 1 1 auto !important; }
}

/* Mobile Portfolio card layout: match _harness-mobile mockup. */
@media (max-width: 600px) {
  .portfolio-table-wrap {
    overflow: visible !important;
    border: 0 !important;
    background: transparent !important;
  }

  .portfolio-table.compact-portfolio-table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: auto !important;
    border-collapse: separate !important;
  }

  .portfolio-table.compact-portfolio-table thead {
    display: none !important;
  }

  .portfolio-table.compact-portfolio-table tbody {
    display: block !important;
    width: 100% !important;
  }

  .portfolio-table.compact-portfolio-table tr.broker-row {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 0 12px !important;
    padding: 13px 15px !important;
    border: 1px solid var(--ios-card-stroke, #2a2a2a) !important;
    border-radius: 14px !important;
    background: var(--ios-card-fill, #0f0f0f) !important;
    background-image: linear-gradient(
      color-mix(in srgb, var(--broker-color, #ffd700) 6%, transparent),
      color-mix(in srgb, var(--broker-color, #ffd700) 6%, transparent)
    ) !important;
    box-shadow: inset 3px 0 0 var(--broker-color, #ffd700) !important;
  }

  .portfolio-table.compact-portfolio-table tr.broker-row.inactive-row {
    opacity: 0.6 !important;
  }

  .portfolio-table.compact-portfolio-table td {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    text-align: left !important;
    box-shadow: none !important;
  }

  .portfolio-table.compact-portfolio-table td:first-child {
    padding-bottom: 11px !important;
    margin-bottom: 9px !important;
    border-bottom: 1px solid var(--ios-card-stroke, #242424) !important;
  }

  .portfolio-table.compact-portfolio-table td.num {
    display: flex !important;
    align-items: baseline !important;
    gap: 8px !important;
    padding: 7px 2px !important;
    text-align: right !important;
  }

  .portfolio-table.compact-portfolio-table td.num + td.num {
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
  }

  .portfolio-table.compact-portfolio-table td.num::before {
    content: attr(data-label) !important;
    margin-right: auto !important;
    color: var(--ios-text-3, #888) !important;
    font-size: 0.74rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px !important;
    text-align: left !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table td.num .money-primary,
  .portfolio-table.compact-portfolio-table td.num .money-muted,
  .portfolio-table.compact-portfolio-table td.num .lot-closed {
    flex: 0 0 auto !important;
    max-width: 48% !important;
    overflow: hidden !important;
    text-align: right !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table td.num .money-primary {
    font-size: 0.92rem !important;
    font-weight: 700 !important;
    letter-spacing: 0 !important;
    line-height: 1.15 !important;
  }

  .portfolio-table.compact-portfolio-table td.num .money-muted {
    margin-top: 0 !important;
    font-size: 0.78rem !important;
    letter-spacing: 0 !important;
    line-height: 1.15 !important;
  }

  .portfolio-table.compact-portfolio-table .account-main-row {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
  }

  .portfolio-table.compact-portfolio-table .account-main {
    display: inline !important;
    width: auto !important;
    min-width: 0 !important;
    font-size: 1rem !important;
    font-weight: 900 !important;
    letter-spacing: 0 !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table .account-online.status-dot {
    display: inline-flex !important;
    width: 10px !important;
    height: 10px !important;
    min-width: 10px !important;
    min-height: 10px !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 999px !important;
  }

  .portfolio-table.compact-portfolio-table .account-sub {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    width: 100% !important;
    margin-top: 4px !important;
    overflow: hidden !important;
    font-size: 0.72rem !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table .broker-chip {
    display: inline-block !important;
    max-width: 118px !important;
    padding: 1px 6px !important;
    overflow: hidden !important;
    font-size: 0.69rem !important;
    text-overflow: ellipsis !important;
    vertical-align: middle !important;
  }

  .portfolio-table.compact-portfolio-table .account-sub-meta {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
    font-size: 0.75rem !important;
    text-overflow: ellipsis !important;
  }

  .portfolio-table.compact-portfolio-table .account-bar-row {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: 9px !important;
  }

  .portfolio-table.compact-portfolio-table .mini-bar {
    flex: 1 1 auto !important;
    width: auto !important;
    min-width: 0 !important;
    height: 6px !important;
    margin-top: 0 !important;
  }

  .portfolio-table.compact-portfolio-table .bar-pct {
    flex: 0 0 auto !important;
    min-width: 42px !important;
    font-size: 0.72rem !important;
    font-weight: 800 !important;
    letter-spacing: 0 !important;
    line-height: 1 !important;
    text-align: right !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table .lot-closed {
    margin-top: 0 !important;
    padding: 1px 6px !important;
    font-size: 0.69rem !important;
    letter-spacing: 0 !important;
  }

  .portfolio-table.compact-portfolio-table .sign-arrow {
    font-size: 0.62rem !important;
  }

  .portfolio-hero {
    padding: 14px !important;
  }

  .hero-eyebrow {
    font-size: 0.62rem !important;
  }

  .hero-label {
    font-size: 0.68rem !important;
  }

  .hero-value {
    font-size: 1.7rem !important;
  }

  .hero-pct {
    font-size: 0.74rem !important;
  }

  .hero-dd {
    font-size: 0.66rem !important;
  }

  .hero-stat .lab {
    font-size: 0.68rem !important;
  }

  .hero-stat .val {
    font-size: 0.84rem !important;
  }

  .portfolio-panel {
    padding: 12px !important;
  }

  .portfolio-head h2 {
    font-size: 0.95rem !important;
  }
}

/* Specificity guard for legacy mobile table overrides. */
@media (max-width: 600px) {
  .portfolio-table.compact-portfolio-table tbody tr.broker-row {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 0 12px !important;
    padding: 13px 15px !important;
    border: 1px solid var(--ios-card-stroke, #2a2a2a) !important;
    border-radius: 14px !important;
    background: var(--ios-card-fill, #0f0f0f) !important;
    background-image: linear-gradient(
      color-mix(in srgb, var(--broker-color, #ffd700) 6%, transparent),
      color-mix(in srgb, var(--broker-color, #ffd700) 6%, transparent)
    ) !important;
    box-shadow: inset 3px 0 0 var(--broker-color, #ffd700) !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td {
    display: block !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    text-align: left !important;
    box-shadow: none !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td:first-child {
    padding-bottom: 11px !important;
    margin-bottom: 9px !important;
    border-bottom: 1px solid var(--ios-card-stroke, #242424) !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num {
    display: grid !important;
    grid-template-columns: minmax(56px, 1fr) minmax(78px, max-content) minmax(76px, max-content) !important;
    align-items: baseline !important;
    gap: 8px !important;
    padding: 7px 2px !important;
    text-align: right !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num + td.num {
    border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num::before {
    content: attr(data-label) !important;
    grid-column: 1 !important;
    justify-self: start !important;
    margin-right: 0 !important;
    color: var(--ios-text-3, #888) !important;
    font-size: 0.74rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px !important;
    text-align: left !important;
    text-transform: uppercase !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num .money-primary {
    grid-column: 2 !important;
    justify-self: end !important;
    width: max-content !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    font-family: inherit !important;
    font-variant-numeric: tabular-nums !important;
    font-feature-settings: "tnum" !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num .money-muted,
  .portfolio-table.compact-portfolio-table tbody tr td.num .lot-closed {
    grid-column: 3 !important;
    justify-self: end !important;
    min-width: 72px !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    margin-top: 0 !important;
    font-family: inherit !important;
    font-size: 0.78rem !important;
    font-weight: 700 !important;
    line-height: 1.15 !important;
    letter-spacing: 0 !important;
    text-align: right !important;
    font-variant-numeric: tabular-nums !important;
    font-feature-settings: "tnum" !important;
    white-space: nowrap !important;
  }

  .portfolio-table.compact-portfolio-table tbody tr td.num .lot-closed {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: max-content !important;
    min-width: 72px !important;
    padding: 1px 6px !important;
  }
}


/* ===== Server Health (CPU / RAM per VPS) ===== */
.host-health-head { flex-wrap: wrap; gap: 10px; }
.host-health-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.host-tabs, .host-range { display: flex; gap: 6px; flex-wrap: wrap; }
.host-tabs button, .host-range button {
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 4px 12px; border-radius: 999px; line-height: 1.6;
  color: var(--ios-text-3, #8b95a7);
  background: var(--ios-card-fill, rgba(255,255,255,0.04));
  border: 1px solid var(--ios-card-stroke, rgba(255,255,255,0.10));
  transition: color .15s, background .15s, border-color .15s;
}
.host-tabs button:hover, .host-range button:hover { color: var(--ios-text, #f2f4f8); }
.host-tabs button.active, .host-range button.active {
  color: var(--ios-bg, #0b0e14);
  background: var(--ios-accent, #38bdf8);
  border-color: var(--ios-accent, #38bdf8);
}
.host-stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.host-stat {
  flex: 1 1 120px; min-width: 120px;
  background: var(--ios-card-fill, rgba(255,255,255,0.04));
  border: 1px solid var(--ios-card-stroke, rgba(255,255,255,0.10));
  border-radius: 12px; padding: 10px 14px;
}
.host-stat .lab { display: block; font-size: 11px; letter-spacing: .06em; color: var(--ios-text-3, #8b95a7); }
.host-stat .val { display: block; font-size: 22px; font-weight: 700; margin-top: 2px; color: var(--ios-text, #f2f4f8); }
.host-stat .sub { display: block; font-size: 11px; color: var(--ios-text-4, #6b7488); margin-top: 1px; }
.host-stat .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.host-chart-wrap { position: relative; width: 100%; height: 260px; }
.host-chart-wrap canvas { display: block; width: 100%; height: 100%; }
@media (max-width: 560px) { .host-chart-wrap { height: 210px; } }

/* =====================================================================
   Per-EA breakdown + order book (account detail modal)
   บัญชีเดียวรัน EA ได้หลายตัว แยกด้วย magic — สีต่อ EA ใช้ inline style
   จาก EA_COLORS ใน app.js เพื่อให้แถบ ตาราง และจุดสีตรงกันทุกที่
   ===================================================================== */
.ea-share-row { margin-bottom: 12px; }
.ea-share-head { display: flex; align-items: center; gap: 8px; }
.ea-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  flex: none; margin-right: 6px; vertical-align: middle;
}
.ea-share-head .ea-dot { margin-right: 0; }
.ea-name-btn {
  flex: 1 1 auto; min-width: 0;
  background: none; border: none; padding: 0;
  font: inherit; text-align: left; cursor: pointer;
  color: var(--ios-text, #f2f4f8);
  border-bottom: 1px dashed var(--ios-text-4, #6b7488);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ea-name-btn:hover { color: var(--ios-accent, #38bdf8); border-bottom-color: var(--ios-accent, #38bdf8); }
.ea-share-pl { flex: none; font-weight: 700; }
.ea-share-bar {
  height: 6px; margin: 5px 0 3px; border-radius: 3px;
  background: var(--ios-card-fill, rgba(255,255,255,0.06)); overflow: hidden;
}
.ea-share-bar span { display: block; height: 100%; border-radius: 3px; }
.ea-share-meta { font-size: 11px; color: var(--ios-text-3, #8b95a7); }

/* Order book มี 8 คอลัมน์ - บีบตัวอักษรลงแทนที่จะให้ล้นออกนอกกรอบ */
.history-table.order-book { font-size: 0.78rem; }
.history-table.order-book th,
.history-table.order-book td { padding: 5px 6px; white-space: nowrap; }
.history-table.order-book td:nth-child(3) {
  text-align: left; max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}

/* =====================================================================
   v2 dashboard - "Forex Performance Dashboard" design
   Local aliases keep the compact v2 layout while following the active theme.
   ===================================================================== */
.v2-root {
  --v2-accent-soft: color-mix(in srgb, var(--ios-accent) 10%, transparent);
  --v2-accent-border: color-mix(in srgb, var(--ios-accent) 30%, var(--ios-card-stroke));
  --v2-hover-border: color-mix(in srgb, var(--ios-text) 24%, var(--ios-card-stroke));
  --v2-soft-track: color-mix(in srgb, var(--ios-text) 7%, var(--ios-card-bg));
  color: var(--ios-text);
  font-family: 'Space Grotesk', 'Leelawadee UI', Tahoma, system-ui, sans-serif;
}
.v2-root .v2-mono, .v2-root .v2-kpi-value, .v2-root .v2-legend-ret,
.v2-root .v2-bar-row-head span:last-child { font-family: 'IBM Plex Mono', monospace; }

.v2-header {
  display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end;
  justify-content: space-between; margin-bottom: 22px;
}
.v2-header-id { display: flex; flex-direction: column; }
.v2-title-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.v2-title { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.v2-meta { font-size: 12px; color: var(--ios-text-3); }
.v2-ea-chip {
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--ios-accent);
  background: var(--v2-accent-soft); border: 1px solid var(--v2-accent-border);
  padding: 3px 9px; border-radius: 6px;
}

.v2-switchers { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.v2-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.v2-pill-divider { width: 1px; height: 26px; background: var(--ios-card-stroke); margin: 0 6px; }
.v2-pill {
  cursor: pointer; font-size: 12px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--ios-card-stroke); color: var(--ios-text-2); background: transparent;
  transition: all .15s ease; white-space: nowrap; font-family: 'Space Grotesk', sans-serif;
}
.v2-pill:hover { border-color: var(--v2-hover-border); color: var(--ios-text); }
.v2-pill.active {
  border-color: var(--ios-accent); color: var(--ios-accent); background: var(--v2-accent-soft);
}
.v2-pill-mono { font-family: 'IBM Plex Mono', monospace; }
.v2-pill-mono.active { border-color: var(--v2-hover-border); color: var(--ios-text); background: var(--ios-card-fill); }

.v2-kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px; background: var(--ios-card-stroke); border: 1px solid var(--ios-card-stroke); border-radius: 14px;
  overflow: hidden; margin-bottom: 22px;
}
.v2-kpi { background: var(--ios-card-bg); padding: 20px 22px; display: flex; flex-direction: column; gap: 9px; }
.v2-kpi-label { font-size: 11px; letter-spacing: .13em; text-transform: uppercase; color: var(--ios-text-3); }
.v2-kpi-value { font-size: 26px; font-weight: 500; letter-spacing: -0.02em; }
.v2-kpi-sub { font-size: 12px; color: var(--ios-text-2); }

.v2-card {
  background: var(--ios-card-bg); border: 1px solid var(--ios-card-stroke); border-radius: 14px;
  padding: 22px 24px; margin-bottom: 18px; min-width: 0;
}
.v2-card-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; }
.v2-card-title { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; }
.v2-card-sub { font-size: 13px; line-height: 1.5; color: var(--ios-text-3); margin-top: 5px; margin-bottom: 18px; }
.v2-full { grid-column: 1 / -1; }

.v2-legend-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.v2-legend-chip {
  display: flex; align-items: center; gap: 9px; padding: 7px 12px;
  border: 1px solid var(--ios-card-stroke); border-radius: 8px; cursor: pointer;
  transition: border-color .15s; white-space: nowrap; flex-shrink: 0;
}
.v2-legend-chip:hover { border-color: var(--v2-hover-border); }
.v2-legend-name { font-size: 12px; color: var(--ios-text-2); white-space: nowrap; }
.v2-legend-ret { font-size: 12px; white-space: nowrap; }
.v2-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.v2-bar-list { display: flex; flex-direction: column; gap: 14px; }
.v2-bar-row { display: flex; flex-direction: column; gap: 7px; }
.v2-bar-row-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.v2-bar-track { height: 8px; background: var(--ios-card-fill); border-radius: 4px; overflow: hidden; }
.v2-bar-track span { display: block; height: 100%; border-radius: 4px; }
.v2-bar-track-thin { height: 10px; }
.v2-bar-track-thin span { border-radius: 5px; }

.v2-risk-return-card {
  margin-bottom: 0;
  background: color-mix(in srgb, var(--ios-card-bg) 94%, var(--ios-text) 6%);
  box-shadow: 0 14px 34px color-mix(in srgb, #000 24%, transparent);
}
.v2-card-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.v2-range-badge {
  display: inline-flex; align-items: center; min-height: 24px; padding: 2px 9px;
  border: 1px solid var(--v2-accent-border); border-radius: 999px;
  background: var(--v2-accent-soft); color: var(--ios-accent);
  font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.v2-diverging-list { display: flex; flex-direction: column; gap: 0; }
.v2-diverging-columns-head,
.v2-diverging-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, .35fr) minmax(150px, .35fr);
  align-items: center; gap: 20px;
}
.v2-diverging-columns-head {
  padding: 0 2px 8px; font-size: 10px; font-weight: 600; letter-spacing: .08em;
  color: var(--ios-text-4); text-transform: uppercase;
}
.v2-diverging-columns-head span:not(:first-child) { text-align: right; }
.v2-diverging-row {
  min-width: 0; padding: 10px 2px;
  border-top: 1px solid color-mix(in srgb, var(--ios-card-stroke) 72%, transparent);
}
.v2-diverging-name { font-size: 13px; font-weight: 650; color: var(--ios-text); }
.v2-net-value {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 8px;
  font-family: 'IBM Plex Mono', ui-monospace, monospace; text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.v2-net-value strong { font-size: 16px; font-weight: 600; }
.v2-dd-value {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; min-width: 0;
  color: var(--ios-negative); text-align: right;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.v2-dd-value strong { font-size: 14px; font-weight: 600; }
.v2-mobile-label {
  display: none; color: var(--ios-text-4);
  font-family: 'Space Grotesk', 'Leelawadee UI', Tahoma, sans-serif;
  font-size: 10px; font-weight: 500;
}
.v2-diverging-net-loss-text { color: color-mix(in srgb, var(--ios-negative) 55%, #ff9f43 45%); }
.v2-diverging-net-text { color: var(--ios-positive); }
.v2-money-zero { color: var(--ios-text-3) !important; }

.v2-bar-tooltip { cursor: help; outline: none; }
.v2-bar-tooltip::after {
  content: attr(data-tooltip); position: absolute; z-index: 30; left: 50%; bottom: calc(100% + 8px);
  width: max-content; max-width: min(280px, 78vw); padding: 7px 9px; border-radius: 7px;
  background: color-mix(in srgb, var(--ios-card-fill) 94%, #000 6%);
  border: 1px solid var(--ios-card-stroke); box-shadow: 0 8px 24px rgba(0,0,0,.28);
  color: var(--ios-text); font-family: 'Space Grotesk', 'Leelawadee UI', Tahoma, sans-serif;
  font-size: 11px; font-weight: 500; line-height: 1.4; white-space: normal;
  opacity: 0; pointer-events: none; transform: translate(-50%, 3px); transition: opacity .15s, transform .15s;
}
.v2-bar-tooltip:hover::after, .v2-bar-tooltip:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

.v2-breakdown-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 18px; margin: 18px 0;
}
.v2-breakdown-card {
  position: relative; background: var(--ios-card-bg); border: 1px solid var(--ios-card-stroke); border-radius: 14px;
  padding: 18px 20px; display: flex; flex-direction: column; gap: 10px;
  cursor: pointer; transition: border-color .15s;
}
.v2-breakdown-card:hover { border-color: var(--v2-hover-border); }
.v2-breakdown-title { font-size: 13px; font-weight: 650; color: var(--ios-text); }
.v2-breakdown-meta, .v2-breakdown-ea { font-size: 12px; line-height: 1.5; color: var(--ios-text-3); }
.v2-breakdown-ea { color: var(--ios-text-3); }
.v2-breakdown-progress-label {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 2px;
  font-size: 11px; line-height: 1.4; color: var(--ios-text-3);
}
.v2-breakdown-progress-label span:last-child {
  font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums;
}
.v2-breakdown-card .v2-bar-track { position: relative; overflow: visible; background: var(--v2-soft-track); }

.v2-single-grid {
  display: grid; grid-template-columns: minmax(0, 2.05fr) minmax(0, 1fr);
  gap: 18px; align-items: start;
}
.v2-single-grid > * { min-width: 0; }
.v2-single-grid .v2-card { margin-bottom: 0; }
.v2-equity-card { padding-bottom: 12px; }
.v2-equity-readout { text-align: right; font-family: 'IBM Plex Mono', monospace; }
.v2-equity-value { font-size: 22px; }
.v2-equity-date { font-size: 12px; color: var(--ios-text-2); margin-top: 3px; }
.v2-equity-chart-wrap { position: relative; cursor: crosshair; }

.v2-open-list { display: flex; flex-direction: column; gap: 1px; background: var(--ios-card-stroke); border-radius: 10px; overflow: hidden; }
.v2-open-row { background: var(--ios-card-bg); padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.v2-open-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.v2-side-badge { font-size: 10px; font-weight: 600; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px; }
.v2-dim { color: var(--ios-text-2); }
.v2-empty { color: var(--ios-text-2); font-size: 13px; }

.v2-daily-bars { display: flex; align-items: stretch; gap: 6px; height: 178px; }
.v2-daily-col {
  flex: 1; min-width: 0; display: grid;
  grid-template-rows: 22px 64px 1px 64px 20px;
  text-align: center;
}
.v2-daily-value, .v2-daily-date {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'IBM Plex Mono', monospace;
}
.v2-daily-value { font-size: 10px; }
.v2-daily-date { font-size: 10px; color: var(--ios-text-2); padding-top: 5px; }
.v2-daily-half { display: flex; justify-content: center; }
.v2-daily-half-up { align-items: flex-end; }
.v2-daily-half-down { align-items: flex-start; }
.v2-daily-up { background: var(--ios-positive); opacity: .85; border-radius: 2px 2px 0 0; }
.v2-daily-mid { height: 1px; background: var(--ios-card-stroke); }
.v2-daily-down { background: var(--ios-negative); opacity: .85; border-radius: 0 0 2px 2px; }
.v2-daily-col:hover .v2-daily-up, .v2-daily-col:hover .v2-daily-down { opacity: 1; }

.v2-order-toggle {
  display: none;
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  border: 1px solid var(--ios-card-stroke);
  border-radius: 9px;
  background: var(--ios-card-fill);
  color: var(--ios-text);
  cursor: pointer;
}

.v2-command-card :is(.btn-group, .ea-action-status) { justify-content: flex-start; }

/* Reuses the order-book / ea-share classes shipped with the deals feature -
   kept unstyled here beyond making them readable on the v2 dark tokens. */
.v2-root .history-table th { color: var(--ios-accent); }
.v2-root .history-table td, .v2-root .history-table th { border-bottom-color: var(--ios-card-stroke); }
.v2-root .ea-name-btn { color: var(--ios-text); border-bottom-color: var(--ios-text-3); }
.v2-root .ea-name-btn:hover { color: var(--ios-accent); border-bottom-color: var(--ios-accent); }

.v2-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(5,6,8,0.72); backdrop-filter: blur(3px); z-index: 40;
}
.v2-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: var(--ios-bg); border-left: 1px solid var(--ios-card-stroke); z-index: 41;
  padding: 28px; overflow-y: auto; font-family: 'Space Grotesk', sans-serif; color: var(--ios-text);
}
.v2-drawer-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; }
.v2-drawer-eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ios-text-3); margin-bottom: 8px; }
.v2-drawer-symbol { font-family: 'IBM Plex Mono', monospace; font-size: 22px; }
.v2-drawer-close {
  cursor: pointer; width: 32px; height: 32px; border: 1px solid var(--ios-card-stroke); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: var(--ios-text-2); font-size: 15px;
  background: transparent;
}
.v2-drawer-close:hover { border-color: var(--v2-hover-border); color: var(--ios-text); }
.v2-drawer-pnl { font-family: 'IBM Plex Mono', monospace; font-size: 34px; margin-bottom: 26px; }
.v2-drawer-rows { display: flex; flex-direction: column; gap: 1px; background: var(--ios-card-stroke); border-radius: 10px; overflow: hidden; }
.v2-drawer-row { background: var(--ios-card-bg); padding: 13px 16px; display: flex; justify-content: space-between; gap: 16px; font-size: 12px; color: var(--ios-text-3); }
.v2-drawer-row span:last-child { color: var(--ios-text); text-align: right; }

@media (max-width: 900px) {
  .v2-single-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .v2-header { gap: 12px; margin-bottom: 14px; }
  .v2-title { font-size: 24px; }
  .v2-meta { font-size: 12px; }

  .v2-switchers {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 8px;
  }
  .v2-pill-divider { display: none; }
  #v2AcctPills, #v2RangePills {
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    padding-bottom: 4px;
  }
  .v2-pill {
    min-height: 44px;
    padding: 8px 13px;
  }

  .v2-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 16px;
  }
  .v2-kpi { min-width: 0; padding: 14px 12px; gap: 6px; }
  .v2-kpi-label { font-size: 10px; }
  .v2-kpi-value { font-size: clamp(19px, 6vw, 23px); overflow-wrap: anywhere; }
  .v2-kpi-sub { font-size: 11px; line-height: 1.35; color: var(--ios-text-2); }

  .v2-card { padding: 16px 14px; }
  .v2-card-sub { font-size: 12px; color: var(--ios-text-2); }
  .v2-diverging-columns-head { display: none; }
  .v2-diverging-row { grid-template-columns: 1fr; gap: 8px; padding: 12px 0; }
  .v2-diverging-name { font-size: 13px; }
  .v2-net-value, .v2-dd-value { justify-content: flex-start; text-align: left; }
  .v2-net-value strong { margin-left: auto; font-size: 15px; }
  .v2-dd-value strong { margin-left: auto; font-size: 14px; }
  .v2-mobile-label { display: inline; }
  .v2-breakdown-grid { grid-template-columns: 1fr; gap: 12px; }
  .v2-legend-wrap {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .v2-daily-bars { gap: 3px; }
  .v2-daily-value, .v2-daily-date { font-size: 9px; }
  .v2-order-toggle { display: block; }
}

/* =====================================================================
   Market overview + basket drawdown (chunk B)
   ===================================================================== */
.v2-market-chart { margin-top: 14px; overflow-x: auto; }
.v2-market-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 11px; color: var(--ios-text-3);
}
.v2-market-legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.v2-mk { width: 8px; height: 8px; flex: none; display: inline-block; }
/* Entry markers echo the triangles drawn on the chart, exits echo the rings. */
.v2-mk-buy  { border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 7px solid #4FD08A; height: 0; }
.v2-mk-sell { border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 7px solid #F0605E; height: 0; }
.v2-mk-win  { border-radius: 50%; border: 2px solid #E8B54D; }
.v2-mk-loss { border-radius: 50%; border: 2px solid #F0605E; }

.v2-basket-value {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 30px; font-weight: 500; letter-spacing: -0.02em;
  color: #E8B54D; margin-top: 14px;
}
.v2-basket-pct { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 13px; color: var(--ios-text-2); margin-top: 6px; }
.v2-basket-meta { font-size: 12px; color: var(--ios-text-3); margin-top: 10px; line-height: 1.5; }
