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

:root {
  --bg:       #0b0f19;
  --bg2:      #111827;
  --bg3:      #1a2235;
  --bg4:      #1f2d45;
  --border:   #243049;
  --border2:  #2d3d5a;
  --text:     #e2e8f0;
  --muted:    #8899b4;
  --muted2:   #b8c8dc;
  --green:    #22c55e;
  --green-bg: #052e16;
  --red:      #ef4444;
  --red-bg:   #1f0505;
  --blue:     #3b82f6;
  --blue-bg:  #0f1f3d;
  --orange:   #f59e0b;
  --purple:   #a855f7;
  --accent:   #3b82f6;
  --accent-hover: #2563eb;
  --run-bg:   #16a34a;
  --run-hover:#15803d;
  --radius:   8px;
  --radius-sm:5px;
}

body.light {
  --bg:       #f0f4f8;
  --bg2:      #ffffff;
  --bg3:      #e8edf3;
  --bg4:      #dde3ec;
  --border:   #c8d3e0;
  --border2:  #b5c2d4;
  --text:     #1a2235;
  --muted:    #64748b;
  --muted2:   #475569;
  --green:    #16a34a;
  --green-bg: #dcfce7;
  --red:      #dc2626;
  --red-bg:   #fee2e2;
  --blue:     #2563eb;
  --blue-bg:  #dbeafe;
  --orange:   #d97706;
  --purple:   #7c3aed;
  --accent:   #2563eb;
  --accent-hover: #1d4ed8;
  --run-bg:   #16a34a;
  --run-hover:#15803d;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ══════════════════════════════════════════════════
   TOP NAVBAR
══════════════════════════════════════════════════ */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: 0.3px;
}
.nav-brand .logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; color: #fff;
}
.nav-status { display: flex; align-items: center; gap: 10px; }

/* ══════════════════════════════════════════════════
   BODY LAYOUT
══════════════════════════════════════════════════ */
#body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ══════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════ */
#sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px 12px;
  gap: 0;
}

.s-section { margin-bottom: 18px; }

.s-head {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 4px;
  margin-bottom: 8px;
}

.s-field { margin-bottom: 8px; }
.s-field label {
  display: block;
  font-size: 11px;
  color: var(--muted2);
  margin-bottom: 4px;
}
.s-field input,
.s-field select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 12px;
  transition: border-color 0.15s;
}
.s-field input:focus,
.s-field select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg4);
}
.s-field select option { background: var(--bg3); }
.s-note {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}

.upload-box {
  border: 1px dashed var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg3);
}
.upload-box:hover { border-color: var(--accent); background: var(--bg4); }
.upload-box input { display: none; }
.upload-box .ub-icon { font-size: 18px; margin-bottom: 4px; }
.upload-box .ub-text { font-size: 11px; color: var(--muted2); }
.upload-box .ub-file { font-size: 11px; color: var(--green); margin-top: 3px; font-weight: 600; }

/* Trade Mode Toggle */
.trade-mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 100%;
}
.tm-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted2);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tm-btn:not(:last-child) { border-right: 1px solid var(--border2); }
.tm-btn:hover { background: var(--bg3); color: var(--text); }
.tm-btn.active { background: var(--accent); color: #fff; }

.btn-sample {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--muted2);
  border-radius: var(--radius-sm);
  padding: 6px 0;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 6px;
}
.btn-sample:hover { border-color: var(--accent); color: var(--accent); background: var(--blue-bg); }

.s-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0 16px; }

.btn-run {
  width: 100%;
  background: var(--run-bg);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}
.btn-run:hover { background: var(--run-hover); }
.btn-run:disabled { background: var(--bg4); color: var(--muted); cursor: not-allowed; }

/* ══════════════════════════════════════════════════
   MAIN AREA
══════════════════════════════════════════════════ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--bg);
}

/* ══════════════════════════════════════════════════
   RISK PANELS BAR
══════════════════════════════════════════════════ */
#risk-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

.rp {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
}
.rp:last-child { border-right: none; }

.rp-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.rp-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--blue-bg);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 6px;
}
.rp-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
  text-transform: uppercase;
}

.rp-info {
  font-size: 10px;
  color: var(--muted);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 8px;
  line-height: 1.6;
}
.rp-info b { color: var(--blue); }

.rp-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.rp-row select,
.rp-row input {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  transition: border-color 0.15s;
}
.rp-row select { flex: 1.4; }
.rp-row input  { flex: 1; }
.rp-row input.sm { flex: 0.7; }
.rp-row select:focus,
.rp-row input:focus  { outline: none; border-color: var(--accent); }

.tsl-enable {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--muted2);
}
input[type="checkbox"] {
  accent-color: var(--green);
  width: 13px; height: 13px;
  cursor: pointer;
}

/* ══════════════════════════════════════════════════
   REPORT AREA
══════════════════════════════════════════════════ */
#report {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rep-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  user-select: none;
}
.rep-header:hover { background: var(--bg3); }
.rep-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.rep-actions { display: flex; align-items: center; gap: 10px; }
.rep-arrow {
  font-size: 11px;
  color: var(--muted2);
  transition: transform 0.25s;
}
.rep-arrow.open { transform: rotate(0deg); }
.rep-arrow:not(.open) { transform: rotate(-90deg); }

.rep-slide {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.35s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.rep-slide.open { max-height: 2000px; }

.badge {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
}
.badge-success { background: var(--green-bg); color: var(--green); border: 1px solid #166534; }
.badge-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #7f1d1d; }
.badge-running { background: var(--blue-bg);  color: var(--blue);  border: 1px solid #1e3a5f; }

.btn-export {
  font-size: 11px;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.btn-export:hover { border-color: var(--accent); color: var(--accent); }
.btn-sample-nav {
  font-size: 11px;
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--muted2);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.btn-sample-nav:hover { border-color: var(--accent); color: var(--accent); background: var(--blue-bg); }

.btn-theme {
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}
.btn-theme:hover { border-color: var(--accent); background: var(--blue-bg); }

/* KPI section collapsible header */
.kpi-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.kpi-section-header:hover { background: var(--bg4); }
.kpi-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--muted2);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.kpi {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  white-space: nowrap;
}
.kpi-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted2);
  margin-bottom: 4px;
}
.kpi-val {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.kpi-sub {
  font-size: 10px;
  color: var(--muted2);
  margin-top: 3px;
}
.c-green  { color: var(--green); }
.c-red    { color: var(--red); }
.c-blue   { color: var(--blue); }
.c-orange { color: var(--orange); }
.c-text   { color: var(--text); }

/* Option signal blocks */
.opt-signal-row {
  display: flex;
  gap: 8px;
  margin: 6px 0;
}
.opt-signal-block {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.opt-signal-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.long-label  { color: var(--green); }
.short-label { color: var(--red); }
.opt-inline-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.opt-inline-field {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.opt-field-label {
  font-size: 10px;
  color: var(--muted2);
  white-space: nowrap;
  flex-shrink: 0;
}
/* Shared row: Expiry + SL on + TGT on */
.opt-shared-row { gap: 16px; align-items: center; }
.opt-shared-select { width: 150px; flex-shrink: 0; }
.opt-shared-toggle { width: auto; flex-shrink: 0; }
.opt-shared-toggle .tm-btn { padding: 5px 12px; }

/* Compact toggles inside option blocks — don't stretch full width */
.opt-signal-block .trade-mode-toggle {
  width: auto;
}
.opt-signal-block .tm-btn {
  padding: 5px 10px;
  font-size: 11px;
}
/* Strike dropdown should not stretch */
.opt-signal-block select {
  width: 110px;
  flex-shrink: 0;
}

/* Leg rows */
.opt-signal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.leg-add-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
}
.leg-add-btn:hover { background: var(--blue-bg); }

.leg-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.leg-row:last-child { border-bottom: none; }

.leg-monitor {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.leg-monitor input[type="radio"] { display: none; }
.leg-monitor-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--muted2);
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.leg-monitor input[type="radio"]:checked + .leg-monitor-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.leg-toggle { width: auto; flex-shrink: 0; }
.leg-toggle .tm-btn { padding: 4px 8px; font-size: 11px; }

.leg-strike-select { width: 100px; flex-shrink: 0; }
.leg-val-input     { width: 48px; flex-shrink: 0; }
.leg-pmode-select  { width: 80px; flex-shrink: 0; }

.leg-remove {
  background: transparent;
  border: none;
  color: var(--muted2);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
}
.leg-remove:hover { color: var(--red); }

/* Option Panel slide */
.rp-head-clickable { cursor: pointer; user-select: none; }
.rp-head-clickable:hover { background: var(--bg4); }
.rp-arrow { margin-left: auto; font-size: 10px; color: var(--muted); transition: transform 0.25s; }
.rp-arrow.open { transform: rotate(180deg); }
.rp-slide {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
.rp-slide.open { max-height: 500px; }
.rp-label { font-size: 11px; color: var(--muted2); white-space: nowrap; }
.rp-option {
  border-left: 2px solid var(--accent);
  grid-column: 1 / -1;
}

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge {
  display: inline-block;
  background: var(--bg4);
  color: var(--muted2);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}
.tab-panel { min-height: 0; }
#tabPanelTrade { overflow-y: auto; max-height: calc(100vh - 280px); }

/* Chart */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 14px 16px; }

/* Perf Grid */
.perf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}
.perf-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.perf-row:last-child { border-bottom: none; }
.perf-key { color: var(--muted2); }
.perf-val { font-weight: 600; }

/* Table */
.tbl-wrap { overflow-x: auto; }
.tbl thead th { position: sticky; top: 0; z-index: 2; background: var(--bg2); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead tr { background: var(--bg3); }
th {
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text);
}
td.bold { font-weight: 600; color: var(--text); }
tbody tr:hover td { background: var(--bg3); }
tbody tr:last-child td { border-bottom: none; }

.long  { color: var(--green); font-weight: 700; }
.short { color: var(--red);   font-weight: 700; }

.rbadge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.rb-sl  { background: #2d0a0a; color: #ef4444; border: 1px solid #7f1d1d; }
.rb-tgt { background: #052e16; color: #22c55e; border: 1px solid #166534; }
.rb-tsl { background: #1e1030; color: #a855f7; border: 1px solid #6b21a8; }
.rb-sq  { background: #1c1404; color: #f59e0b; border: 1px solid #92400e; }
.rb-ce  { background: #0f1f3d; color: #3b82f6; border: 1px solid #1e3a5f; }

/* Empty State */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--muted);
  text-align: center;
  gap: 12px;
}
.empty-icon { font-size: 42px; opacity: 0.4; }
.empty p { font-size: 13px; line-height: 1.6; max-width: 300px; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px; right: 20px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  z-index: 9999;
  max-width: 340px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
