/* ═══════════════════════════════════════════════════════════════
   PTV Trading System — Dark Theme
   Cowan Price-Time-Astro geometric analysis dashboard
═══════════════════════════════════════════════════════════════ */

:root {
  --bg-deep:       #0b0f1a;
  --bg-panel:      #111827;
  --bg-card:       #1a2235;
  --bg-hover:      #1e2d42;
  --border:        #1f3050;
  --border-light:  #2a4060;
  --text-primary:  #e0e8f8;
  --text-secondary:#8ba0be;
  --text-muted:    #4a6080;
  --accent-blue:   #3b82f6;
  --accent-cyan:   #22d3ee;
  --accent-green:  #10b981;
  --accent-red:    #ef4444;
  --accent-orange: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-gold:   #fbbf24;
  --accent-moon:   #c4b5fd;
  --bull:          #10b981;
  --bear:          #ef4444;
  --ptv-line:      #3b82f6;
  --ellipse-outer: #8b5cf6;
  --ellipse-inner: #6d28d9;
  --proj-fan:      #f59e0b;
  --astro-moon:    #c4b5fd;
  --astro-sun:     #fbbf24;
  --astro-mercury: #67e8f9;
  --astro-mars:    #f87171;
  --astro-jupiter: #fb923c;
  --astro-saturn:  #d4a054;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-ui:       -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --panel-width:   270px;
  --header-h:      52px;
  --status-h:      38px;
  --chart-h:       520px;
  --radius:        6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 22px;
  color: var(--accent-blue);
  line-height: 1;
}

.app-header h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 11px;
  color: var(--text-muted);
  padding-left: 4px;
  border-left: 1px solid var(--border-light);
  margin-left: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.astro-badge {
  background: #1a1040;
  border: 1px solid var(--accent-moon);
  color: var(--accent-moon);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
}

.utc-clock {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Layout ─────────────────────────────────────── */
.app-body {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
  overflow: hidden;
}

/* ── Control Panel ──────────────────────────────── */
.control-panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.control-panel::-webkit-scrollbar { width: 4px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-blue);
  margin-bottom: 8px;
}

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  margin-top: 8px;
}
.field-label:first-of-type { margin-top: 0; }

.val-display {
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  font-size: 11px;
}

.input-field {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 12px;
  padding: 5px 8px;
  margin-bottom: 4px;
  outline: none;
  transition: border-color 0.15s;
}
.input-field:focus { border-color: var(--accent-blue); }
.input-field::placeholder { color: var(--text-muted); }

select.input-field option {
  background: var(--bg-card);
}

.slider {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  outline: none;
  margin: 4px 0 8px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--accent-blue);
  border-radius: 50%;
  cursor: pointer;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 4px;
  cursor: pointer;
}
.checkbox-label input { accent-color: var(--accent-blue); }

/* Timeframe grid */
.tf-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

/* Fib / rotation grids */
.fib-grid, .rot-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.pill-toggle {
  background: var(--bg-deep);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.pill-toggle.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.active-bodies-display {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 6px;
}

.body-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}
.btn-primary:hover { background: #2563eb; }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-light);
}
.btn-secondary:hover { border-color: var(--accent-blue); color: var(--accent-blue); }

.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-xs { padding: 3px 7px; font-size: 10px; }

.btn-full {
  width: calc(100% - 24px);
  margin: 4px 12px;
  text-align: center;
}

.export-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px 12px;
}

/* ── Main Content ────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  position: relative;
}
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

/* ── Status Bar ─────────────────────────────────── */
.status-bar {
  height: var(--status-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
}

#statusText {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
}

.stat-pills {
  display: flex;
  gap: 8px;
}

.stat-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
}
.stat-pill.bull { border-color: var(--bull); color: var(--bull); }
.stat-pill.bear { border-color: var(--bear); color: var(--bear); }
.stat-pill.neutral { border-color: var(--accent-blue); color: var(--accent-blue); }

/* ── Chart ──────────────────────────────────────── */
.chart-container {
  height: var(--chart-h);
  flex-shrink: 0;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}

/* ── Bottom Panels ──────────────────────────────── */
.bottom-panels {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr 1.2fr;
  gap: 1px;
  background: var(--border);
  min-height: 220px;
  flex: 1;
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
}

.panel-badge {
  background: var(--bg-deep);
  color: var(--accent-blue);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
}

.table-scroll {
  overflow-y: auto;
  flex: 1;
}
.table-scroll::-webkit-scrollbar { width: 4px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.data-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.data-table tr:hover td { background: var(--bg-hover); }

.data-table .bull { color: var(--bull); }
.data-table .bear { color: var(--bear); }

.conf-bar {
  display: inline-block;
  height: 4px;
  border-radius: 2px;
  background: var(--accent-blue);
  margin-left: 4px;
  vertical-align: middle;
}

.status-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-badge.active   { background: #0f3020; color: var(--bull); border: 1px solid var(--bull); }
.status-badge.breached { background: #3a0a0a; color: var(--bear); border: 1px solid var(--bear); }
.status-badge.expired  { background: #1a1a1a; color: var(--text-muted); border: 1px solid var(--border); }

/* ── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 14px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}
.modal-body { padding: 16px; }

.backtest-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.bt-metric {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border-light);
}
.bt-metric .bt-val {
  font-size: 22px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
}
.bt-metric .bt-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ── Loading Overlay ─────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11,15,26,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loadingText { color: var(--text-secondary); font-size: 13px; }

/* ── Astro body colours ──────────────────────────── */
.body-Moon    { background: #1a1040; border-color: var(--astro-moon); color: var(--astro-moon); }
.body-Sun     { background: #1a1000; border-color: var(--astro-sun);  color: var(--astro-sun);  }
.body-Mercury { background: #001a1a; border-color: var(--astro-mercury); color: var(--astro-mercury); }
.body-Mars    { background: #1a0a0a; border-color: var(--astro-mars);    color: var(--astro-mars); }
.body-Jupiter { background: #1a0e00; border-color: var(--astro-jupiter); color: var(--astro-jupiter); }
.body-Saturn  { background: #130e00; border-color: var(--astro-saturn);  color: var(--astro-saturn); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 1400px) {
  .bottom-panels { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .control-panel { width: 220px; min-width: 220px; }
  .bottom-panels { grid-template-columns: 1fr; }
  :root { --chart-h: 380px; }
}
