/* ══════════════════════════════════════════
   Variables
══════════════════════════════════════════ */
:root {
  --bg:           #0f172a;
  --surface:      #1e293b;
  --surface-2:    #2d3f55;
  --border:       #334155;
  --primary:      #3b82f6;
  --primary-dk:   #2563eb;
  --success:      #10b981;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --indigo:       #6366f1;
  --text:         #f1f5f9;
  --muted:        #94a3b8;
  --r:            10px;
  --r-sm:         6px;
  --hh:           60px;        /* header height */
  --shadow:       0 4px 20px rgba(0,0,0,.35);
}

/* ══════════════════════════════════════════
   Reset
══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}
html[lang="fa"] body {
  font-family: 'Vazirmatn', Tahoma, 'B Nazanin', system-ui, sans-serif;
  line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
img { display: block; }
input, select, button, textarea { font-family: inherit; font-size: inherit; outline: none; }
select { -webkit-appearance: none; appearance: none; }

/* ══════════════════════════════════════════
   Header
══════════════════════════════════════════ */
.header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--hh);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.01em;
  flex-shrink: 0;
}

.header-mid {
  flex: 1;
  display: flex;
  justify-content: center;
}

.selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  min-width: 200px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.running { background: var(--success); box-shadow: 0 0 7px var(--success); }
.status-dot.stopped { background: var(--danger); }

#robotSelector {
  background: transparent;
  color: var(--text);
  border: none;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-chip {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
  white-space: nowrap;
}

/* ══════════════════════════════════════════
   Main
══════════════════════════════════════════ */
#mainContent {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ══════════════════════════════════════════
   Buttons
══════════════════════════════════════════ */
button { cursor: pointer; border: none; border-radius: var(--r-sm); transition: opacity .15s, background .15s, transform .1s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary  { background: var(--primary); color: #fff; padding: 9px 18px; font-weight: 500; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dk); }

.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 9px 18px; font-weight: 500; }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { background: var(--danger); color: #fff; padding: 9px 18px; font-weight: 500; }
.btn-danger:hover:not(:disabled) { opacity: .85; }

.btn-ghost { background: transparent; color: var(--muted); padding: 9px 18px; }
.btn-ghost:hover { color: var(--text); }

.btn-sm { padding: 8px 12px; font-size: 0.83rem; min-height: 36px; }
.full { width: 100%; }

.icon-btn { background: transparent; color: var(--muted); padding: 8px 12px; font-size: 1rem; border-radius: 4px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ══════════════════════════════════════════
   Form Elements
══════════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.82rem; color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 0.78rem; }
.error-msg { color: var(--danger); font-size: 0.82rem; min-height: 16px; }

.field input,
.field select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  transition: border-color .15s;
  width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--primary); }
.field select option { background: var(--surface); }

/* ══════════════════════════════════════════
   Overlay + Modals
══════════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

/* Auth card */
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow);
}
.auth-logo { display: flex; align-items: center; gap: 12px; }
.auth-logo h1 { font-size: 1.4rem; font-weight: 700; }

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  padding: 7px;
  border-radius: 4px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.auth-tab.active { background: var(--surface); color: var(--text); }

form { display: flex; flex-direction: column; gap: 14px; }

/* General modal card */
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  width: 100%;
  max-width: 620px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sm { max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.modal-sm h3 { font-size: 1.05rem; }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-head h2 { font-size: 1.05rem; font-weight: 600; }

#createStep1, #createStep2 {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 4px;
}

/* ══════════════════════════════════════════
   Live Price Bar
══════════════════════════════════════════ */
.live-price-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 18px;
  position: relative;
  overflow: hidden;
}
.live-price-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--success), var(--primary), var(--danger));
  animation: shimmer 3s linear infinite;
  background-size: 200% 100%;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.live-price-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  text-align: center;
}
.lp-label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.lp-val {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: color .3s;
}
.lp-val.bid  { color: var(--danger); }
.lp-val.ask  { color: var(--success); }

.live-price-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 16px;
}

.live-price-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--success);
  font-weight: 600;
  position: absolute;
  top: 8px;
  right: 10px;
}
.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.7); }
}

/* flash animation on price update */
.lp-val.flash { animation: flashVal .4s ease; }
@keyframes flashVal {
  0%   { opacity: .3; }
  100% { opacity: 1; }
}

/* ══════════════════════════════════════════
   Profit Hint
══════════════════════════════════════════ */
.profit-hint {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
}
.ph-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
}
.ph-label {
  color: var(--muted);
  white-space: nowrap;
}
.ph-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ph-val.green { color: var(--success); }
.ph-val.amber { color: var(--warning); }
.ph-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ph-range-bar {
  width: 60px;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--warning), var(--success));
}

/* ══════════════════════════════════════════
   Preview
══════════════════════════════════════════ */
.preview-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.p-stat {
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 12px 14px;
}
.p-stat .p-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.p-stat .p-val { font-size: 1rem; font-weight: 600; }

.preview-table-wrap { max-height: 220px; overflow-y: auto; border-radius: var(--r-sm); border: 1px solid var(--border); }

/* ══════════════════════════════════════════
   Stats Grid
══════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 26px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
}
.stat-card .sc-label { font-size: 0.78rem; color: var(--muted); font-weight: 500; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .sc-val { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.stat-card .sc-val.green { color: var(--success); }
.stat-card .sc-val.red   { color: var(--danger); }
.stat-card .sc-val.blue  { color: var(--primary); }
.stat-card .sc-sub { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

/* ══════════════════════════════════════════
   Tabs
══════════════════════════════════════════ */
.tabs-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 2px;
  overflow-x: auto;
}
.tab {
  background: transparent;
  color: var(--muted);
  padding: 10px 20px;
  font-size: 0.88rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover:not(.active) { color: var(--text); }

/* ══════════════════════════════════════════
   Tables
══════════════════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
}
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead th {
  background: var(--bg);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }

.no-data {
  color: var(--muted);
  text-align: center;
  padding: 48px 20px;
  font-size: 0.9rem;
}

/* ══════════════════════════════════════════
   Badges
══════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.b-buy     { background: rgba(59,130,246,.15); color: #60a5fa; }
.b-sell    { background: rgba(16,185,129,.15); color: #34d399; }
.b-open    { background: rgba(245,158,11,.15); color: #fbbf24; }
.b-filled  { background: rgba(99,102,241,.15); color: #a5b4fc; }
.b-closed  { background: rgba(16,185,129,.12); color: #6ee7b7; }
.b-running { background: rgba(16,185,129,.15); color: #34d399; }
.b-stopped { background: rgba(239,68,68,.15); color: #fca5a5; }

/* ══════════════════════════════════════════
   Profit Colors
══════════════════════════════════════════ */
.profit-pos { color: var(--success); font-weight: 600; }
.profit-neg { color: var(--danger); font-weight: 600; }
.profit-zero { color: var(--muted); }

/* ══════════════════════════════════════════
   Center States
══════════════════════════════════════════ */
.center-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 20px;
  text-align: center;
}
.empty-icon { font-size: 3.5rem; line-height: 1; }
.center-state h3 { font-size: 1.15rem; }
.center-state p { max-width: 280px; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   Toast
══════════════════════════════════════════ */
#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  max-width: 300px;
  pointer-events: auto;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--primary); }

:root { --toast-slide: 30px; }
[dir="rtl"] { --toast-slide: -30px; }
@keyframes toastIn { from { transform: translateX(var(--toast-slide)); opacity: 0; } to { transform: none; opacity: 1; } }

[dir="rtl"] #toastContainer { right: auto; left: 20px; }
[dir="rtl"] .toast.success { border-left: none; border-right: 3px solid var(--success); }
[dir="rtl"] .toast.error   { border-left: none; border-right: 3px solid var(--danger); }
[dir="rtl"] .toast.info    { border-left: none; border-right: 3px solid var(--primary); }

/* ══════════════════════════════════════════
   Responsive — Tablet
══════════════════════════════════════════ */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .header { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .header-mid { order: 3; width: 100%; justify-content: flex-start; }
  .selector-wrap { width: 100%; }
  #robotSelector { width: 100%; }
  .user-chip { display: none; }
  .header-actions { gap: 6px; }

  #mainContent { padding: 14px 14px 40px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
  .stat-card { padding: 14px 16px; }
  .stat-card .sc-val { font-size: 1.1rem; }

  .form-grid-2 { grid-template-columns: 1fr; }
  .preview-summary { grid-template-columns: 1fr 1fr; }

  .auth-card { padding: 24px 18px; }
  .modal-card { border-radius: var(--r) var(--r) 0 0; align-self: flex-end; max-height: 88vh; }
  .overlay { align-items: flex-end; padding: 0; }
  .auth-card { align-self: center; border-radius: var(--r); }

  #createStep1, #createStep2 { padding: 16px 18px 20px; }
  .modal-head { padding: 14px 18px; }

  thead th, tbody td { padding: 8px 10px; }
  .tab { padding: 9px 14px; }
}

/* ══════════════════════════════════════════
   Responsive — Mobile
══════════════════════════════════════════ */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .preview-summary { grid-template-columns: 1fr; }
  .header-actions .btn-sm { padding: 5px 8px; font-size: 0.78rem; }
  .btn-primary.btn-sm, .btn-danger.btn-sm { padding: 5px 10px; }
}

/* ══════════════════════════════════════════
   Balance Hint
══════════════════════════════════════════ */
.balance-hint {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
  font-size: 0.78rem;
  min-height: 22px;
}
.balance-label { color: var(--muted); }
.balance-sep   { color: var(--muted); }
.balance-amount {
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.balance-currency {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 600;
}
.balance-locked-wrap { color: var(--muted); font-size: 0.73rem; }
.btn-use-all {
  background: rgba(59,130,246,.13);
  color: var(--primary);
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 0.73rem;
  font-weight: 600;
  border: 1px solid rgba(59,130,246,.25);
  cursor: pointer;
  transition: background .15s;
  font-family: inherit;
}
.btn-use-all:hover { background: rgba(59,130,246,.25); }

/* ══════════════════════════════════════════
   Price Chart
══════════════════════════════════════════ */
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 10px;
  flex-wrap: wrap;
}
.chart-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
}
.chart-res-group {
  display: flex;
  gap: 4px;
}
.chart-res {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.chart-res:hover  { background: var(--hover); color: var(--text); }
.chart-res.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ══════════════════════════════════════════
   RTL Overrides
══════════════════════════════════════════ */

/* Header: flip brand ↔ actions */
[dir="rtl"] .header        { flex-direction: row-reverse; }
[dir="rtl"] .header-brand  { flex-direction: row-reverse; }
[dir="rtl"] .header-actions { flex-direction: row-reverse; }
[dir="rtl"] .selector-wrap { flex-direction: row-reverse; }

/* Modals */
[dir="rtl"] .modal-head    { flex-direction: row-reverse; }
[dir="rtl"] .modal-actions { flex-direction: row-reverse; }
[dir="rtl"] .modal-sm      { text-align: right; }

/* Auth */
[dir="rtl"] .auth-card     { text-align: right; }
[dir="rtl"] .auth-logo     { flex-direction: row-reverse; }

/* Stats */
[dir="rtl"] .stat-card     { text-align: right; }

/* Form fields */
[dir="rtl"] .field         { text-align: right; }
[dir="rtl"] .error-msg     { text-align: right; }

/* Live price badge (absolute positioned) */
[dir="rtl"] .live-price-badge { right: auto; left: 10px; }

/* Profit hint rows */
[dir="rtl"] .ph-row        { flex-direction: row-reverse; }
[dir="rtl"] .ph-range      { flex-direction: row-reverse; }

/* Preview stat cards */
[dir="rtl"] .p-stat        { text-align: right; }

/* Tables: keep data LTR for readability */
[dir="rtl"] .table-wrap    { direction: ltr; }

/* Center states stay centered */
[dir="rtl"] .center-state  { text-align: center; }

/* Tabs: right-aligned text */
[dir="rtl"] .tabs-bar      { flex-direction: row-reverse; }

/* Mobile RTL: selector wrap full-width still works */
@media (max-width: 768px) {
  [dir="rtl"] .header-mid  { justify-content: flex-end; }
}

/* ══════════════════════════════════════════
   Subscription Modal
══════════════════════════════════════════ */
.modal-sub { max-width: 560px; width: 100%; }

.sub-current {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: .85rem;
  color: var(--muted);
}
.sub-current .sub-plan { color: var(--success); font-weight: 600; }
.sub-current .sub-exp  { color: var(--muted); }

.plan-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
@media (max-width: 520px) {
  .plan-cards { grid-template-columns: 1fr; }
}

.plan-card {
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.plan-card:hover { border-color: var(--primary); background: rgba(59,130,246,.05); }
.plan-card.selected { border-color: var(--primary); background: rgba(59,130,246,.1); }

.plan-card .plan-name  { font-weight: 700; font-size: 1rem; }
.plan-card .plan-limit { font-size: .8rem; color: var(--muted); }
.plan-card .plan-price { font-size: 1.1rem; font-weight: 700; color: var(--primary); margin-top: 6px; }
.plan-card .plan-sub   { font-size: .75rem; color: var(--muted); }

.plan-pay-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  margin-top: 4px;
}
.plan-pay-btn:hover:not(:disabled) { background: var(--primary-dk); }
.plan-pay-btn:disabled { opacity: .5; cursor: default; }

/* Sub button in header */
#subBtn { font-size: .78rem; }
#subBtn.sub-active { color: var(--success); border-color: var(--success); }
#subBtn.sub-expired { color: var(--danger); border-color: var(--danger); }

/* Auto-rebalance warning in preview */
.rebalance-warning {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .4);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  margin: 12px 0 4px;
  font-size: .85rem;
  line-height: 1.6;
  color: var(--text);
}
.rebalance-warning .rw-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }
.rebalance-warning strong { color: var(--warning); }

/* Phone & OTP inputs: always LTR regardless of page direction */
#loginPhone, #regPhone, #loginOtp, #regOtp {
  direction: ltr;
  text-align: left;
}

/* ══════════════════════════════════════════
   History View
══════════════════════════════════════════ */
.history-view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.history-view-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 900px) {
  .history-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .history-grid { grid-template-columns: 1fr; }
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color .15s;
}
.history-card:hover { border-color: var(--primary); }

.hc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.hc-title-group { display: flex; flex-direction: column; gap: 3px; }
.hc-symbol { font-weight: 700; font-size: 1rem; }
.hc-name   { font-size: 0.78rem; color: var(--muted); }

.hc-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}
.hc-row    { display: flex; flex-direction: column; gap: 2px; }
.hc-label  { font-size: 0.72rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.hc-val    { font-size: 0.88rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.hc-actions {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  justify-content: flex-end;
}

/* b-sl badge for stop-loss triggered */
.b-sl { background: rgba(239,68,68,.2); color: #f87171; }

/* ── History Detail Modal ─────────────────────────── */
.modal-xl {
  max-width: 900px;
  max-height: 90vh;
}
.modal-body-pad {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* RTL history */
[dir="rtl"] .history-view-header { flex-direction: row-reverse; }
[dir="rtl"] .hc-top              { flex-direction: row-reverse; }
[dir="rtl"] .hc-title-group      { text-align: right; }
[dir="rtl"] .hc-row              { text-align: right; }
[dir="rtl"] .hc-actions          { justify-content: flex-start; }
[dir="rtl"] #historyTabsBar      { flex-direction: row-reverse; }
