/* ==========================================================================
   Groww Intraday MIS Desk — Apple HIG Minimalist System (Light + Dark)
   Two-layer architecture:
     • Functional layer (sticky nav & tabs): Liquid Glass translucency
     • Content layer (cards, tables, charts): Solid elevated system surfaces
   ========================================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-hover: #f7f7fa;
  --glass: rgba(245, 245, 247, 0.78);
  --glass-border: rgba(0, 0, 0, 0.08);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --blue: #0071e3;
  --blue-dim: rgba(0, 113, 227, 0.11);
  --green: #248a3d;
  --green-dim: rgba(36, 138, 61, 0.11);
  --red: #d70015;
  --red-dim: rgba(215, 0, 21, 0.10);
  --amber: #b25000;
  --amber-dim: rgba(178, 80, 0, 0.11);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.03);
  --code-bg: #f2f2f7;
  --code-text: #1d1d1f;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-hover: #252528;
  --glass: rgba(28, 28, 30, 0.78);
  --glass-border: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --muted: #98989d;
  --blue: #0a84ff;
  --blue-dim: rgba(10, 132, 255, 0.16);
  --green: #30d158;
  --green-dim: rgba(48, 209, 88, 0.15);
  --red: #ff453a;
  --red-dim: rgba(255, 69, 58, 0.15);
  --amber: #ff9f0a;
  --amber-dim: rgba(255, 159, 10, 0.16);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35);
  --code-bg: #111113;
  --code-text: #e5e5ea;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  overflow-x: hidden;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 24px 48px;
}

/* ---------- Functional Layer: Liquid Glass Sticky Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin: 0 -16px 18px;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--glass-border);
  border-radius: 0 0 18px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}
.subtitle {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: -0.005em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill,
.countdown-pill,
.mode-pill,
.lev-pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status-pill.open { color: var(--green); border-color: transparent; background: var(--green-dim); }
.status-pill.closed { color: var(--muted); background: var(--surface-2); border-color: transparent; }
.countdown-pill.urgent { color: var(--amber); background: var(--amber-dim); border-color: transparent; }
.mode-pill { color: var(--blue); background: var(--blue-dim); border-color: transparent; }
.mode-pill.live { color: var(--amber); background: var(--amber-dim); border-color: transparent; }
.lev-pill { color: var(--green); background: var(--green-dim); border-color: transparent; }

/* Theme Segmented Toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.theme-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Master Privacy Toggle (masks real Groww portfolio/cash values without flash) */
.privacy-btn.active {
  background: var(--blue-dim);
  color: var(--blue);
  border-color: transparent;
}
[data-privacy="true"] .private-val,
[data-privacy="true"] #holdingsSummaryLine,
[data-privacy="true"] #positionsContainer,
[data-privacy="true"] #holdingsTbody td.num {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
  transition: filter 0.15s ease;
}

/* ---------- KPI Grid (Content Layer — Solid Surfaces) ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.kpi-card.accent-green {
  border-color: var(--green-dim);
}
.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Functional Layer: Segmented Pill Tab Bar ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.badge {
  background: var(--surface-2);
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tab.active .badge {
  background: var(--blue-dim);
  color: var(--blue);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Controls & Buttons ---------- */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.controls-left, .controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.input {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
}
.input-sm { width: 88px; }
.input-xs { width: 68px; }

.toggle, .inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s ease, transform 0.1s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #ffffff; }
.btn-primary:hover { opacity: 0.92; }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ---------- Workspace Layout & Panels ---------- */
.workspace-split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); font-size: 12.5px; }
.scan-status {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Tables ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr.selected { background: var(--blue-dim); }
.data-table tbody tr:last-child td { border-bottom: none; }
.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.empty-row {
  text-align: center;
  padding: 30px 14px !important;
  color: var(--muted);
}

.sym-main { font-weight: 700; font-size: 13.5px; letter-spacing: -0.01em; }
.sym-sub { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.tag-green { background: var(--green-dim); color: var(--green); }
.tag-amber { background: var(--amber-dim); color: var(--amber); }
.tag-blue { background: var(--blue-dim); color: var(--blue); }
.tag-red { background: var(--red-dim); color: var(--red); }

.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- Detail Panel & Charts ---------- */
.detail-panel { position: sticky; top: 76px; }
.det-empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}
.det-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.hidden { display: none !important; }

.chart-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px 6px;
}
.chart-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.leg-t2 { color: var(--green); }
.leg-t15 { color: var(--blue); }
.leg-en { color: var(--blue); }
.leg-or { color: var(--amber); }
.leg-sl { color: var(--red); }
#intradayChart { width: 100%; height: 200px; display: block; }

.mini-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.mini-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.mini-stat span { font-size: 11.5px; color: var(--muted); }
.mini-stat strong { font-size: 13.5px; font-variant-numeric: tabular-nums; }

.sizer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.sizer-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.calc-summary {
  background: var(--green-dim);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.action-row { display: flex; gap: 8px; flex-wrap: wrap; }
.action-row .btn-primary { flex: 1; }

.risk-box {
  border-radius: 12px;
  padding: 14px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.risk-box.pass { border-color: var(--green); background: var(--green-dim); }
.risk-box.block { border-color: var(--red); background: var(--red-dim); }
.risk-box pre {
  margin-top: 8px;
  padding: 10px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 11px;
}

.positions-box { padding: 16px 18px; color: var(--muted); }

/* ---------- Learnings & Progression Components ---------- */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.weights-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.weight-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.weight-chip span { color: var(--muted); }
.weight-chip strong { color: var(--blue); }

.lessons-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}
.lessons-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Tablet Breakpoint ---------- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-split { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
}

/* ---------- Mobile Breakpoint (iPhone / Android 360px–768px) ---------- */
@media (max-width: 768px) {
  .app-shell {
    padding: 0 12px 36px;
  }
  .topbar {
    margin: 0 -12px 14px;
    padding: 10px 14px;
    border-radius: 0;
    gap: 8px;
  }
  .brand h1 { font-size: 16px; }
  .subtitle { display: none; }
  #liveSyncPill, #modePill { display: none; }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .countdown-pill { font-size: 11px; padding: 4px 8px; }
  .status-pill { font-size: 11px; padding: 4px 8px; }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
  }
  .kpi-card {
    padding: 12px 14px;
    border-radius: 14px;
  }
  .kpi-label { font-size: 11px; margin-bottom: 4px; }
  .kpi-value { font-size: 18px; }
  .kpi-sub { font-size: 11px; }

  .tabs {
    margin-bottom: 14px;
    padding: 3px;
    border-radius: 12px;
  }
  .tab {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 12.5px;
  }

  .btn { min-height: 40px; padding: 8px 14px; }
  .btn-sm { min-height: 32px; padding: 5px 10px; }
  .input { min-height: 40px; font-size: 14px; }

  .controls-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .controls-left, .controls-right { width: 100%; }
  #searchPicks, #searchHoldings { width: 100% !important; min-width: 0 !important; }

  .panel { border-radius: 14px; }
  .panel-head { padding: 14px; }
  .det-body { padding: 14px; }
  .data-table th, .data-table td { padding: 9px 10px; font-size: 12.5px; }

  .mini-stats, .sizer-grid, .calc-summary, .weights-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}

@media (max-width: 420px) {
  .calc-summary, .weights-grid {
    grid-template-columns: 1fr;
  }
}
