/* =============================================================================
   BOURSE IA -- Dashboard styles
   Design : sombre, dense, type Bloomberg / Koyfin retailer.
   Variables CSS en haut pour personnalisation simple.
   ========================================================================== */

:root {
  /* Palette */
  --bg:        #0a0e14;
  --panel:    #131820;
  --panel-2:  #1a212c;
  --border:   #2a323d;
  --text:     #e6edf3;
  --muted:    #8b95a5;
  --accent:   #58a6ff;
  --green:    #3fb950;
  --red:      #f85149;
  --yellow:   #d29922;
  --purple:   #bc8cff;
  --orange:   #ff9b53;

  /* Typo */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, ui-monospace, monospace;

  /* Layout */
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    8px;
  --radius-sm: 4px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =============================================================================
   TOPBAR
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  /* position: fixed plus stable que sticky dans un flex sur iOS Safari */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}
/* Spacer pour compenser la topbar fixed */
.app { padding-top: var(--topbar-h); }
.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
}
.brand-sub {
  margin-left: 12px;
  font-size: 12px;
  color: var(--muted);
  border-left: 1px solid var(--border);
  padding-left: 12px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 24px;
  max-width: 600px;
}
#ticker-search {
  width: 100%;
  max-width: 360px;
}
#ticker-search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  transition: border-color 100ms;
}
#ticker-search-input:focus {
  outline: none;
  border-color: var(--accent);
}
.btn.ghost {
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 8px;
  font-size: 18px;
  display: none;  /* visible only on mobile */
}

/* Score cards (dip_buy / value_trap) */
.score-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  position: relative;
}
.score-card .score-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.score-card .score-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  margin: 4px 0;
}
.score-card .score-label {
  font-size: 12px;
}
.score-card.dip { border-left: 3px solid var(--green); }
.score-card.trap { border-left: 3px solid var(--red); }
.score-card .score-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
.score-card .score-bar-fill {
  height: 100%;
  transition: width 300ms;
}

/* Compare table */
.compare-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.compare-table th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
.compare-table td.indicator-name-col {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  width: 280px;
}

/* Sector heatmap cells */
.heatmap-cell {
  padding: 8px 10px;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* =============================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 0;
  }
  .topbar-center {
    display: none;
  }
  .btn.ghost {
    display: inline-flex;
    margin-right: 8px;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 220ms ease-out;
    visibility: hidden;
    pointer-events: none;
  }
  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
    box-shadow: 4px 0 16px rgba(0,0,0,0.6);
  }
  /* Overlay sombre quand le drawer est ouvert */
  .sidebar-overlay {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity 220ms;
  }
  .sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
  }
  .content {
    padding: 16px;
    width: 100%;
  }
  .brand-sub {
    display: none;
  }
}
@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  .page-title {
    font-size: 18px;
  }
}

/* =============================================================================
   APP LAYOUT
   ========================================================================== */

.app {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#nav {
  flex: 1;
  padding: 12px 0;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 20px;
  color: var(--text);
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: background 100ms, border-color 100ms;
  cursor: pointer;
}
.nav-link:hover { background: var(--panel-2); text-decoration: none; }
.nav-link.active {
  background: var(--panel-2);
  border-left-color: var(--accent);
}
.nav-icon {
  color: var(--muted);
  font-size: 10px;
}
.nav-link.active .nav-icon { color: var(--accent); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.content {
  flex: 1;
  padding: 24px 28px;
  overflow-x: hidden;
  min-width: 0;
}

/* =============================================================================
   COMPOSANTS GENERIQUES
   ========================================================================== */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h3 {
  margin: 0 0 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}
.panel h3 .badge {
  margin-left: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  color: var(--text);
  font-weight: 500;
}

.page-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
}
.page-subtitle {
  margin: 0 0 22px;
  color: var(--muted);
}

/* Grilles */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1100px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* KPI cards */
.kpi {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.kpi-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 600;
  font-family: var(--font-mono);
  margin-top: 4px;
}

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
td.num, th.num { text-align: right; font-family: var(--font-mono); }
tbody tr { cursor: pointer; transition: background 80ms; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.no-hover { cursor: default; }
tbody tr.no-hover:hover { background: transparent; }

/* Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 80ms;
}
.btn:hover { filter: brightness(1.15); }
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn-icon { font-size: 14px; line-height: 1; }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.active,
.period-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
/* Conteneur des boutons periode : wrap sur petit ecran, padding compact */
.period-btn {
  padding: 6px 10px;
  font-size: 12px;
}
.period-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}
@media (max-width: 500px) {
  .period-btn {
    padding: 5px 8px;
    font-size: 11px;
    flex: 1 1 auto;
    min-width: 44px;
  }
}

/* Autocomplete dropdown sous la barre de recherche */
.search-wrap { position: relative; }
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 1000;
  max-height: 320px;
  overflow-y: auto;
}
.search-dropdown.hidden { display: none; }
.search-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover,
.search-item.active {
  background: var(--panel-2);
}
.search-item .sym {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
  min-width: 70px;
}
.search-item .name {
  flex: 1;
  color: var(--text);
  font-size: 13px;
}
.search-item .exch {
  color: var(--muted);
  font-size: 11px;
}
.search-item .badge-watchlist {
  background: rgba(63,185,80,0.15);
  color: var(--green);
  border: 1px solid var(--green);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
}

/* Pills / badges */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.muted   { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.pill.green   { background: rgba(63,185,80,0.15);  color: var(--green); }
.pill.red     { background: rgba(248,81,73,0.15);  color: var(--red); }
.pill.yellow  { background: rgba(210,153,34,0.15); color: var(--yellow); }
.pill.purple  { background: rgba(188,140,255,0.15);color: var(--purple); }
.pill.accent  { background: rgba(88,166,255,0.15); color: var(--accent); }

/* Couleurs valeur */
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }

/* Charts */
.chart-wrap {
  position: relative;
  height: 320px;
}
.chart-wrap.tall  { height: 400px; }
.chart-wrap.short { height: 200px; }

/* Loading overlay */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 13px;
}

/* DB stats footer */
.db-stats {
  font-family: var(--font-mono);
  line-height: 1.6;
}

/* =============================================================================
   COMPOSANTS SPECIFIQUES
   ========================================================================== */

/* Indicator row avec annotation contextuelle */
.indicator-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: 13px;
}
.indicator-row:last-child { border-bottom: none; }
.indicator-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.indicator-help {
  color: var(--muted);
  cursor: help;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.indicator-value {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
  min-width: 90px;
}
.indicator-flag {
  font-size: 11px;
  color: var(--yellow);
}

/* Tooltip indicateur (au hover sur le ?) */
.tooltip {
  position: absolute;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  z-index: 100;
  pointer-events: none;
}

/* News card */
.news-card {
  border-left: 3px solid var(--border);
  background: var(--panel-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.news-card.critique { border-left-color: var(--red); }
.news-card.important { border-left-color: var(--orange); }
.news-card.notable   { border-left-color: var(--yellow); }
.news-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}
.news-card-title {
  margin: 4px 0 6px;
  color: var(--text);
}
.news-card-summary {
  font-style: italic;
  color: var(--muted);
}
.news-card-link {
  margin-top: 6px;
  font-size: 11px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.toast.hidden { display: none; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* Drawdown table cell colors */
.dd-strong { color: var(--red); font-weight: 600; }
.dd-medium { color: var(--orange); }
.dd-light  { color: var(--yellow); }

/* Forms */
input[type="text"], input[type="number"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
}
label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

/* Annotation inline badge */
.annotation {
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  background: var(--panel-2);
  color: var(--yellow);
  border: 1px solid var(--border);
}
.annotation.warn  { color: var(--red); }
.annotation.info  { color: var(--accent); }
.annotation.good  { color: var(--green); }

/* Section title */
h2.section {
  margin: 24px 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}

/* Helper */
.spacer { height: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
