/* ChartFX PWA — port of SMCFX_CHART_TV theming (QSS palette) */
:root, [data-theme="dark"] {
  --base: #171a1f;
  --alt: #1f232b;
  --text: #e6edf3;
  --border: #3b4450;
  --accent: #58a6ff;
  --hint: #9aa4b2;
  --btn-bg: rgba(255,255,255,0.04);
  --btn-hover: rgba(255,255,255,0.08);
  --bg-window: #0b0f14;
  --up: #26a69a;
  --down: #ef5350;
  --panel: #171a1f;
}
[data-theme="light"] {
  --base: #ffffff;
  --alt: #f3f4f6;
  --text: #111827;
  --border: #d1d5db;
  --accent: #2563eb;
  --hint: #6b7280;
  --btn-bg: rgba(0,0,0,0.04);
  --btn-hover: rgba(0,0,0,0.07);
  --bg-window: #f8fafc;
  --up: #26a69a;
  --down: #ef5350;
  --panel: #ffffff;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg-window);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  overflow: hidden;
}
#app { height: 100%; }

/* ---------- main shell ---------- */
.main-window { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  background: var(--base);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.brand-name { letter-spacing: .5px; }
.brand-ver { color: var(--hint); font-size: 11px; font-weight: 400; }
.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }

.workspace { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 190px; min-width: 140px;
  background: var(--base);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 8px; gap: 8px;
}
.symbol-list { overflow-y: auto; flex: 1; }
.symbol-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  color: var(--text);
}
.symbol-row:hover { background: var(--btn-hover); }
.sym-price { color: var(--hint); font-variant-numeric: tabular-nums; }

.chart-grid {
  flex: 1; display: grid; gap: 6px; padding: 6px; min-width: 0; min-height: 0;
  grid-template-columns: repeat(1, minmax(0,1fr));
}
.chart-grid.cols-1 { grid-template-columns: repeat(1, minmax(0,1fr)); grid-template-rows: 1fr; }
.chart-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); grid-template-rows: 1fr; }
.chart-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.chart-grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); grid-template-rows: repeat(2, minmax(0,1fr)); }

/* ---------- chart panel ---------- */
.chart-panel {
  display: flex; flex-direction: column;
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden; position: relative; min-width: 0; min-height: 0;
}
.chart-panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chart-sym-wrap { display: flex; align-items: center; gap: 8px; }
.chart-symbol { font-weight: 800; font-size: 14px; letter-spacing: .4px; }
.chart-status { display: inline-flex; align-items: center; gap: 5px; color: var(--hint); font-size: 11px; }
.led { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.led-on { background: #2ea043; box-shadow: 0 0 6px #2ea043; }
.led-wait { background: #d29922; box-shadow: 0 0 6px #d29922; }
.led-off { background: #6e7681; }
.chart-tf-bar { display: flex; gap: 2px; flex-wrap: wrap; }
.cfx-btn-tf.active { border-color: var(--accent); color: var(--accent); }
.chart-head-right { margin-left: auto; }
.ohlc { font-variant-numeric: tabular-nums; font-size: 11px; display: flex; gap: 8px; }
.ohlc .up { color: var(--up); }
.ohlc .down { color: var(--down); }

.chart-body { flex: 1; position: relative; min-height: 0; }
.chart-body > .tv-lightweight-charts { position: absolute; inset: 0; }
.drawings-canvas { position: absolute; inset: 0; }

.chart-tools {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.tool-btn.active { border-color: var(--accent); color: var(--accent); }
.cfx-type-sel { width: 110px; }

.trade-toolbar {
  display: flex; gap: 6px; align-items: center;
  padding: 4px 8px; border-top: 1px solid var(--border);
  background: var(--alt);
}
.trade-volume, .trade-sl, .trade-tp { width: 78px; }
.trade-buy { background: rgba(38,166,154,.18); border-color: var(--up); color: var(--up); font-weight: 700; }
.trade-sell { background: rgba(239,83,80,.18); border-color: var(--down); color: var(--down); font-weight: 700; }

.statusbar {
  display: flex; gap: 14px; align-items: center;
  padding: 4px 12px; background: var(--base);
  border-top: 1px solid var(--border);
  color: var(--hint); font-size: 11px;
}
.status-item.feed-online { color: #2ea043; }

/* ---------- buttons / inputs ---------- */
.cfx-btn {
  min-height: 26px; padding: 3px 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--btn-bg); color: var(--text);
  cursor: pointer; font-size: 12px;
}
.cfx-btn:hover { background: var(--btn-hover); }
.cfx-btn:focus { outline: none; border-color: var(--accent); }
.cfx-btn-primary { border-color: var(--accent); color: var(--accent); }
.cfx-btn-icon { min-width: 26px; padding: 3px 8px; }
.cfx-input {
  min-height: 26px; padding: 3px 8px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--alt); color: var(--text);
  font-size: 12px;
}
.cfx-input:focus { outline: none; border-color: var(--accent); }
.symbol-search { width: 100%; }

/* ---------- dialogs ---------- */
.cfx-dialog-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.cfx-dialog {
  background: var(--alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  max-height: 92vh; overflow: auto;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.cfx-dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-weight: 800;
}
.cfx-dialog-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cfx-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cfx-form-col { flex-direction: column; align-items: stretch; }
.cfx-table { width: 100%; border-collapse: collapse; }
.cfx-table th, .cfx-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px; text-align: left;
}
.cfx-table tr.selected td { background: var(--btn-hover); }
.cfx-table th { font-weight: 700; }
.cfx-pre {
  background: var(--base); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; max-height: 50vh; overflow: auto; font-size: 11px;
}
.cfx-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.cfx-list-row { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); padding: 6px 4px; }
.mm-stretch { flex: 1; }
.pos { color: var(--up); }

/* ---------- money management dialog (mm* ids from QSS port) ---------- */
.mm-dialog { background: var(--alt); }
.mm-root { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.mm-title { font-weight: 800; font-size: 14px; }
.mm-section-frame {
  background: var(--base);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px;
}
.mm-section-layout { display: flex; flex-direction: column; gap: 10px; }
.mm-section-title { font-weight: 700; font-size: 13px; }
.mm-section-hint { color: var(--hint); font-size: 11px; }
.mm-grid { display: grid; gap: 8px 10px; align-items: center; }
.mm-grid-head { font-weight: 700; }
.mm-rowlbl { color: var(--text); }
.mm-hint-cell { color: var(--hint); font-size: 11px; }
.mm-center { display: flex; justify-content: center; }
.mm-mode-lbl { color: var(--text); }
.mm-spin {
  min-height: 28px; padding: 2px 8px; width: 100%;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--alt); color: var(--text);
}
.mm-spin:focus { outline: none; border-color: var(--accent); }
.mm-autoexit-top { display: flex; align-items: center; gap: 8px; }
.mm-round-mode { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mm-radio-lbl { color: var(--text); }
.mm-autoexit-body { display: flex; gap: 10px; align-items: flex-start; }
.mm-table { border: 1px solid var(--border); border-radius: 8px; border-collapse: collapse; min-width: 320px; max-width: 520px; }
.mm-table th, .mm-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; }
.mm-table th { font-weight: 700; }
.mm-table tr.selected td { background: var(--btn-hover); }
.mm-spin-cell { width: 110px; }
.mm-autoexit-buttons { display: flex; flex-direction: column; gap: 8px; }
.mm-footer { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- switch (theme_toggle port) ---------- */
.cfx-switch { position: relative; display: inline-block; width: 34px; height: 18px; }
.cfx-switch input { opacity: 0; width: 0; height: 0; }
.cfx-switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 999px; transition: .15s;
}
.cfx-switch-slider:before {
  content: ""; position: absolute; height: 14px; width: 14px;
  left: 2px; top: 2px; background: var(--text); border-radius: 50%; transition: .15s;
}
.cfx-switch input:checked + .cfx-switch-slider { background: var(--accent); }
.cfx-switch input:checked + .cfx-switch-slider:before { transform: translateX(16px); }

/* ---------- replay ---------- */
.replay-progress { color: var(--hint); font-variant-numeric: tabular-nums; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* mobile responsiveness */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .chart-grid.cols-2, .chart-grid.cols-3, .chart-grid.cols-4 { grid-template-columns: 1fr; grid-template-rows: none; }
  .topbar-actions { margin-left: 0; }
}

/* ---------- symbol catalog sidebar (feed layer v2) ---------- */
.symbol-group-header {
  padding: 8px 10px 3px; font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--hint); border-top: 1px solid var(--border); margin-top: 4px;
}
.symbol-row.pinned .sym-name { color: var(--accent); font-weight: 600; }
.symbol-row.domestic { direction: rtl; }
.symbol-row.domestic .sym-name { font-size: 11px; }
.symbol-row.domestic { direction: ltr; }
.symbol-row.domestic .sym-name { direction: rtl; unicode-bidi: embed; }
.net-ok { color: #26a69a; }
.net-ir { color: #FFD54A; }
.net-off { color: #ef5350; }
.lat-good { color: #26a69a; }
.lat-bad { color: #ef5350; }

/* ---------- plan dialogs (plan_dialog.py + reply_plan_dialog.py port) ---------- */
.plan-dialog { max-width: 96vw; }
.plan-backdrop { z-index: 900; }
.plan-body { gap: 10px; min-height: 220px; }
.plan-list { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 6px; min-height: 180px; background: var(--panel); }
.plan-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.plan-item:hover { background: var(--btn-hover); }
.plan-item.selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.plan-item-sub { color: var(--hint); font-size: 11px; direction: rtl; }
.plan-btnrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.plan-right { justify-content: flex-end; }
.plan-stretch { flex: 1; }
.plan-gap { width: 12px; }
.plan-warn-text { color: #EF4444; font-size: 13px; }
.reply-notice { font-size: 16px; font-weight: 700; text-align: center; }
.plan-form-label { font-size: 12px; color: var(--hint); }
.plan-name-input { text-align: center; }
.plan-combo { text-align: center; }
.plan-groupbox { border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.plan-group-title { font-weight: 600; font-size: 12px; }
.plan-sep { height: 1px; background: var(--border); }
.reply-top { display: flex; flex-direction: column; gap: 8px; }
.reply-cols { display: flex; gap: 10px; }
.reply-left { flex: 3; }
.reply-right { flex: 2; }
.reply-listbox { flex: 1; min-height: 200px; }
.plan-charts-title { font-weight: 600; font-size: 12px; }
.reply-charts-wrap { }
.reply-charts-scroll { max-height: 190px; min-height: 130px; overflow: auto; }
.reply-charts-grid { display: grid; grid-template-columns: 24px 1fr 110px; gap: 6px 10px; align-items: center; }
.reply-charts-hdr { font-size: 11px; color: var(--hint); }
.reply-charts-idx { text-align: center; font-size: 12px; color: var(--hint); }
.reply-start-grid { display: grid; grid-template-columns: auto 1fr 96px; gap: 8px 10px; align-items: center; }
.reply-spin { text-align: center; width: 90px; }
.plan-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.plan-table th { padding: 6px 8px; text-align: center; color: var(--hint); font-weight: 600; border-bottom: 1px solid var(--border); }
.plan-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.plan-table tr.selected td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.plan-table tr.filtered-out { display: none; }
.plan-table-wrap { flex: 1; overflow: auto; max-height: 260px; border: 1px solid var(--border); border-radius: 6px; }
.plan-table tr:hover td { background: var(--btn-hover); }
