/* ═══════════════════════════════════════════════════════
   Options Chain Panel
   ═══════════════════════════════════════════════════════ */

/* Topbar button */
.tb-opt-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 8px; border: none; background: none;
  color: var(--text-dim); border-radius: var(--radius-sm);
  cursor: pointer; font-family: var(--font-ui);
  font-size: .92rem; font-weight: 450;
  transition: background var(--ease), color var(--ease);
}
.tb-opt-btn:hover { background: var(--surface-raised); color: var(--text); }
.tb-opt-btn svg {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ═══════════════════════════════════════════════════════
   Options Panel v2
   ═══════════════════════════════════════════════════════ */

/* Overlay backdrop */
.opt-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  z-index: 200; display: none;
  align-items: center; justify-content: center;
  backdrop-filter: blur(var(--overlay-blur));
}
.opt-overlay.open { display: flex; animation: optFadeIn .15s ease; }

@keyframes optFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Panel */
.opt-panel {
  width: 96vw; max-width: 1280px;
  height: 88vh;
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  box-shadow: var(--overlay-shadow);
  overflow: hidden;
  animation: optSlideIn .2s ease;
}
@keyframes optSlideIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ── */
.opt-header {
  padding: 12px 20px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0; flex-wrap: wrap;
}
.opt-header h3 {
  font-family: var(--font-ui);
  font-size: 1.05rem; font-weight: 700;
  color: var(--text-bright); white-space: nowrap;
}
.opt-header-controls {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
}
.opt-exp-select {
  padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-family: var(--font-ui);
  font-size: .82rem; cursor: pointer; outline: none;
}
.opt-exp-select:focus { border-color: var(--blue); }
.opt-close {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 1.2rem; font-weight: 700;
}
.opt-close:hover { background: var(--hover-medium); color: #fff; }
.opt-plot-btn {
  background: var(--blue-dim); border: 1px solid var(--blue-focus); color: var(--blue);
  padding: 4px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: .82rem; font-weight: 600;
  font-family: var(--font-ui); white-space: nowrap; transition: all var(--ease);
}
.opt-plot-btn:hover { background: var(--blue-strong); border-color: var(--blue); }
.opt-plot-btn.active { background: var(--blue-strong); border-color: var(--blue); color: #fff; }
.opt-status {
  font-family: var(--font-ui);
  font-size: .82rem; color: var(--text-muted);
}
.opt-status.loading { color: var(--amber); }
.opt-status.done { color: var(--green); }
.opt-status.error { color: var(--red); }

/* ── Mode toggle (Per Scadenza / Aggregate) ── */
.mode-toggle {
  display: flex; border: 1px solid var(--border-hi); border-radius: var(--radius-sm); overflow: hidden;
}
.mode-toggle button {
  padding: 5px 14px; border: none; background: transparent;
  color: var(--text-muted); font-family: var(--font-ui);
  font-size: .82rem; font-weight: 600; cursor: pointer;
  transition: all var(--ease);
}
.mode-toggle button:not(:last-child) { border-right: 1px solid var(--border-hi); }
.mode-toggle button.active {
  background: var(--blue-dim); color: var(--blue);
}
.mode-toggle button:hover:not(.active) { background: var(--divider-soft); color: var(--text); }

/* ── Main area: metric tabs (left) + insight (right) ── */
.opt-main {
  flex: 1; display: flex; overflow: hidden;
}

/* Left: 2/3 — metric area */
.opt-metric-area {
  flex: 2; display: flex; flex-direction: column; overflow: hidden;
  border-right: 1px solid var(--border);
}

/* Tabs row (aggregate mode) */
.opt-tabs {
  display: flex; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}
.opt-tabs button {
  padding: 10px 16px; border: none; background: transparent;
  color: var(--text-muted); font-family: var(--font-ui);
  font-size: .82rem; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap; transition: all var(--ease);
}
.opt-tabs button.active {
  color: var(--blue); border-bottom-color: var(--blue);
}
.opt-tabs button:hover:not(.active) { color: var(--text); }

/* Summary header (persistent in aggregate mode) */
#optAggSummaryHeader {
  flex-shrink: 0; padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border);
}
#optAggSummaryHeader .opt-cards { margin-bottom: 4px; }
#optAggSummaryHeader .agg-sub {
  text-align: center; color: var(--text-muted);
  font-size: .82rem; padding: 2px 0;
}

/* Metric content (scrollable) */
.opt-metric-content {
  flex: 1; overflow-y: auto; padding: 16px 20px;
}

/* Legend footer (persistent, always visible) */
.opt-legend-footer {
  flex-shrink: 0; padding: 8px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  font-size: .82rem; color: var(--text-muted);
}
.opt-legend-footer .oi-legend-item { display: flex; align-items: center; gap: 5px; }
.opt-legend-footer .oi-legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* Right: 1/3 — insight panel */
.opt-insight-area {
  flex: 1; overflow-y: auto; padding: 16px;
  background: var(--card);
  min-width: 280px; max-width: 380px;
}
.opt-insight-area .insight-header {
  font-family: var(--font-ui);
  font-size: .82rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Loading / empty */
.opt-loading {
  padding: 40px 20px;
  text-align: center;
  font-size: .9rem;
  color: var(--text-muted);
}
.opt-no-data {
  max-width: 520px;
  margin: 60px auto;
  padding: 24px 28px;
  text-align: center;
  font-size: .95rem;
  line-height: 1.6;
  color: var(--text-bright);
  background: var(--hover-subtle);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
}
.opt-no-data strong { color: var(--accent, #c3a05f); }

/* ═══════════════════════════════════════════════════════
   Reusable — cards, charts, tables
   ═══════════════════════════════════════════════════════ */
.opt-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px; margin-bottom: 16px;
}
.opt-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px; text-align: center;
}
.opt-card-label {
  font-size: .82rem; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 3px;
}
.opt-card-value {
  font-family: var(--font-ui);
  font-size: .95rem; font-weight: 700; color: var(--text);
}
.opt-card-sub {
  font-family: var(--font-ui);
  font-size: .82rem; color: var(--text-muted); margin-top: 2px;
}
.bullish { color: var(--green) !important; }
.bearish { color: var(--red) !important; }
.neutral { color: var(--amber) !important; }
.opt-call-color { color: var(--green) !important; }
.opt-put-color { color: var(--red) !important; }

/* Section titles */
.opt-section-title {
  font-size: .82rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

/* ── OI bar chart ── */
.oi-header {
  display: flex; justify-content: space-between;
  padding: 0 8px 6px;
  font-size: .82rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
}
.oi-chart { margin-bottom: 10px; }
.oi-row {
  display: flex; align-items: center; height: 22px; margin-bottom: 1px;
  font-family: var(--font-ui); font-size: .82rem;
  transition: background .1s;
}
.oi-row:hover { background: var(--hover-subtle); }
.oi-row.row-current { background: var(--blue-med); border-top: 1px solid var(--blue); border-bottom: 1px solid var(--blue); }
.oi-row.row-current .oi-strike { color: var(--blue); font-weight: 700; }
.oi-row.row-maxpain { background: var(--amber-dim); border-top: 1px solid var(--amber); border-bottom: 1px solid var(--amber); }
.oi-row.row-maxpain .oi-strike { color: var(--amber); font-weight: 700; }
.oi-row.row-callwall { background: var(--green-dim); border-top: 1px dashed var(--green); border-bottom: 1px dashed var(--green); }
.oi-row.row-callwall .oi-strike { color: var(--green); font-weight: 700; }
.oi-row.row-putwall { background: var(--red-dim); border-top: 1px dashed var(--red); border-bottom: 1px dashed var(--red); }
.oi-row.row-putwall .oi-strike { color: var(--red); font-weight: 700; }

.oi-call-wrap { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 5px; padding-right: 6px; height: 100%; }
.oi-call-val { color: var(--text-muted); min-width: 40px; text-align: right; font-size: .82rem; }
.oi-bar-call { height: 14px; background: var(--green); border-radius: 2px 0 0 2px; min-width: 1px; opacity: .7; }
.oi-strike { width: 68px; text-align: center; flex-shrink: 0; color: var(--text); font-weight: 600; }
.oi-put-wrap { flex: 1; display: flex; align-items: center; gap: 5px; padding-left: 6px; height: 100%; }
.oi-bar-put { height: 14px; background: var(--red); border-radius: 0 2px 2px 0; min-width: 1px; opacity: .7; }
.oi-put-val { color: var(--text-muted); min-width: 40px; font-size: .82rem; }

.oi-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 6px 0; font-size: .82rem; color: var(--text-muted);
}
.oi-legend-item { display: flex; align-items: center; gap: 4px; }
.oi-legend-dot { width: 8px; height: 8px; border-radius: 2px; }

/* ── GEX bar chart ── */
.gex-chart { margin-bottom: 10px; }
.gex-row {
  display: flex; align-items: center; height: 22px; margin-bottom: 1px;
  font-family: var(--font-ui); font-size: .82rem;
  transition: background .1s;
}
.gex-row:hover { background: var(--hover-subtle); }
.gex-row.row-current { background: var(--blue-med); border-top: 1px solid var(--blue); border-bottom: 1px solid var(--blue); }
.gex-row.row-current .gex-strike { color: var(--blue); font-weight: 700; }
.gex-row.row-flip { background: var(--purple-dim); border-top: 1px dashed var(--purple); border-bottom: 1px dashed var(--purple); }
.gex-row.row-flip .gex-strike { color: var(--purple); font-weight: 700; }
.gex-neg-wrap { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 5px; padding-right: 6px; height: 100%; }
.gex-neg-val { color: var(--text-muted); min-width: 50px; text-align: right; font-size: .82rem; }
.gex-bar-neg { height: 14px; background: var(--red); border-radius: 2px 0 0 2px; min-width: 0; opacity: .7; }
.gex-strike { width: 68px; text-align: center; flex-shrink: 0; color: var(--text); font-weight: 600; }
.gex-pos-wrap { flex: 1; display: flex; align-items: center; gap: 5px; padding-left: 6px; height: 100%; }
.gex-bar-pos { height: 14px; background: var(--green); border-radius: 0 2px 2px 0; min-width: 0; opacity: .7; }
.gex-pos-val { color: var(--text-muted); min-width: 50px; font-size: .82rem; }

/* ── IV Term Structure ── */
.iv-term { margin-bottom: 8px; }
.iv-term-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-family: var(--font-ui); font-size: .82rem;
}
.iv-term-label { width: 80px; text-align: right; flex-shrink: 0; color: var(--text-dim); font-size: .7rem; }
.iv-term-dte { width: 36px; flex-shrink: 0; text-align: right; color: var(--text-muted); font-size: .82rem; }
.iv-term-bar-wrap {
  flex: 1; display: flex; flex-direction: column; gap: 1px; justify-content: center;
}
.iv-term-bar-row { display: flex; align-items: center; height: 8px; }
.iv-term-bar-row .iv-call { height: 100%; background: var(--green); opacity: .7; border-radius: 2px; min-width: 1px; transition: width .4s ease; }
.iv-term-bar-row .iv-put { height: 100%; background: var(--red); opacity: .7; border-radius: 2px; min-width: 1px; transition: width .4s ease; }
.iv-term-val { width: 50px; flex-shrink: 0; font-weight: 600; color: var(--text); }
.iv-term-vals {
  width: 130px; flex-shrink: 0; display: flex; gap: 4px; justify-content: flex-end;
  font-family: var(--font-ui); font-size: .82rem;
}
.iv-term-vals .iv-c { color: var(--green); }
.iv-term-vals .iv-p { color: var(--red); }
.iv-term-vals .iv-sep { color: var(--text-muted); }

/* ── OI per Expiration chart ── */
.exp-oi-chart { margin-bottom: 10px; }
.exp-oi-row {
  display: flex; align-items: center; height: 26px; margin-bottom: 2px;
  font-family: var(--font-ui); font-size: .82rem;
}
.exp-oi-label { width: 80px; text-align: right; flex-shrink: 0; color: var(--text-dim); font-size: .7rem; padding-right: 8px; }
.exp-oi-dte { width: 30px; flex-shrink: 0; text-align: right; color: var(--text-muted); font-size: .82rem; padding-right: 8px; }
.exp-oi-bars { flex: 1; display: flex; flex-direction: column; gap: 1px; justify-content: center; }
.exp-oi-bar-row { display: flex; align-items: center; height: 10px; gap: 4px; }
.exp-oi-bar-call { height: 100%; background: var(--green); opacity: .7; border-radius: 2px; min-width: 1px; }
.exp-oi-bar-put { height: 100%; background: var(--red); opacity: .7; border-radius: 2px; min-width: 1px; }
.exp-oi-vals {
  width: 130px; flex-shrink: 0; display: flex; gap: 4px; justify-content: flex-end;
  font-size: .82rem;
}
.exp-oi-vals .oi-c { color: var(--green); }
.exp-oi-vals .oi-p { color: var(--red); }
.exp-oi-vals .oi-sep { color: var(--text-muted); }
.exp-oi-ratio {
  width: 44px; flex-shrink: 0; text-align: right; font-size: .82rem; font-weight: 600;
}

/* ── OI Pie chart ── */
.oi-pie-wrap {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 0 18px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.oi-pie {
  width: 90px; height: 90px; border-radius: 50%; flex-shrink: 0;
  position: relative; box-shadow: 0 0 20px rgba(0,0,0,.3);
}
.oi-pie-hole {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 50px; height: 50px; border-radius: 50%; background: var(--panel);
}
.oi-pie-legend { display: flex; flex-direction: column; gap: 6px; }
.oi-pie-item { display: flex; align-items: center; gap: 8px; }
.oi-pie-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.oi-pie-label {
  font-family: var(--font-ui); font-size: .7rem;
  color: var(--text-dim); min-width: 50px;
}
.oi-pie-val {
  font-family: var(--font-ui); font-size: .82rem; font-weight: 700;
}

/* ── Options Chain Table ── */
.opt-table-wrap { overflow-x: auto; margin-top: 4px; }
.opt-table {
  width: 100%; border-collapse: collapse;
  font-family: var(--font-ui); font-size: .82rem;
}
.opt-table thead th {
  padding: 5px 7px; font-size: .82rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.opt-th-call { text-align: center; color: #fff; background: var(--green-strong); border-bottom: 2px solid var(--green); }
.opt-th-put { text-align: center; color: #fff; background: var(--red-strong); border-bottom: 2px solid var(--red); }
.opt-th-strike { text-align: center; color: var(--text); width: 65px; }
.opt-table tbody tr { transition: background .1s; }
.opt-table tbody tr:hover .opt-td-call { background: var(--green-med); }
.opt-table tbody tr:hover .opt-td-put { background: var(--red-med); }
.opt-table tbody td { padding: 4px 7px; border-bottom: 1px solid rgba(31,35,52,.5); white-space: nowrap; }
.opt-td-call { text-align: right; color: var(--text); background: var(--green-subtle); }
.opt-td-put { text-align: left; color: var(--text); background: var(--red-subtle); }
.opt-td-call.opt-itm { background: var(--green-strong); color: #fff; font-weight: 500; }
.opt-td-put.opt-itm { background: var(--red-strong); color: #fff; font-weight: 500; }
.opt-td-strike {
  text-align: center; font-weight: 700; color: #fff;
  background: var(--surface-raised);
  border-left: 2px solid var(--border-hi); border-right: 2px solid var(--border-hi);
}
.opt-strike-current { color: var(--blue) !important; background: var(--blue-med) !important; border-left-color: var(--blue) !important; border-right-color: var(--blue) !important; }
.opt-tr-current td { border-top: 1px solid var(--blue); border-bottom: 1px solid var(--blue); }

/* ── Unusual activity table ── */
.ua-table { width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: .82rem; }
.ua-table thead th {
  padding: 5px 7px; font-size: .82rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap;
}
.ua-table tbody td { padding: 4px 7px; border-bottom: 1px solid rgba(31,35,52,.5); white-space: nowrap; }
.ua-table tbody tr:hover { background: var(--hover-subtle); }
.ua-type-call { color: var(--green); font-weight: 600; }
.ua-type-put { color: var(--red); font-weight: 600; }
.ua-ratio { color: var(--amber); font-weight: 700; }

/* ── Scorecard (right panel overview) ── */
.opt-scorecard {
  margin-bottom: 16px; padding: 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.opt-scorecard-title {
  font-size: .82rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 10px;
}
.opt-sc-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--divider-soft);
  font-size: .85rem; color: var(--text);
}
.opt-sc-row:last-child { border-bottom: none; }
.opt-sc-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.opt-sc-dot.bullish { background: var(--green); box-shadow: 0 0 6px var(--green); }
.opt-sc-dot.bearish { background: var(--red); box-shadow: 0 0 6px var(--red); }
.opt-sc-dot.neutral { background: var(--amber); box-shadow: 0 0 4px var(--amber); }
.opt-sc-label { flex: 1; color: var(--text-dim); font-weight: 500; }
.opt-sc-value { font-weight: 600; text-align: right; }
.opt-sc-value.bullish { color: var(--green); }
.opt-sc-value.bearish { color: var(--red); }
.opt-sc-value.neutral { color: var(--amber); }

.opt-sc-verdict {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-md);
  text-align: center; font-size: .90rem; font-weight: 600;
}
.opt-sc-verdict.bullish { background: var(--green-dim); color: var(--green); border: 1px solid var(--green-strong); }
.opt-sc-verdict.bearish { background: var(--red-dim); color: var(--red); border: 1px solid var(--red-strong); }
.opt-sc-verdict.neutral { background: var(--amber-dim); color: var(--amber); border: 1px solid var(--amber-dim); }

/* ── Chatbot insight styling (right panel) ── */
.chat-msg {
  margin-bottom: 16px; position: relative;
  padding: 12px 14px; border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 2px;
  background: var(--blue-dim); border: 1px solid var(--blue-med);
  font-size: .82rem; line-height: 1.65; color: var(--text);
  font-family: var(--font-ui);
}
.chat-msg.chat-bullish { background: var(--green-dim); border-color: var(--green-strong); }
.chat-msg.chat-bearish { background: var(--red-dim); border-color: var(--red-strong); }
.chat-msg.chat-neutral { background: var(--amber-dim); border-color: var(--amber-dim); }
.chat-msg .chat-label {
  font-family: var(--font-ui);
  font-size: .82rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px;
}
.chat-msg .chat-label .chat-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--blue);
}
.chat-msg.chat-bullish .chat-label .chat-dot { background: var(--green); }
.chat-msg.chat-bearish .chat-label .chat-dot { background: var(--red); }
.chat-msg.chat-neutral .chat-label .chat-dot { background: var(--amber); }
.chat-msg p { margin: 0 0 8px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg .hl { font-weight: 600; }
.chat-msg .hl-green { color: var(--green); font-weight: 600; }
.chat-msg .hl-red { color: var(--red); font-weight: 600; }
.chat-msg .hl-blue { color: var(--blue); font-weight: 600; }
.chat-msg .hl-amber { color: var(--amber); font-weight: 600; }
.chat-msg .hl-purple { color: var(--purple); font-weight: 600; }
.chat-msg .hl-white { color: var(--text-bright); font-weight: 600; }

/* Badge */
.badge {
  font-family: var(--font-ui);
  font-size: .82rem; font-weight: 600;
  padding: 2px 7px; border-radius: var(--radius-sm); letter-spacing: .03em;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }

