/* Couleurs Orpaille (thème sombre) : or du logo pour l'accent, dégradé de marque bordeaux → cuivre, neutres chauds */
:root {
  --bg: #0f0c0d;
  --panel: #171214;
  --panel-2: #1f181b;
  --border: #362b2f;
  --text: #efe8e4;
  --muted: #a59a96;
  --accent: #e2b35c;
  --accent-rgb: 226 179 92;
  --on-accent: #22140f;
  --brand-1: #8e2236;
  --brand-1-rgb: 142 34 54;
  --brand-2: #a8672a;
  --brand-3: #e2b35c;
  --up: #22c55e;
  --down: #ef4444;
  --wait: #f28a3c;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.muted { color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; }
.logo { color: var(--accent); }
.badge {
  margin-left: auto;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.symbol-form { display: flex; gap: 8px; flex: 1; max-width: 720px; }
.search-wrap { position: relative; flex: 1; }

input, select, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
input { width: 100%; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: wait; }

.search-results {
  position: absolute;
  z-index: 10;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.search-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; }
.search-results li:hover { background: var(--border); }
.search-results .sym { font-weight: 600; min-width: 80px; }

.disclaimer {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 20px;
  background: #1a1408;
  border-bottom: 1px solid #3a2c0b;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 1fr);
  gap: 16px;
  padding: 16px 20px;
  height: calc(100vh - 100px);
}
.left { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow-y: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
h2 { margin: 0 0 10px; font-size: 15px; }

.quote-header { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 10px; }
.quote-header .name { font-weight: 700; font-size: 16px; }
.quote-header .price { font-size: 26px; font-weight: 700; line-height: 1.2; }
.quote-header .price small { font-size: 14px; font-weight: 500; color: var(--muted); }
.qh-price { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.pill { padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 13px; }
.pill.up { background: rgba(34, 197, 94, .15); }
.pill.down { background: rgba(239, 68, 68, .15); }

/* Fourchette plus bas / plus haut de la période */
.qh-range { flex: 1 1 260px; max-width: 360px; font-size: 13px; }
.qh-range-label { font-size: 12px; margin-bottom: 2px; }
.qh-range-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.qh-low { color: var(--down); }
.qh-high { color: var(--up); }
.range-track {
  position: relative; flex: 1; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(239, 68, 68, .5), rgba(138, 148, 168, .35), rgba(34, 197, 94, .5));
}
.range-marker {
  position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--panel); transform: translate(-50%, -50%);
}
.qh-range-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-top: 3px; }
.up { color: var(--up); }
.down { color: var(--down); }
.chart { height: 340px; }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chat */
.chat-panel { display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble {
  max-width: 92%;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--accent); color: var(--on-accent); }
.bubble p { margin: 4px 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 20px; }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 3px 8px; }
.bubble a { color: #9cc0ff; }
.tool-chip {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  margin: 2px 0;
  align-self: flex-start;
}
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.suggestions button { font-size: 12px; padding: 4px 10px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; }
.chat-form textarea { flex: 1; resize: none; }
.usage { font-size: 11px; margin-top: 6px; min-height: 16px; }
.error { color: var(--down); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; padding: 12px 16px; }
  .chat-panel { height: 80vh; }
  .symbol-form { flex-wrap: wrap; max-width: none; }
  .levels { grid-template-columns: repeat(2, 1fr); }
  .cols { grid-template-columns: 1fr; }
}

.live-dot {
  display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%;
  background: var(--up); animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 50% { opacity: .3; } }

/* Erreur avec bouton « Réessayer » */
.error-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px;
  background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.3); color: var(--down, #ef4444); font-size: 14px; }
.error-box span { flex: 1; min-width: 200px; }

/* Icônes vectorielles (icons.js) : taille et couleur du texte */
.ic { width: 1.1em; height: 1.1em; vertical-align: -0.18em; flex-shrink: 0; }
.ic.filled { fill: currentColor; }
.ic.h-ic { width: 0.95em; height: 0.95em; vertical-align: -0.1em; margin-right: 4px; color: var(--accent, #3b82f6); }
.icon-btn .ic, .share-btn .ic { width: 17px; height: 17px; vertical-align: middle; }
.share-btn[data-fav] .ic.filled, [data-fav].active .ic { color: #f59e0b; }
.scr2-goal-icon .ic { width: 26px; height: 26px; color: var(--accent, #3b82f6); }
.tool-card > span .ic { width: 26px; height: 26px; color: var(--accent, #3b82f6); }
.news-ph .ic { width: 28px; height: 28px; opacity: 0.5; }

/* Chat repliable (chat-dock.js) : fermé, une seule colonne et un bouton flottant ; ouvert, colonne à droite */
body:not(.chat-open) .layout { grid-template-columns: minmax(0, 1fr); }
body:not(.chat-open) .chat-panel { display: none; }
body:not(.chat-open) .left { max-width: 1240px; width: 100%; margin: 0 auto; }
.chat-head-actions { display: flex; align-items: center; gap: 6px; }
.chat-head-actions .icon-btn { margin-left: 0; display: inline-flex; align-items: center; justify-content: center; }
.chat-panel { animation: chat-in .22s ease-out; }
@keyframes chat-in { from { opacity: 0; transform: translateX(16px); } }
.chat-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 50; display: inline-flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 20px 0 16px; border: 0; border-radius: 24px; cursor: pointer;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2)); color: #fff; font-size: 14.5px; font-weight: 700;
  box-shadow: 0 10px 28px rgb(var(--accent-rgb) / .45); transition: transform .15s, box-shadow .15s;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgb(var(--accent-rgb) / .55); }
.chat-fab .ic { width: 19px; height: 19px; }
.chat-fab[hidden] { display: none; }
@media (max-width: 900px) {
  .chat-fab { right: 16px; bottom: 16px; }
  body.chat-open .chat-panel { position: fixed; inset: 0; z-index: 60; height: auto; border-radius: 0; }
}
.scr2-goal.active .scr2-goal-icon .ic { color: #fff; }

/* Quotas du jour (sous le chat et sous l'analyse documentée) */
.usage.low { color: var(--wait); }
.rs-quota { margin-top: 6px; }

/* Favoris : étoile de la barre du haut et sa liste, page Mes favoris (favorites.js) */
.fav-top-box { position: relative; }
.fav-top { position: relative; display: inline-flex; align-items: center; justify-content: center; margin-left: 0; }
.fav-top .ic { width: 17px; height: 17px; }
.fav-top[aria-expanded="true"], .fav-top:hover { color: #f59e0b; }
.fav-count {
  position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: #f59e0b; color: #1a1408; font-size: 10.5px; font-weight: 800; line-height: 17px; text-align: center;
}
.fav-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 70; width: 340px; padding: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
  animation: tb-pop .14s ease-out;
}
.fav-pop-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 6px 8px; }
.fav-pop-list { display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow-y: auto; }
.fav-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; width: 100%;
  padding: 8px; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.fav-row:hover { background: var(--panel-2); }
.fav-row-name { display: flex; flex-direction: column; min-width: 0; }
.fav-row-name b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-row-name small { font-size: 11.5px; }
.fav-row-price { font-weight: 700; font-size: 13.5px; }
.fav-empty { padding: 4px 6px 8px; margin: 0; }
.fav-pop-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px 6px 2px; border-top: 1px solid var(--border); margin-top: 6px; }
.fav-pop-foot .ic { width: 13px; height: 13px; color: var(--up); }
.favorites-page .page-head .ic:not(.h-ic) { width: 13px; height: 13px; color: var(--up); vertical-align: -0.1em; }
.fav-item { position: relative; }
.fav-item .mk-card { width: 100%; }
.fav-remove {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .15s;
}
.fav-item:hover .fav-remove, .fav-remove:focus-visible { opacity: 1; }
.fav-remove:hover { color: var(--down); border-color: var(--down); }
.fav-remove .ic { width: 14px; height: 14px; }
.fav-page-empty { display: flex; align-items: center; gap: 16px; padding: 28px; border: 1px dashed var(--border); border-radius: 14px; }
.fav-page-empty > .ic { width: 34px; height: 34px; color: #f59e0b; flex-shrink: 0; }
.fav-page-empty p { margin: 0; line-height: 1.6; }
.fav-page-sub { margin: 22px 0 10px; font-size: 15px; }
@media (hover: none) { .fav-remove { opacity: 1; } }
@media (max-width: 600px) { .fav-pop { width: calc(100vw - 32px); right: -60px; } }

/* Recherche : dernier cours d'un résultat (choix de la place de cotation) */
.search-results li:has(.sr-price) { grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
.search-results .sr-price { min-width: 64px; text-align: right; font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
