/* ============================
   CSS Variables & Reset
   ============================ */
:root {
  --bg-dark: #111827;
  --bg-sidebar: #1f2937;
  --bg-card: #1f2937;
  --bg-panel: #1a2332;
  --border: #374151;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --green: #10b981;
  --red: #ef4444;
  --gold: #f59e0b;
  --blue: #3b82f6;
  --orange: #f97316;
  --sidebar-width: 260px;
  --kundli-width: 440px;
  --topbar-height: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================
   Sidebar
   ============================ */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.range-selector {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-selector label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.range-selector select {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

#index-list {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.index-item {
  display: flex;
  flex-direction: column;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.index-item:hover {
  background: rgba(59, 130, 246, 0.08);
}

.index-item.active {
  background: rgba(59, 130, 246, 0.12);
  border-left-color: var(--accent);
}

.index-item .index-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.index-item .index-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================
   Main Area
   ============================ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#top-bar {
  height: var(--topbar-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
}

#index-title {
  font-size: 1rem;
  font-weight: 600;
}

#index-price {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ============================
   Chart
   ============================ */
#chart-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#chart-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}

.placeholder-title {
  font-size: 1rem;
  font-weight: 500;
}

#chart-placeholder .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.7;
}

#chart {
  width: 100%;
  height: 100%;
}

/* ============================
   Kundli Panel
   ============================ */
#kundli-panel {
  width: var(--kundli-width);
  min-width: var(--kundli-width);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

#kundli-panel.hidden {
  display: none;
}

#kundli-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 10;
}

#kundli-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
}

#kundli-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
#kundli-close:hover { color: var(--red); }

#kundli-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  gap: 12px;
  color: var(--text-secondary);
}

#kundli-loading.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#kundli-content {
  padding: 12px 16px 24px;
}

/* --- Kundli Card Sections --- */
.k-section {
  margin-bottom: 16px;
}

.k-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-light);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.k-card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.k-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 0.8rem;
}

.k-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.k-value {
  font-weight: 600;
  text-align: right;
  font-size: 0.8rem;
}

.k-value.green { color: var(--green); }
.k-value.red { color: var(--red); }
.k-value.gold { color: var(--gold); }
.k-value.blue { color: var(--blue); }
.k-value.accent { color: var(--accent-light); }

/* Planet table */
.planet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.planet-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.planet-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(42, 45, 62, 0.5);
  white-space: nowrap;
}

.planet-table tr:last-child td { border-bottom: none; }

.retro-badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  font-size: 0.6rem;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  font-weight: 700;
}

/* Yoga cards */
.yoga-card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}

.yoga-name {
  font-weight: 700;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.yoga-badge {
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.yoga-badge.benefic { background: rgba(16,185,129,0.15); color: var(--green); }
.yoga-badge.malefic { background: rgba(239,68,68,0.15); color: var(--red); }

.yoga-desc {
  font-size: 0.73rem;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.4;
}

.yoga-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Houses grid */
.houses-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.house-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  text-align: center;
  font-size: 0.7rem;
}

.house-num {
  font-weight: 700;
  color: var(--accent-light);
  font-size: 0.72rem;
}

.house-sign {
  color: var(--text-secondary);
  font-size: 0.65rem;
  margin-top: 1px;
}

.house-planets {
  color: var(--gold);
  font-size: 0.62rem;
  margin-top: 2px;
  min-height: 12px;
}

.house-lord {
  color: var(--text-muted);
  font-size: 0.6rem;
  margin-top: 1px;
}

/* Kundli Chart SVG */
.kundli-chart-svg {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  display: block;
}

.chart-sign {
  font-size: 11px;
  fill: var(--text-muted);
  font-weight: 600;
}

.chart-planet {
  font-size: 12px;
  fill: var(--text-primary);
  font-weight: 700;
}

/* Dasha section */
.dasha-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin: 6px 0;
}

.dasha-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--green));
}

/* Scrollbar */
#kundli-panel::-webkit-scrollbar,
#sidebar::-webkit-scrollbar { width: 6px; }
#kundli-panel::-webkit-scrollbar-track,
#sidebar::-webkit-scrollbar-track { background: transparent; }
#kundli-panel::-webkit-scrollbar-thumb,
#sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Candle tooltip on chart */
.chart-tooltip {
  position: absolute;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  pointer-events: none;
  font-size: 0.78rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Loading overlay for chart */
#chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.8);
  z-index: 20;
}

#chart-loading.hidden { display: none; }
