/* SECTION_CSS_RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 13px; overflow-x: hidden; }
a { color: var(--green); text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font-family: inherit; font-size: inherit; }
input, select { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-family: var(--mono); font-size: 12px; padding: 4px 8px; border-radius: var(--radius); outline: none; }
input:focus, select:focus { border-color: var(--green); }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }
canvas { display: block; }

/* SECTION_CSS_HEADER */
/* ── App shell : sidebar gauche + zone principale ── */
#app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
@media (max-width: 900px) {
  #app-shell { grid-template-columns: 1fr; }
}

/* ── Sidebar ── */
#sidebar {
  width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
  overflow-y: auto;
}
#sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#sidebar-logo .logo-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--green2), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.logo-name { font-size: 14px; font-weight: 700; letter-spacing: 0.05em; display: block; }
.logo-sub  { color: var(--muted); font-size: 10px; font-weight: 400; display: block; }

/* Nav items */
#sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; flex: 1; }
.sidebar-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--muted); font-size: 12px; font-weight: 500;
  letter-spacing: .02em; transition: all .15s;
  width: 100%; text-align: left;
}
.sidebar-btn:hover { background: rgba(255,255,255,.04); color: var(--text); }
.sidebar-btn.active {
  background: rgba(0,212,170,.08);
  color: var(--green);
  border-left: 2px solid var(--green);
  padding-left: 10px;
  font-weight: 600;
}
.sidebar-icon { font-size: 16px; flex-shrink: 0; line-height: 1; }
.sidebar-label { font-family: var(--sans); }

/* Section label dans la sidebar */
.sidebar-section-label {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted2);
  padding: 8px 12px 4px; font-family: var(--sans);
}

/* Bas sidebar : clock compact */
#sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 6px;
}
/* Quick Stats sidebar widget */
#sidebar-quick-stats {
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.qs-title {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted2); font-family: var(--sans);
  margin-bottom: 2px;
}
.qs-row {
  display: flex; align-items: center; justify-content: space-between;
}
.qs-label { font-size: 10px; color: var(--muted2); font-family: var(--sans); }
.qs-val   { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--text); }
.qs-mini-bar {
  height: 3px; border-radius: 2px; margin-top: 3px;
  background: var(--bg4); overflow: hidden;
}
.qs-mini-fill { height: 100%; border-radius: 2px; transition: width .4s, background .4s; }
.sidebar-clock-row {
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-clock-label {
  font-size: 9px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .09em; color: var(--muted2); font-family: var(--sans);
}
.sidebar-clock-val {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
}

/* Hamburger mobile */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 0; left: 0;
  z-index: 300;
  /* Flush avec le header : même hauteur, même fond */
  width: 52px; height: 52px;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text); font-size: 18px;
  align-items: center; justify-content: center;
  /* Touch target iOS — dépasse visuellement pas mais zone cliquable OK */
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}
#sidebar-toggle:active { background: var(--bg3); }

#sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 199;
}
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #sidebar-toggle { display: flex; }
  #sidebar-overlay.active { display: block; }
  #main-content { margin-left: 0 !important; }

  /* Header : laisser la place au hamburger (52px) à gauche */
  #header {
    padding-left: 60px;
    padding-right: 12px;
  }

  /* Touch targets iOS minimum 44px pour tous les boutons header */
  #btn-privacy {
    height: 44px;
    min-width: 44px;
    padding: 0 12px;
    border-radius: var(--radius);
  }
  #btn-wallet {
    height: 44px;
    min-width: 44px;
    padding: 0 12px;
  }

  /* Cacher le label texte "Masquer" sur mobile — garder l'icône œil */
  #privacy-label { display: none; }
  /* Agrandir l'icône œil pour faciliter la visée */
  #btn-privacy #privacy-eye { font-size: 18px; }

  /* header-right : serrer un peu le gap */
  #header-right { gap: 8px; }
}

/* ── Zone principale ── */
#main-content {
  margin-left: 220px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header (bande du haut, sans logo ni tabs) ── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  flex-shrink: 0;
}
#header-right { display: flex; align-items: center; gap: 10px; }
#address-display { font-size: 11px; color: var(--muted); }
#freshness-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
#btn-wallet {
  padding: 5px 14px; border-radius: var(--radius);
  border: 1px solid var(--green2); color: var(--green);
  background: rgba(0,212,170,0.07); font-size: 12px; font-weight: 600;
  transition: all 0.2s;
}
#btn-wallet:hover { background: rgba(0,212,170,0.14); }
#btn-wallet.connected { border-color: var(--border2); color: var(--muted); background: transparent; }
#btn-privacy {
  height: 32px; width: auto; padding: 0 12px; gap: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border2); background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 700;
  font-family: var(--sans); letter-spacing: .04em;
  display: flex; align-items: center; cursor: pointer;
  transition: all 0.2s;
}
#btn-privacy #privacy-eye { font-size: 14px; line-height: 1; }
#btn-privacy:hover { border-color: rgba(255,255,255,0.2); color: var(--text); background: rgba(255,255,255,.04); }
#btn-privacy.active { border-color: var(--orange); color: var(--orange); background: rgba(240,165,0,0.08); }
#btn-privacy.active #privacy-eye { filter: brightness(1.2); }

/* ── Barre de prix sticky ── */
#price-bar {
  display: flex; align-items: center; gap: 0;
  flex: 1; justify-content: center;
}
.price-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 14px;
  border-right: 1px solid var(--border);
  cursor: default; transition: background .12s;
}
.price-pill:first-child { border-left: 1px solid var(--border); }
.price-pill:hover { background: rgba(255,255,255,.03); }
.price-pill-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.price-pill-coin { font-family: var(--sans); font-size: 10px; font-weight: 700; color: var(--muted2); letter-spacing: .06em; }
.price-pill-val  { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--text); }
.price-pill-chg  { font-family: var(--mono); font-size: 10px; font-weight: 600; }
.price-pill-chg.pos { color: var(--green); }
.price-pill-chg.neg { color: var(--red); }
.price-pill-chg.neu { color: var(--muted2); }
@media (max-width: 900px) { #price-bar { display: none; } }

/* SECTION_CSS_TABS */
/* tabs-nav supprimé — remplacé par sidebar */
#tab-content { flex: 1; min-height: 0; }
.tab-panel { display: none; padding: 20px 22px 40px; }
.tab-panel.active { display: block; }

/* Market Tickers Tab1 */
#t1-market-tickers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media(max-width:900px) { #t1-market-tickers { grid-template-columns: repeat(2,1fr); } }
.mkt-ticker-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s;
  position: relative; overflow: hidden;
}
.mkt-ticker-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.mkt-ticker-card.btc::before  { background: #FFA726; }
.mkt-ticker-card.eth::before  { background: #42A5F5; }
.mkt-ticker-card.sol::before  { background: #AB7CF7; }
.mkt-ticker-card.hype::before { background: #42A5F5; }
.mkt-ticker-card:hover { border-color: var(--border2); }
.mkt-ticker-coin {
  font-family: var(--sans); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted2);
}
.mkt-ticker-price {
  font-family: var(--mono); font-size: 22px; font-weight: 800;
  color: var(--text); line-height: 1; letter-spacing: -.02em;
}
.mkt-ticker-chg {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 4px;
}
.mkt-ticker-chg.pos { color: var(--green); }
.mkt-ticker-chg.neg { color: var(--red); }
.mkt-ticker-chg.neu { color: var(--muted2); }

/* SECTION_CSS_MARKET_CLOCK */
#market-clock {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  background: transparent; border: none; height: auto; padding: 0;
}
.clock-item { display: flex; align-items: center; gap: 6px; }
.clock-label { font-family: var(--sans); font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted2); }
.clock-val { font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--muted); }
.clock-val.urgent { color: var(--orange); }
.clock-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); display: inline-block; animation: pulse 2s infinite; }
.clock-sep { width: 1px; height: 12px; background: var(--border2); }
@media (max-width: 768px) { #market-clock { display: none; } }

/* ── iPhone — optimisations supplémentaires ── */
@media (max-width: 480px) {
  #sidebar { width: 82vw; max-width: 280px; }
  /* Éviter overflow horizontal global */
  #main-content { overflow-x: hidden; }
  /* Price pills du header cachées sur iPhone */
  .price-pill { display: none; }

  /* Header encore plus compact sur iPhone */
  #header { padding-left: 56px; padding-right: 8px; gap: 6px; }
  #header-right { gap: 6px; }

  /* Adresse wallet : tronquée ou cachée sur très petit écran */
  #address-display { display: none; }

  /* Bouton Connecter : label raccourci */
  #btn-wallet { font-size: 11px; padding: 0 10px; }

  /* Tab panels : réduire le padding latéral */
  .tab-panel { padding: 14px 12px 60px; }

  /* Tous les boutons d'action principaux : touch target 44px */
  .btn-sm, .t3-period-btn, .t3-eq-period-btn,
  .t4-api-btn, button.focus-btn {
    min-height: 36px;
    padding: 6px 12px;
  }

  /* Fond safe-area pour iPhone avec notch/Dynamic Island */
  #header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(52px + env(safe-area-inset-top, 0px));
  }
  #sidebar-toggle {
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
