/* ═══════════════════════════════════════════════════════════════════════
   bartolo-theme.css — Bartolo Signal Analyzer shared design tokens
   Single source of truth for all pages (Signal Analyzer, Gap, News, P&F)
   ═══════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=DM+Sans:wght@400;500;700&display=swap');

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

:root {
  color-scheme: dark;
  --bg:        #1a2420;
  --surface:   #222e28;
  --border:    #2d3e35;
  --text:      #d0d8d2;
  --text-dim:  #7a8a80;
  --accent:    #d4a24e;
  --green:     #3dd68c;
  --red:       #e5534b;
  --blue:      #539bf5;
  --pink:      #ff69b4;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'DM Sans', sans-serif;
  --chart-bg:  #0b0e14;
  --chart-border: #1e2430;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ═══ NAV BAR ═══════════════════════════════════════════════════════════ */

.bartolo-nav {
  display: flex;
  align-items: center;
  background: #1a1a1a;
  border-bottom: 2px solid var(--border);
  padding: 0 16px;
  height: 42px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.bartolo-nav .nav-brand {
  font-size: 15px;
  font-weight: 700;
  color: #E0E0E0;
  margin-right: 24px;
  letter-spacing: 0.5px;
  font-family: var(--sans);
}
.bartolo-nav .nav-link {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #aaaaaa;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-family: var(--sans);
  transition: color 0.15s, border-color 0.15s;
}
.bartolo-nav .nav-link:hover {
  color: #FFFFFF;
}
.bartolo-nav .nav-link.active {
  color: #2980B9;
  border-bottom-color: #2980B9;
}

/* ═══ LAYOUT ════════════════════════════════════════════════════════════ */

.bartolo-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ═══ CARD ══════════════════════════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.card-header h2 {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.card-body { padding: 1.2rem; }

/* ═══ BADGE ═════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge.ok   { background: rgba(61,214,140,0.1); color: var(--green); }
.badge.ok::before   { background: var(--green); }
.badge.err  { background: rgba(229,83,75,0.1); color: var(--red); }
.badge.err::before  { background: var(--red); }
.badge.wait { background: rgba(99,107,120,0.15); color: var(--text-dim); }
.badge.wait::before { background: var(--text-dim); }

/* ═══ STAT ROW ══════════════════════════════════════════════════════════ */

.stat-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat {
  flex: 1; min-width: 140px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.8rem 1rem;
}
.stat-label {
  font-family: var(--mono); font-size: 0.65rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin-bottom: 0.3rem;
}
.stat-value { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; color: var(--accent); }

/* ═══ CHIPS ═════════════════════════════════════════════════════════════ */

.chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font-family: var(--mono); font-size: 0.72rem; padding: 0.3em 0.7em;
  border-radius: 4px; background: rgba(83,155,245,0.1);
  color: var(--blue); border: 1px solid rgba(83,155,245,0.15);
}

/* ═══ WATCHLIST GRID ════════════════════════════════════════════════════ */

.wl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem; }
.wl-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.7rem 0.9rem;
  cursor: pointer; transition: all 0.15s ease;
}
.wl-card:hover { border-color: var(--accent); background: rgba(212,162,78,0.05); }
.wl-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.wl-symbol { font-family: var(--mono); font-weight: 700; font-size: 1rem; color: var(--accent); }
.wl-name { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-sector { font-family: var(--mono); font-size: 0.65rem; color: var(--text-dim); margin-top: 0.2rem; }

/* ═══ DETAIL PANEL ══════════════════════════════════════════════════════ */

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

/* ═══ DATA TABLE ════════════════════════════════════════════════════════ */

.data-scroll { max-height: 360px; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.73rem; }
.data-table th {
  text-align: left; padding: 0.5em 0.7em; color: var(--text-dim);
  border-bottom: 1px solid var(--border); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  position: sticky; top: 0; background: var(--surface);
}
.data-table td { padding: 0.4em 0.7em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr:hover { background: rgba(212,162,78,0.04); }
.data-table .positive { color: var(--green); }
.data-table .negative { color: var(--red); }

pre.json {
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.7;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
  max-height: 240px; overflow-y: auto; padding: 0.8rem;
  background: var(--bg); border-radius: 6px; border: 1px solid var(--border);
}

/* ═══ TAB BAR ═══════════════════════════════════════════════════════════ */

.tab-bar { display: flex; gap: 0; border-bottom: 1px solid var(--border); }
.tab-btn {
  font-family: var(--mono); font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.6rem 1.2rem; background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ═══ INTERVAL TOGGLE (D/W/M) ══════════════════════════════════════════ */

.interval-toggle { display: flex; gap: 0; }
.interval-btn {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 600;
  padding: 0.35em 0.9em; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-dim); letter-spacing: 0.04em;
  transition: all 0.15s;
}
.interval-btn:first-child { border-radius: 4px 0 0 4px; }
.interval-btn:last-child  { border-radius: 0 4px 4px 0; }
.interval-btn:not(:first-child) { border-left: none; }
.interval-btn:hover { color: var(--text); border-color: var(--accent); }
.interval-btn.active {
  background: rgba(212,162,78,0.15); color: var(--accent);
  border-color: var(--accent);
}

/* ═══ CHART PANELS (Stage 6) ═══════════════════════════════════════════ */

.chart-section {
  display: none;
  padding: 1.2rem;
  border-top: 1px solid var(--border);
}
.chart-section.active { display: block; }
.chart-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.chart-section-title {
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600;
  color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em;
}
.chart-panel { margin-bottom: 1.2rem; }
.chart-panel-title {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}
.chart-canvas-wrap {
  position: relative;
  background: var(--chart-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
}
.chart-canvas-wrap canvas {
  width: 100% !important;
  height: 320px !important;
}

/* ═══ GAP CHART CONTROLS ═══════════════════════════════════════════════ */

.gap-master-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.2rem; flex-wrap: wrap; gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.gap-master-controls .legend {
  display: flex; gap: 1.2rem; flex-wrap: wrap;
  font-family: var(--mono); font-size: 0.7rem; color: var(--text-dim);
}
.gap-master-controls .legend span { display: flex; align-items: center; gap: 0.4em; }
.gap-master-controls .legend .sw { width: 12px; height: 4px; border-radius: 1px; display: inline-block; }
.gap-master-controls select, .gap-master-controls button {
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-family: var(--mono); font-size: 0.72rem; padding: 0.3em 0.6em; cursor: pointer;
}
.gap-master-controls button:hover { border-color: var(--accent); color: var(--accent); }
.gap-chart-scroll { overflow: auto; max-height: 80vh; background: var(--bg); }

/* ═══ SIDEBAR & WATCHLIST (News + future sidebar pages) ════════════════ */

.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.search-area-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.search-row {
  display: flex;
  gap: 0.4rem;
}

.search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.45em 0.6em;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0;
}

.watchlist-header {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-align: center;
  font-weight: 600;
}

.watchlist-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 500px;
}

/* .watchlist-item is the flex row wrapper (injected by JS renderWatchlist) */
.watchlist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3em;
  padding: 0.45em 0.7em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
  position: relative;
}
.watchlist-item:hover {
  border-color: var(--accent);
  background: rgba(212, 162, 78, 0.05);
}
.watchlist-item.active {
  border-color: var(--accent);
  background: rgba(212, 162, 78, 0.12);
}

/* .watchlist-ticker is just the symbol text inside .watchlist-item */
.watchlist-ticker {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}
.watchlist-item.active .watchlist-ticker {
  color: var(--accent);
}

.watchlist-remove {
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0 0.3em;
  background: none;
  border: none;
  transition: color 0.12s;
}
.watchlist-remove:hover {
  color: var(--red);
}

/* ═══ FOOTER ═══════════════════════════════════════════════════════════ */

.bartolo-footer {
  text-align: center; padding: 2rem;
  font-size: 0.72rem; color: var(--text-dim); font-family: var(--mono);
}

/* ═══ SPINNER ══════════════════════════════════════════════════════════ */

.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ RESPONSIVE ═══════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .bartolo-main { padding: 1rem; }
  .wl-grid { grid-template-columns: 1fr 1fr; }
}

/* ═══ STAGE 10.5 — BARTOLO BRAND DROPDOWN MENU ═════════════════════════ */

/* Applies to the .nav-brand used on: index, analyzer, gap, pnf, portfolio, status */
.bartolo-nav .nav-brand {
  cursor: pointer;
  position: relative;
  user-select: none;
}

.bartolo-nav .nav-brand::after {
  content: ' ▾';
  font-size: 0.7em;
  opacity: 0.6;
  margin-left: 2px;
}

.bartolo-nav .nav-brand:hover {
  color: #FFFFFF;
}

/* The dropdown panel — positioned relative to the nav-brand span */
.bartolo-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  padding: 4px 0;
  margin-top: 6px;
  font-family: var(--sans);
}

.bartolo-dropdown.open {
  display: block;
}

.bartolo-dropdown a {
  display: block;
  padding: 8px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.bartolo-dropdown a:hover {
  background: var(--bg);
  color: var(--accent);
}

.bartolo-dropdown .dropdown-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
/* ═══ STAGE 10.7 — PORTFOLIO DROPDOWN & MANAGE MODAL ═══════════════════ */

/* Portfolio selector row — sits above ticker lists on Gap and Cockpit */
.portfolio-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.portfolio-selector label {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}
.portfolio-select {
  flex: 1;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.35em 0.6em;
  cursor: pointer;
  transition: border-color 0.15s;
}
.portfolio-select:focus {
  outline: none;
  border-color: var(--accent);
}
.portfolio-manage-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.35em 0.7em;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.portfolio-manage-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

/* ── Modal dialog ──────────────────────────────────────────────────────── */
.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 420px;
  max-width: 95vw;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  transition: color 0.12s;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* Portfolio list inside modal */
.modal-portfolio-list {
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-y: auto;
  max-height: 240px;
  background: var(--bg);
}
.modal-portfolio-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5em 0.8em;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.modal-portfolio-item:last-child { border-bottom: none; }
.modal-portfolio-item:hover { background: rgba(212,162,78,0.05); }
.modal-portfolio-item.selected {
  background: rgba(212,162,78,0.1);
  color: var(--accent);
}
.modal-portfolio-item .mpf-name { flex: 1; }
.modal-portfolio-item .mpf-count {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: 0.8rem;
}
.modal-portfolio-item .mpf-active-marker {
  color: var(--accent);
  font-weight: 700;
  margin-right: 0.4rem;
}

/* Modal action buttons row */
.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.modal-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.4em 0.9em;
  cursor: pointer;
  transition: all 0.15s;
}
.modal-btn:hover { border-color: var(--accent); color: var(--accent); }
.modal-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.modal-btn.danger:hover { border-color: var(--red); color: var(--red); }

/* Inline prompt row (New / Rename input) */
.modal-input-row {
  display: none;
  gap: 0.4rem;
  align-items: center;
}
.modal-input-row.open { display: flex; }
.modal-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.4em 0.6em;
}
.modal-input:focus { outline: none; border-color: var(--accent); }

.modal-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  min-height: 1.2em;
}
.modal-status.err { color: var(--red); }
.modal-status.ok  { color: var(--green); }
