/* ==========================================================================
   NIFTY·OC dashboard theme
   Dark "trading terminal" look. Colour has one meaning everywhere:
   green = bullish / up / good, red = bearish / down / bad, amber = warning / paper,
   blue = action / information, violet = market closed (last known values).
   ========================================================================== */

:root, [data-bs-theme="dark"] {
  --app-bg: #0a0e15;
  --app-surface: #111723;
  --app-surface-2: #161e2d;
  --app-surface-3: #1c2536;
  --app-border: #212b3c;
  --app-border-strong: #2c384d;
  --app-text: #e7ebf2;
  --app-muted: #8a94a7;
  --app-faint: #5d6778;

  --app-accent: #4c8dff;
  --app-up: #22c55e;
  --app-down: #f05252;
  --app-warn: #f5a524;
  --app-info: #60a5fa;
  --app-closed: #a78bfa;

  --app-atm: rgba(76, 141, 255, 0.16);
  --app-itm: rgba(245, 165, 36, 0.05);
  --app-ce-bar: rgba(240, 82, 82, 0.22);
  --app-pe-bar: rgba(34, 197, 94, 0.22);

  --app-radius: 12px;
  --app-font: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;

  --bs-body-bg: var(--app-bg);
  --bs-body-color: var(--app-text);
  --bs-secondary-color: var(--app-muted);
  --bs-tertiary-color: var(--app-faint);
  --bs-border-color: var(--app-border);
  --bs-body-font-family: var(--app-font);
  --bs-link-color: var(--app-accent);
  --bs-link-color-rgb: 76, 141, 255;
  --bs-link-hover-color: #7aaaff;
  --bs-success-rgb: 34, 197, 94;
  --bs-danger-rgb: 240, 82, 82;
  --bs-warning-rgb: 245, 165, 36;
  --bs-info-rgb: 96, 165, 250;
  --bs-success: #22c55e;
  --bs-danger: #f05252;
  --bs-warning: #f5a524;
  --bs-info: #60a5fa;
}

html { font-size: 15px; }

body {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(76, 141, 255, 0.06), transparent 60%), var(--app-bg);
  background-attachment: fixed;
  color: var(--app-text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* Numbers: the app marks numeric values with .font-monospace. Use the readable UI font with fixed-width digits
   instead of a code font, so columns still line up but text is easy to read. */
.font-monospace {
  font-family: var(--app-font) !important;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0.005em;
}
.font-sans { font-family: var(--app-font) !important; }
.num { font-variant-numeric: tabular-nums; }

a { text-decoration: none; }
a:hover { text-decoration: underline; }
.text-body-secondary { color: var(--app-muted) !important; }
.text-success { color: var(--app-up) !important; }
.text-danger { color: var(--app-down) !important; }
.text-warning { color: var(--app-warn) !important; }
.text-info { color: var(--app-info) !important; }
.small, small { font-size: 0.86rem; }

/* ---------- Header ---------- */
.app-nav {
  background: rgba(8, 11, 17, 0.92);
  backdrop-filter: blur(8px);
  border-color: var(--app-border) !important;
  position: sticky;
  top: 0;
  z-index: 1030;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}
.app-brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; letter-spacing: 0.02em; color: var(--app-text) !important; }
.app-brand:hover { text-decoration: none; }
.app-brand .mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #4c8dff, #22c55e); color: #fff; font-size: 0.8rem; font-weight: 800;
}
.app-brand .sub { font-weight: 500; color: var(--app-muted); font-size: 0.8rem; }
.app-nav .nav-link { color: var(--app-muted); border-radius: 8px; padding: 0.4rem 0.7rem !important; display: flex; align-items: center; gap: 0.4rem; }
.app-nav .nav-link:hover { color: var(--app-text); background: var(--app-surface-2); text-decoration: none; }
.app-nav .nav-link.active, .app-nav .nav-link.show { color: var(--app-text) !important; background: var(--app-surface-3); }
.app-nav .nav-link svg { width: 16px; height: 16px; opacity: 0.85; flex: none; }
.dropdown-menu { background: var(--app-surface-2); border-color: var(--app-border-strong); border-radius: 10px; padding: 0.35rem; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45); }
.dropdown-item { border-radius: 6px; padding: 0.45rem 0.75rem; color: var(--app-text); }
.dropdown-item .hint { display: block; font-size: 0.75rem; color: var(--app-muted); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--app-surface-3); color: var(--app-text); text-decoration: none; }
.dropdown-item.active { background: rgba(76, 141, 255, 0.16); color: #cfe0ff; }
.dropdown-item.active .hint { color: #9fbaf0; }

.status-pill {
  display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; font-weight: 600;
  padding: 0.28rem 0.7rem; border-radius: 999px; border: 1px solid var(--app-border-strong); background: var(--app-surface-2);
  white-space: nowrap; color: var(--app-text);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--app-faint); flex: none; }
.status-pill.ok .dot { background: var(--app-up); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.status-pill.warn .dot { background: var(--app-warn); }
.status-pill.bad .dot { background: var(--app-down); }
.status-pill.closed .dot { background: var(--app-closed); }
.status-pill.paper { color: #ffd58a; border-color: rgba(245, 165, 36, 0.45); background: rgba(245, 165, 36, 0.1); }
.hub-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--app-faint); display: inline-block; }
.hub-dot.ok { background: var(--app-up); }
.hub-dot.warn { background: var(--app-warn); }
.hub-dot.bad { background: var(--app-down); }
.clock { color: var(--app-muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; border-radius: 9px; }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- Sign-in ---------- */
/* Hide pages until site.js has confirmed sign-in (prevents a flash of the dashboard before redirecting). */
html.auth-check body { visibility: hidden; }
/* With sign-in on, writes are controlled by the user's role, so the old admin-key fields are not needed */
html[data-auth="on"] .admin-key-field { display: none !important; }

/* ---------- Page ---------- */
main.container-fluid { max-width: 1680px; padding-left: 1.25rem; padding-right: 1.25rem; }
main h1.h5 { font-size: 1.35rem; font-weight: 650; letter-spacing: -0.01em; margin-right: 0.25rem; }
.page-sub { color: var(--app-muted); font-size: 0.86rem; }

/* ---------- Cards ---------- */
.card {
  background: linear-gradient(180deg, var(--app-surface) 0%, rgba(17, 23, 35, 0.92) 100%);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 8px 24px rgba(0, 0, 0, 0.18);
}
.card-body { padding: 1rem 1.15rem; }
/* Section label: the first muted line of a card (used across all pages) */
.card-body > .text-body-secondary:first-child,
.card-body > .d-flex:first-child > .text-body-secondary:first-child,
.section-label {
  font-size: 0.72rem !important;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--app-muted) !important;
}
.card-body > .text-body-secondary:first-child { margin-bottom: 0.6rem !important; }

/* KPI tiles */
.kpi { position: relative; overflow: hidden; }
.kpi .kpi-label { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--app-muted); }
.kpi .kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { color: var(--app-muted); font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-chg { font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: transparent; }
.kpi.up::after { background: var(--app-up); }
.kpi.down::after { background: var(--app-down); }
.kpi.neutral::after { background: var(--app-border-strong); }
.display-6 { font-size: 2rem; }

/* ---------- Badges: soft tinted style ---------- */
.badge { font-weight: 650; letter-spacing: 0.02em; border-radius: 6px; padding: 0.3em 0.55em; }
.badge.text-bg-success { background: rgba(34, 197, 94, 0.14) !important; color: #5ee08e !important; box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.35); }
.badge.text-bg-danger { background: rgba(240, 82, 82, 0.14) !important; color: #ff8a8a !important; box-shadow: inset 0 0 0 1px rgba(240, 82, 82, 0.35); }
.badge.text-bg-warning { background: rgba(245, 165, 36, 0.14) !important; color: #ffc766 !important; box-shadow: inset 0 0 0 1px rgba(245, 165, 36, 0.35); }
.badge.text-bg-info { background: rgba(167, 139, 250, 0.14) !important; color: #c4b5fd !important; box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.35); }
.badge.text-bg-primary { background: rgba(76, 141, 255, 0.16) !important; color: #9cc0ff !important; box-shadow: inset 0 0 0 1px rgba(76, 141, 255, 0.35); }
.badge.text-bg-secondary { background: rgba(138, 148, 167, 0.14) !important; color: #c3cad6 !important; box-shadow: inset 0 0 0 1px rgba(138, 148, 167, 0.3); }
.badge.text-bg-dark { background: var(--app-surface-3) !important; color: var(--app-text) !important; }
.badge.fs-6, .badge.fs-5 { padding: 0.4em 0.75em; }

/* ---------- Buttons & forms ---------- */
.btn { border-radius: 8px; font-weight: 600; }
.btn-info, .btn-primary {
  --bs-btn-bg: var(--app-accent); --bs-btn-border-color: var(--app-accent); --bs-btn-color: #fff;
  --bs-btn-hover-bg: #3a7bf0; --bs-btn-hover-border-color: #3a7bf0; --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #2f6be0; --bs-btn-active-border-color: #2f6be0; --bs-btn-active-color: #fff;
  --bs-btn-disabled-bg: #2a4a80; --bs-btn-disabled-border-color: #2a4a80; --bs-btn-disabled-color: #c9d6ee;
}
.btn-outline-info, .btn-outline-primary {
  --bs-btn-color: #9cc0ff; --bs-btn-border-color: rgba(76, 141, 255, 0.5);
  --bs-btn-hover-bg: rgba(76, 141, 255, 0.15); --bs-btn-hover-border-color: var(--app-accent); --bs-btn-hover-color: #cfe0ff;
  --bs-btn-active-bg: var(--app-accent); --bs-btn-active-border-color: var(--app-accent); --bs-btn-active-color: #fff;
}
.btn-outline-secondary { --bs-btn-color: var(--app-muted); --bs-btn-border-color: var(--app-border-strong); --bs-btn-hover-bg: var(--app-surface-3); --bs-btn-hover-border-color: var(--app-border-strong); --bs-btn-hover-color: var(--app-text); }
.form-control, .form-select { background-color: var(--app-surface-2); border-color: var(--app-border-strong); color: var(--app-text); border-radius: 8px; }
.form-control:focus, .form-select:focus { background-color: var(--app-surface-2); border-color: var(--app-accent); box-shadow: 0 0 0 0.2rem rgba(76, 141, 255, 0.2); color: var(--app-text); }
.form-label { color: var(--app-muted); font-size: 0.8rem; font-weight: 600; }
.form-check-input:checked { background-color: var(--app-accent); border-color: var(--app-accent); }

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--app-text);
  --bs-table-border-color: var(--app-border);
  --bs-table-hover-bg: rgba(76, 141, 255, 0.06);
  --bs-table-hover-color: var(--app-text);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.015);
  font-variant-numeric: tabular-nums;
}
.table > :not(caption) > * > * { padding: 0.45rem 0.6rem; }
.table-sm > :not(caption) > * > * { padding: 0.32rem 0.5rem; }
.table thead th {
  font-family: var(--app-font) !important;
  font-size: 0.7rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--app-muted); border-bottom: 1px solid var(--app-border-strong); white-space: nowrap;
}
.table td { border-color: var(--app-border); }
.table tbody tr:last-child td { border-bottom: 0; }
.kv-table th, .kv-table td { background: transparent; padding: 0.3rem 0.45rem; border-color: var(--app-border); }
.kv-table th { color: var(--app-muted); font-weight: 500; font-family: var(--app-font) !important; text-transform: none; letter-spacing: 0; font-size: 0.86rem; }
.table-responsive { border-radius: 8px; }

/* Empty states: rows that span the whole table with a muted message */
tbody td[colspan].text-body-secondary,
.empty-state {
  text-align: center; padding: 1.6rem 1rem !important; color: var(--app-faint) !important;
  font-family: var(--app-font) !important;
}
.empty-state .title { color: var(--app-muted); font-weight: 600; display: block; margin-bottom: 0.15rem; }

/* Progress bars */
.progress { background: var(--app-surface-3); border-radius: 99px; }
.progress-bar { border-radius: 99px; }

/* Alert boxes */
.alert { border-radius: 10px; }
.alert-warning { background: rgba(245, 165, 36, 0.08); border-color: rgba(245, 165, 36, 0.3); color: #ffd58a; }
.alert-info { background: rgba(167, 139, 250, 0.08); border-color: rgba(167, 139, 250, 0.3); color: #d6ccff; }
.alert-danger { background: rgba(240, 82, 82, 0.08); border-color: rgba(240, 82, 82, 0.3); color: #ffb3b3; }
.alert-success { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.3); color: #a7f0c2; }
.alert-secondary { background: var(--app-surface-2); border-color: var(--app-border-strong); color: var(--app-muted); }

/* Collapsible explanations */
details.why { margin-top: 0.4rem; }
details.why > summary {
  cursor: pointer; color: var(--app-accent); font-size: 0.84rem; font-weight: 600; list-style: none; display: inline-flex; align-items: center; gap: 0.3rem;
}
details.why > summary::-webkit-details-marker { display: none; }
details.why > summary::before { content: "▸"; transition: transform 0.15s; display: inline-block; }
details.why[open] > summary::before { transform: rotate(90deg); }
details.why > .why-body { margin-top: 0.45rem; color: var(--app-muted); font-size: 0.86rem; line-height: 1.55; }

/* Summary chips (pass counts etc.) */
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.65rem; border-radius: 999px; background: var(--app-surface-2); border: 1px solid var(--app-border-strong); font-size: 0.84rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.ok { border-color: rgba(34, 197, 94, 0.45); color: #7ee2a2; }
.chip.bad { border-color: rgba(240, 82, 82, 0.45); color: #ff9b9b; }
.chip.warn { border-color: rgba(245, 165, 36, 0.45); color: #ffcf7a; }

/* ---------- Option chain ---------- */
.oc-wrap { max-height: calc(100vh - 210px); border: 1px solid var(--app-border); border-radius: var(--app-radius); background: var(--app-surface); }
.oc-table { font-size: 0.86rem; white-space: nowrap; margin-bottom: 0; }
.oc-table thead th { background: #0d121c !important; border-bottom-color: var(--app-border-strong); position: sticky; z-index: 3; }
.oc-table thead tr:first-child th { top: 0; }
.oc-table thead tr:nth-child(2) th { top: 2.05rem; }
.oc-table td { text-align: right; padding: 0.28rem 0.55rem; }
.oc-table td.strike, .oc-table th.strike {
  text-align: center; font-weight: 700; background: #0e1420 !important;
  border-left: 1px solid var(--app-border-strong); border-right: 1px solid var(--app-border-strong);
}
.oc-table tbody tr:hover td { background-color: rgba(76, 141, 255, 0.05); }
.oc-table tr.atm td { background-color: var(--app-atm) !important; }
.oc-table tr.atm td.strike { color: #cfe0ff; box-shadow: inset 3px 0 0 var(--app-accent); }
.oc-table td.itm { background-color: var(--app-itm); }
.oc-table td.oi-bar { position: relative; }
.oc-table td.oi-bar > span.bar { position: absolute; top: 3px; bottom: 3px; z-index: 0; border-radius: 3px; }
.oc-table td.ce.oi-bar > span.bar { right: 0; background: var(--app-ce-bar); }
.oc-table td.pe.oi-bar > span.bar { left: 0; background: var(--app-pe-bar); }
.oc-table td.oi-bar > span.val { position: relative; z-index: 1; }
.oc-table tfoot td { font-weight: 700; border-top: 2px solid var(--app-border-strong); background: #0d121c; position: sticky; bottom: 0; }
.oc-side-ce { color: #ff9b9b !important; }
.oc-side-pe { color: #7ee2a2 !important; }
/* Phone: compact chain (OI, change, LTP each side) so calls, strike and puts fit without sideways scrolling */
@media (max-width: 767.98px) {
  .oc-table .opt { display: none; }
  .oc-table { font-size: 0.78rem; }
  .oc-table td { padding: 0.28rem 0.3rem; }
}

/* ---------- OI analysis ---------- */
.badge.pos-LongBuildup { background: rgba(34, 197, 94, 0.16); color: #6fe39b; box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.35); }
.badge.pos-ShortBuildup { background: rgba(240, 82, 82, 0.16); color: #ff9090; box-shadow: inset 0 0 0 1px rgba(240, 82, 82, 0.35); }
.badge.pos-ShortCovering { background: rgba(96, 165, 250, 0.16); color: #9cc8ff; box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.35); }
.badge.pos-LongUnwinding { background: rgba(245, 165, 36, 0.16); color: #ffc766; box-shadow: inset 0 0 0 1px rgba(245, 165, 36, 0.35); }
.badge.pos-Neutral { background: rgba(138, 148, 167, 0.14); color: #c3cad6; }
.highlight-list li { line-height: 1.45; padding: 0.45rem 0; border-bottom: 1px solid var(--app-border); }
.highlight-list li:last-child { border-bottom: 0; }

/* ---------- Support & resistance ---------- */
.comp-row { font-size: 0.8rem; margin-bottom: 4px; }
.comp-row .comp-name { width: 9rem; color: var(--app-muted); }
.comp-row .comp-val { width: 4.4rem; text-align: right; font-variant-numeric: tabular-nums; }
.comp-row .progress { height: 6px; }
.level-ladder .rung { display: grid; grid-template-columns: 6rem 1fr 6.5rem; align-items: center; gap: 0.7rem; padding: 0.32rem 0.2rem; font-variant-numeric: tabular-nums; }
.level-ladder .rung .track { height: 8px; border-radius: 99px; background: var(--app-surface-3); overflow: hidden; }
.level-ladder .rung .fill { height: 100%; border-radius: 99px; }
.level-ladder .rung.res .fill { background: linear-gradient(90deg, rgba(240, 82, 82, 0.9), rgba(240, 82, 82, 0.45)); }
.level-ladder .rung.sup .fill { background: linear-gradient(90deg, rgba(34, 197, 94, 0.9), rgba(34, 197, 94, 0.45)); }
.level-ladder .rung.spot { border-top: 1px dashed rgba(76, 141, 255, 0.6); border-bottom: 1px dashed rgba(76, 141, 255, 0.6); margin: 0.25rem 0; color: #cfe0ff; font-weight: 700; }

/* ---------- Market structure ---------- */
.ms-chart { height: 640px; }
@media (max-width: 991.98px) { .ms-chart { height: 420px; } }
.legend-swatch { display: inline-block; width: 14px; height: 3px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }

/* ---------- Signals ---------- */
.cond-list li { line-height: 1.4; padding: 0.3rem 0; }
.plan-table th { white-space: nowrap; }
.conf-items { font-size: 0.78rem; line-height: 1.45; color: var(--app-muted); }

/* ---------- Alerts panel ---------- */
.alerts-panel { --bs-offcanvas-width: 440px; background: var(--app-surface); border-left: 1px solid var(--app-border); }
.alert-item { border-bottom: 1px solid var(--app-border); padding: 0.55rem 0; line-height: 1.4; }
.alert-item.acked { opacity: 0.55; }
.toast { background: var(--app-surface-2); border: 1px solid var(--app-border-strong); border-radius: 10px; max-width: 420px; }

/* ---------- Footer note ---------- */
.app-foot { color: var(--app-faint); font-size: 0.8rem; border-top: 1px solid var(--app-border); margin-top: 1.5rem; padding-top: 0.9rem; }

/* ---------- Small screens ---------- */
@media (max-width: 575.98px) {
  html { font-size: 14.5px; }
  main.container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; }
  .card-body { padding: 0.85rem 0.9rem; }
  .kpi .kpi-value { font-size: 1.6rem; }
}
