:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-border: #6ee7b7;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 14px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}
.header { margin-bottom: 24px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #60a5fa, #34d399 55%, #a78bfa);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #111827;
}
h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 22px;
}
.controls { display: grid; gap: 12px; }
.controls-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: end;
}
.controls-hint { margin: 0; }
.field span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.field.is-active .select-input {
  border-color: #059669;
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.15);
}
.field.is-active span {
  color: #059669;
  font-weight: 600;
}
.select-like, .pill-box, .select-input {
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
  color: #374151;
}
.select-input {
  width: 100%;
  max-width: 100%;
  font: inherit;
  cursor: pointer;
  appearance: auto;
}
.select-input:disabled {
  opacity: 0.6;
  cursor: wait;
}
.gift-card.is-hidden,
.fii-section.is-hidden {
  display: none;
}
.pill-box {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  min-height: 46px;
  display: flex;
  align-items: center;
}

.cards {
  margin-bottom: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 420px));
  gap: 16px;
}
.index-card {
  background: linear-gradient(180deg, #ecfdf5 0%, #f0fdf4 100%);
  border: 2px solid #059669;
  border-radius: 16px;
  padding: 18px 20px 16px;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.index-card.fut-card {
  background: linear-gradient(180deg, #eff6ff 0%, #f0f9ff 100%);
  border-color: #2563eb;
}
.index-card.fut-card .tag { color: #1e3a8a; }
.index-card.fut-card .badge { background: #2563eb; }
.index-card.fut-card .badge .dot {
  background: #bfdbfe;
  box-shadow: 0 0 0 3px rgba(191, 219, 254, 0.4);
}
.index-card.fut-card .price { color: #1e3a8a; }
.index-card.gift-card {
  background: linear-gradient(180deg, #fff7ed 0%, #fffbeb 100%);
  border-color: #ea580c;
}
.index-card.gift-card .tag { color: #9a3412; }
.index-card.gift-card .badge { background: #ea580c; }
.index-card.gift-card .badge .dot {
  background: #fed7aa;
  box-shadow: 0 0 0 3px rgba(254, 215, 170, 0.45);
}
.index-card.gift-card .price { color: #9a3412; }
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.card-top .left { display: flex; align-items: center; gap: 10px; }
.tag {
  font-size: 0.78rem;
  font-weight: 700;
  color: #065f46;
  letter-spacing: 0.04em;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #059669;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
}
.badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #bbf7d0;
  box-shadow: 0 0 0 3px rgba(187, 247, 208, 0.35);
}
.badge.warn { background: #d97706; }
.badge.err { background: #dc2626; }
.updated {
  font-size: 0.72rem;
  color: #6b7280;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.price {
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: #064e3b;
  font-variant-numeric: tabular-nums;
}
.change {
  margin-top: 4px;
  font-weight: 650;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
}
.change.up { color: var(--green); }
.change.down { color: var(--red); }
.meta-row {
  margin-top: 12px;
  display: flex;
  gap: 18px;
  font-size: 0.8rem;
  color: #4b5563;
  flex-wrap: wrap;
}
.meta-row strong { color: #111827; }
.ohlc-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  font-size: 0.72rem;
  color: #6b7280;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.ohlc-row strong {
  display: block;
  margin-top: 2px;
  color: #111827;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.index-card.fut-card .ohlc-row strong { color: #1e3a8a; }
.index-card.gift-card .ohlc-row strong { color: #9a3412; }

.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.chart-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #c4b5fd, #818cf8);
}
.btn {
  margin-left: auto;
  border: 1px solid #d1d5db;
  background: #111827;
  color: white;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn.secondary {
  margin-left: 0;
  background: white;
  color: #111827;
}
.btn:hover { opacity: 0.92; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  padding: 12px 14px;
  border-bottom: 1px solid #f3f4f6;
  text-align: left;
  white-space: nowrap;
}
th {
  color: #6b7280;
  font-weight: 600;
  font-size: 0.8rem;
  background: #fafafa;
}
td { font-variant-numeric: tabular-nums; color: #111827; }
td.idx { color: #9ca3af; width: 36px; }
.dhb {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  background: #ecfdf5;
  color: #047857;
  font-weight: 650;
}
.dhb.down {
  background: #fef2f2;
  color: #b91c1c;
}
.dhb.flat { background: #f3f4f6; color: #6b7280; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.chain-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
  margin-left: 4px;
}
.section-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}
.section-hint.inline-hint {
  margin: 0;
  margin-left: 4px;
  flex: 1;
}
.chart-icon.alert-icon {
  background: linear-gradient(135deg, #fbbf24, #f97316);
}
.chart-icon.fii-icon {
  background: linear-gradient(135deg, #34d399, #0ea5e9);
}
.fii-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.fii-stat {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
}
.fii-stat span {
  display: block;
  font-size: 0.72rem;
  color: #6b7280;
  font-weight: 600;
  margin-bottom: 4px;
}
.fii-stat strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: #111827;
}
.fii-stat strong.up { color: #059669; }
.fii-stat strong.down { color: #dc2626; }
.fii-history { font-size: 0.84rem; }
.fii-history th {
  background: #fafafa;
  color: #6b7280;
  font-size: 0.75rem;
}
.alerts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}
.alerts-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.88rem;
}
.alerts-list li:last-child { border-bottom: none; }
.alerts-list .alerts-empty {
  color: var(--muted);
  justify-content: center;
  padding: 16px;
}
.alerts-list .a-time {
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.78rem;
  min-width: 54px;
}
.alerts-list .a-level {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
  text-transform: uppercase;
}
.alerts-list .a-level.info { background: #e0f2fe; color: #0369a1; }
.alerts-list .a-level.warn { background: #fef3c7; color: #b45309; }
.alerts-list .a-level.critical { background: #fee2e2; color: #b91c1c; }
.alerts-list .a-msg { color: #111827; flex: 1; }
.alerts-section .section-title .btn { margin-left: 0; }
.chain-section .section-title .btn {
  margin-left: 0;
}
.chain-section .wing-control {
  margin-left: 0;
}
.chain-section .expiry-control {
  margin-left: auto;
}
.chain-section .expiry-control select {
  min-width: 220px;
  max-width: 320px;
}
.chain-section #chain-meta {
  margin: 8px 0 12px;
  display: block;
}
.wing-control {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #4b5563;
  font-weight: 600;
}
.wing-control select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: white;
  font-weight: 600;
}
.chart-icon.purple {
  background: linear-gradient(135deg, #a78bfa, #6366f1);
}
.chain-table-wrap { max-height: 520px; overflow: auto; }
.chain-table { font-size: 0.86rem; }
.chain-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fafafa;
}
.chain-table th.ce, .chain-table td.ce { color: #1d4ed8; }
.chain-table th.pe, .chain-table td.pe { color: #b45309; }
.chain-table .strike-col {
  text-align: center;
  background: #f9fafb;
  font-variant-numeric: tabular-nums;
}

/* Broker-style light gold for ITM option legs */
.chain-table td.itm-cell {
  background: #fff4cc; /* light gold */
}
.chain-table tr.ce-itm-row td.ce.itm-cell {
  background: #fff4cc;
}
.chain-table tr.pe-itm-row td.pe.itm-cell {
  background: #fff4cc;
}
/* Soft gold wash across ITM rows; strike stays readable */
.chain-table tr.itm-row td.strike-col {
  background: #ffe9a8;
  font-weight: 700;
  color: #92400e;
  box-shadow: inset 0 0 0 1px #f0d060;
}
.chain-table tr.ce-itm-row:not(.atm) td.pcr-col,
.chain-table tr.pe-itm-row:not(.atm) td:last-child {
  background: #fff8e1;
}

/* ATM = strongest highlight (green edge + gold ITM still applies to ITM legs) */
.chain-table tr.atm td {
  font-weight: 650;
}
.chain-table tr.atm td.strike-col {
  background: #fde68a;
  color: #78350f;
  box-shadow: inset 0 0 0 2px #d97706;
  font-weight: 800;
}
.chain-table tr.atm td.itm-cell {
  background: #ffefb0;
}

.chain-table td.up { color: #059669 !important; font-weight: 650; }
.chain-table td.down { color: #dc2626 !important; font-weight: 650; }
.chain-table td.muted-cell { color: #6b7280 !important; font-weight: 500; }
.chain-table td.itm-cell.muted-cell { color: #78716c !important; }
/* Live WS LTP (Upstox) */
.chain-table td.live-ltp {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(16, 185, 129, 0.45);
  text-underline-offset: 3px;
}
.chain-table td.ltp-hover {
  cursor: help;
}
.chain-table td.ltp-hover:hover {
  outline: 1px solid rgba(99, 102, 241, 0.45);
}

/* Column header tooltips */
.chain-table th.tip {
  cursor: help;
  position: relative;
  border-bottom: 1px dotted #9ca3af;
}
.chain-table th.tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 40;
  min-width: 180px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #111827;
  color: #f9fafb;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: normal;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  pointer-events: none;
}
.chain-table th.tip:hover::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 2px);
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: #111827;
  z-index: 41;
  pointer-events: none;
}

/* Multi-expiry strike hover card */
.strike-pop {
  position: fixed;
  z-index: 50;
  min-width: 320px;
  max-width: 420px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
  padding: 12px 14px;
  pointer-events: none;
}
.strike-pop[hidden] { display: none !important; }
.strike-pop-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: #111827;
  margin-bottom: 8px;
}
.strike-pop-hint {
  margin-top: 8px;
  font-size: 0.72rem;
  color: #9ca3af;
}
.strike-pop table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.strike-pop th, .strike-pop td {
  padding: 5px 6px;
  border-bottom: 1px solid #f3f4f6;
  text-align: right;
  white-space: nowrap;
}
.strike-pop th:first-child, .strike-pop td:first-child {
  text-align: left;
}
.strike-pop th {
  color: #6b7280;
  font-weight: 600;
  background: #fafafa;
}
.strike-pop tr.selected td {
  background: #eef2ff;
  font-weight: 650;
}
.strike-pop td.live-ltp {
  font-weight: 700;
  color: #047857;
  text-decoration: underline;
  text-decoration-color: rgba(16, 185, 129, 0.45);
  text-underline-offset: 2px;
}
.strike-pop .tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  margin-left: 4px;
  font-weight: 600;
}

.footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 8px;
}
.footer .note { color: #9ca3af; }
