/* ══════════════════════════════════════════════════════════════════════
   optbook control deck — modern fintech design system
   Inspired by TradingView's clarity + Upstox's warmth.
   Full-width, layered shadows, generous spacing, strong hierarchy.
   ══════════════════════════════════════════════════════════════════════ */

:root {
  /* surfaces */
  --bg: #f0f2f7;
  --card: #ffffff;
  --card-hover: #fafbfd;
  --card-inset: #f8fafc;
  --line: #e2e8f0;
  --line-hi: #cbd5e1;

  /* text */
  --ink: #111827;
  --ink-2: #1f2937;
  --dim: #4b5563;
  --faint: #6b7280;

  /* brand */
  --blue: #3b82f6;
  --blue-dk: #2563eb;
  --blue-lt: #eff6ff;
  --blue-border: #bfdbfe;

  /* semantic */
  --green: #10b981;
  --green-dk: #059669;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --red: #ef4444;
  --red-dk: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --amber: #f59e0b;
  --amber-dk: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;

  /* typography */
  --sans: "DM Sans", -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;

  /* geometry */
  --r-card: 12px;
  --r-inner: 8px;
  --r-btn: 8px;
  --r-pill: 6px;

  /* elevation */
  --sh-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --sh-md: 0 2px 4px rgba(15, 23, 42, .04), 0 1px 2px rgba(15, 23, 42, .06);
  --sh-lg: 0 8px 16px -4px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --sh-xl: 0 20px 40px -8px rgba(15, 23, 42, .12), 0 4px 8px rgba(15, 23, 42, .04);

  /* transitions */
  --ease: cubic-bezier(.25, .46, .45, .94);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--blue); color: #fff; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--green-dk); }
.neg { color: var(--red-dk); }

/* ══ scrollbar ══════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-hi); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ══ sidebar ════════════════════════════════════════════════════════ */
.has-sidebar { display: flex; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 90;
  width: 210px; display: flex; flex-direction: column; gap: 2px;
  padding: 20px 10px 14px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  margin-bottom: 20px; padding: 0 10px;
}
.sidebar-logo {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--blue); border-radius: var(--r-inner);
  color: #fff; font-size: 16px; font-weight: 700;
}
.sidebar-name { font-weight: 700; font-size: 15px; color: var(--ink); letter-spacing: -.01em; }
.sidebar-divider { height: 1px; background: var(--line); margin: 0 6px 10px; }

.sidebar-item {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  padding: 11px 12px; border-radius: var(--r-btn);
  color: var(--dim); font-weight: 500; font-size: 14px;
  transition: all .15s var(--ease);
}
.sidebar-item:hover { background: var(--card-inset); color: var(--ink-2); }
.sidebar-item-active {
  background: var(--blue-lt); color: var(--blue-dk); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--blue-border);
}
.sidebar-icon { font-size: 18px; width: 24px; text-align: center; opacity: .8; }
.sidebar-item-active .sidebar-icon { opacity: 1; }
.sidebar-label { line-height: 1.3; font-weight: 600; color: var(--ink-2); }
.sidebar-label small { display: block; font-size: 11px; color: var(--dim); font-weight: 400; }
.sidebar-item-active .sidebar-label small { color: var(--blue); opacity: .6; }

.sidebar-spacer { flex: 1; }
.sidebar-logout { padding: 0 6px; }

/* ══ main content ═══════════════════════════════════════════════════ */
.main-content {
  margin-left: 210px; flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}

/* ══ topbar ═════════════════════════════════════════════════════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.topbar-slim { padding: 10px 24px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--blue); border-radius: 6px;
  color: #fff; font-size: 12px; font-weight: 700; flex: none;
}
.brand-name { font-weight: 700; font-size: 17px; color: var(--ink); letter-spacing: -.02em; }
.brand-sub { color: var(--dim); font-size: 13px; margin-left: 2px; font-weight: 500; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.clock { color: var(--faint); font-size: 12px; }
.inline { display: inline; }

.kill-chip {
  font: 600 10px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
  color: var(--red-dk); background: var(--red-bg);
  border: 1px solid var(--red-border); border-radius: var(--r-pill);
  padding: 4px 10px; display: inline-flex; align-items: center; gap: 5px;
}
.kill-chip::before { content: "●"; font-size: 7px; }

/* ══ deck (main scroll area) ════════════════════════════════════════ */
.deck {
  flex: 1; padding: 20px 24px 60px;
  display: flex; flex-direction: column; gap: 14px;
  width: 100%; max-width: none;
}
.deck-foot { color: var(--dim); font-size: 11px; text-align: center; margin-top: 12px; font-weight: 500; }

/* ══ KPI strip — connected stat bar ═════════════════════════════════ */
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr) 1.3fr; gap: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--sh-md);
  overflow: hidden;
}
.kpi {
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 20px 14px;
  border-right: 1px solid var(--line);
  transition: background .15s var(--ease);
}
.kpi:hover { background: var(--card-hover); }
.kpi:last-child { border-right: none; }
.kpis-4 { grid-template-columns: repeat(4, 1fr) !important; }

.kpi-label {
  font: 700 10px/1 var(--sans); letter-spacing: .1em;
  text-transform: uppercase; color: var(--dim);
}
.kpi-value {
  font-family: var(--mono); font-weight: 600; font-size: 28px;
  line-height: 1.1; color: var(--ink); letter-spacing: -.03em;
}
.kpi-dim { color: var(--dim); }
.kpi-foot { font-size: 11px; color: var(--dim); font-family: var(--mono); margin-top: auto; font-weight: 500; }
.kpi-gate { justify-content: center; gap: 6px; }

.gate-track {
  position: relative; height: 10px; border-radius: 5px; overflow: hidden;
  background: var(--card-inset); border: 1px solid var(--line);
}
.gate-fill {
  position: absolute; inset: 0 auto 0 0; width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--blue-dk));
  border-radius: 5px;
  transition: width .8s var(--ease-out);
}
.gate-fill-inv { background: linear-gradient(90deg, var(--green), var(--amber), var(--red)) !important; }
.gate-ticks { display: none; }

/* ══ fired banner ═══════════════════════════════════════════════════ */
.fired-banner {
  display: flex; gap: 14px; align-items: center;
  border: 1px solid var(--red-border);
  border-left: 4px solid var(--red);
  border-radius: var(--r-card); background: var(--card);
  padding: 16px 20px; font-size: 14px;
  box-shadow: var(--sh-md);
}
.fired-banner strong { color: var(--red-dk); letter-spacing: .02em; font-size: 13px; text-transform: uppercase; }
.fired-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red); flex: none;
  animation: dotBlink 1.4s ease-in-out infinite;
}
@keyframes dotBlink { 50% { opacity: .3; transform: scale(.85); } }

/* ══ grids ══════════════════════════════════════════════════════════ */
.hero-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
.lower-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; }
.hero-grid > *, .lower-grid > * { min-width: 0; }

/* ══ panels (cards) ═════════════════════════════════════════════════ */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 20px 22px 22px;
  box-shadow: var(--sh-sm);
  transition: box-shadow .2s var(--ease);
}
.panel:hover { box-shadow: var(--sh-md); }
.panel-accent { border-top: 3px solid var(--blue); box-shadow: var(--sh-md); }

.panel-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  font: 700 13px/1 var(--sans); letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink);
}

.pill {
  font: 500 11px/1 var(--mono); color: var(--dim);
  border: 1px solid var(--line-hi); border-radius: var(--r-pill);
  padding: 3px 8px; background: var(--card-inset); font-weight: 600;
}
.pill-cyan {
  color: var(--blue-dk); border-color: var(--blue-border);
  background: var(--blue-lt); font-weight: 600;
}

/* ══ spread viz ═════════════════════════════════════════════════════ */
.spread-viz { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; margin: 8px 0 20px; }
.leg { display: flex; flex-direction: column; gap: 3px; }
.leg-tag { font: 700 11px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; }
.leg-short .leg-tag { color: var(--red); }
.leg-long .leg-tag { color: var(--green); }
.leg-strike { font-size: 30px; font-weight: 600; font-family: var(--mono); color: var(--ink); letter-spacing: -.02em; }

.wing-line {
  position: relative; height: 14px; border-radius: 7px;
  background: var(--card-inset); border: 1px solid var(--line-hi);
}
.wing-fill {
  position: absolute; inset: 2px auto 2px 2px; width: 0%;
  background: linear-gradient(90deg, rgba(239,68,68,.12), rgba(245,158,11,.12));
  border-radius: 5px; transition: width .7s var(--ease-out);
}
.spot-dot {
  position: absolute; top: 50%; left: 0%;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--blue); border: 4px solid var(--card);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--blue), var(--sh-md);
  transition: left .7s var(--ease-out);
  z-index: 1;
}

.kv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kv-grid > div {
  display: flex; flex-direction: column; gap: 3px;
  padding-left: 12px; border-left: 3px solid var(--line);
}
.kv-grid dt { font: 700 10px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.kv-grid dd { font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--ink); }

.zone-note { margin-top: 14px; color: var(--dim); font-size: 13px; font-weight: 500; font-family: var(--mono); padding: 8px 12px; background: var(--card-inset); border-radius: var(--r-inner); }

.empty { color: var(--dim); font: 500 13px var(--sans); padding: 24px 8px; text-align: center; }

/* ══ smart exit monitor ═════════════════════════════════════════════ */
.se-body { display: flex; flex-direction: column; gap: 16px; }
.se-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.se-num {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 0 10px 14px;
  border-left: 3px solid var(--blue);
  background: var(--blue-lt);
  border-radius: 0 var(--r-inner) var(--r-inner) 0;
}
.se-lab { font: 700 10px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.se-num span:last-child { font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--ink); }

.se-gauge { display: flex; flex-direction: column; gap: 8px; }
.se-track {
  position: relative; height: 18px; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--line-hi); background: var(--card-inset);
}
.se-zone { position: absolute; top: 0; bottom: 0; }
.se-safe { left: 0; width: 55%; background: var(--green-bg); border-right: 1px solid var(--green-border); }
.se-warn  { left: 55%; width: 25%; background: var(--amber-bg); border-right: 1px solid var(--amber-border); }
.se-fire  { left: 80%; right: 0; background: var(--red-bg); }
.se-marker {
  position: absolute; top: -3px; bottom: -3px; left: 80%; width: 3px;
  background: var(--red); border-radius: 2px; z-index: 2;
}
.se-track .spot-dot { top: 50%; width: 14px; height: 14px; border: 3px solid var(--card); }
.se-caption { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.se-research {
  font-size: 12px; color: var(--dim); font-family: var(--mono); font-weight: 500;
  border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px;
}

/* ══ actions ════════════════════════════════════════════════════════ */
.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.run-opts { display: flex; gap: 14px; align-items: center; color: var(--dim); font-size: 12px; }
.run-opts input[type="number"] {
  width: 50px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line-hi); border-radius: 6px; padding: 4px 6px;
  font-family: var(--mono); font-size: 12px;
  outline: none; transition: border-color .15s;
}
.run-opts input[type="number"]:focus { border-color: var(--blue); }
.run-opts input[type="checkbox"] { accent-color: var(--blue); margin-right: 3px; width: 14px; height: 14px; }

.btn {
  font: 600 13px/1 var(--sans); color: var(--ink-2);
  background: var(--card); border: 1px solid var(--line-hi);
  border-radius: var(--r-btn); padding: 10px 16px; cursor: pointer;
  transition: all .15s var(--ease);
  display: inline-flex; align-items: center; gap: 7px;
  box-shadow: var(--sh-sm);
}
.btn:hover { background: var(--card-inset); border-color: var(--faint); transform: translateY(-1px); box-shadow: var(--sh-md); }
.btn:active { transform: translateY(0); box-shadow: var(--sh-sm); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary {
  color: #fff; background: var(--blue); border-color: var(--blue);
  box-shadow: 0 1px 3px rgba(37, 99, 235, .3);
}
.btn-primary:hover { background: var(--blue-dk); border-color: var(--blue-dk); }

.btn-danger { color: var(--red-dk); border-color: var(--red-border); background: var(--red-bg); box-shadow: none; }
.btn-danger:hover { background: #fee2e2; border-color: var(--red); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--dim); box-shadow: none; }
.btn-ghost:hover { background: var(--card-inset); border-color: transparent; color: var(--ink); transform: none; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

.job-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--amber);
  animation: dotBlink 1.2s infinite;
}
.job-note { font-size: 12px; color: var(--dim); }

/* ══ console ════════════════════════════════════════════════════════ */
.console-out {
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  color: #374151; background: #fafafa;
  border: 1px solid var(--line); border-radius: var(--r-inner);
  padding: 14px 16px;
  max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* ══ tables ═════════════════════════════════════════════════════════ */
.table-scroll { overflow-x: auto; border-radius: var(--r-inner); border: 1px solid var(--line); }
table.trades { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.trades th {
  text-align: left; font: 700 11px/1 var(--sans); letter-spacing: .06em;
  text-transform: uppercase; color: var(--dim);
  padding: 10px 12px; border-bottom: 2px solid var(--line-hi);
  background: var(--card-inset);
  position: sticky; top: 0; z-index: 1;
}
.trades td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--ink); }
.trades tbody tr { transition: background .1s; }
.trades tbody tr:hover { background: var(--blue-lt); }
.trades .r { text-align: right; }
.trades .notes-row td {
  white-space: normal; color: var(--dim); font-size: 12px; padding: 8px 12px;
  border-bottom: 1px solid var(--line-hi); background: var(--card-inset);
}.out-win { color: var(--green-dk); font-weight: 600; }
.out-loss { color: var(--red-dk); font-weight: 600; }

/* ══ chart ══════════════════════════════════════════════════════════ */
.chart-box { height: 280px; position: relative; max-width: 100%; }

/* ══ modal ══════════════════════════════════════════════════════════ */
[hidden] { display: none !important; }

.modal-veil {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: min(440px, 100%);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px;
  box-shadow: var(--sh-xl);
  animation: modalIn .25s var(--ease-out);
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } }
.modal h3 {
  font: 700 14px/1 var(--sans); letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-2); margin-bottom: 14px;
}
.modal p { font-size: 15px; margin-bottom: 22px; color: var(--ink); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ══ gate bars (swingbook) ══════════════════════════════════════════ */
.gate-bars { display: flex; flex-direction: column; gap: 12px; }
.gate-row { display: grid; grid-template-columns: 100px 1fr 90px; gap: 14px; align-items: center; }
.gate-lab { font: 700 11px/1 var(--sans); color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.gate-val { font: 600 12px/1 var(--mono); color: var(--ink-2); text-align: right; }
.gate-fails { margin-top: 10px; color: var(--amber-dk); font-size: 12px; font-family: var(--mono); padding: 8px 12px; background: var(--amber-bg); border-radius: var(--r-inner); }

/* ══ login ══════════════════════════════════════════════════════════ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
  background-image: radial-gradient(ellipse 600px 300px at 50% 0%, rgba(59, 130, 246, .06), transparent);
}
.login-card {
  width: min(400px, calc(100vw - 40px));
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 40px 36px 28px; text-align: center;
  box-shadow: var(--sh-xl);
}
.brand-lg { justify-content: center; gap: 12px; margin-bottom: 8px; }
.brand-lg .brand-mark { width: 44px; height: 44px; border-radius: 10px; font-size: 18px; }
.brand-lg .brand-name { font-size: 28px; letter-spacing: -.03em; }
.login-tag { color: var(--dim); font-size: 14px; margin-bottom: 28px; }

.login-error {
  color: var(--red-dk); border: 1px solid var(--red-border);
  border-radius: var(--r-inner); background: var(--red-bg);
  padding: 12px 14px; font-size: 13px; margin-bottom: 18px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font: 700 11px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.field input {
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line-hi); border-radius: var(--r-btn);
  padding: 12px 14px; font-family: var(--mono); font-size: 14px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, .12); }
.field input::placeholder { color: var(--faint); }
.login-foot { margin-top: 24px; color: var(--faint); font: 500 11px var(--mono); }

/* ══ reveal animation ═══════════════════════════════════════════════ */
.reveal { opacity: 0; transform: translateY(8px); animation: reveal .45s var(--ease-out) forwards; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes reveal { to { opacity: 1; transform: none; } }

/* ══ responsive ═════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  .hero-grid { grid-template-columns: 1fr; }
  .lower-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(2) { border-right: none; }
  .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 768px) {
  .sidebar { width: 56px; padding: 16px 6px; }
  .sidebar-name, .sidebar-label, .sidebar-divider, .sidebar-logout { display: none; }
  .sidebar-brand { justify-content: center; padding: 0; }
  .sidebar-item { justify-content: center; padding: 12px 0; }
  .sidebar-icon { font-size: 20px; }
  .main-content { margin-left: 56px; }
}

@media (max-width: 640px) {
  .deck { padding: 12px 10px 80px; }
  .topbar, .topbar-slim { padding: 10px 14px; }
  .brand-sub, .clock { display: none; }
  .kv-grid { grid-template-columns: repeat(2, 1fr); }
  .run-opts { display: none; }
  .kpi { padding: 12px 14px 10px; }
  .kpi-value { font-size: 22px; }
  .spread-viz { gap: 10px; }
  .leg-strike { font-size: 22px; }
  .se-readout { grid-template-columns: 1fr; }
  .se-num { padding: 8px 0 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}
