/* ══════════════════════════════════════════════════════════════════════════════
   KikiskoTrading — style_responsive.css  v2.0
   Remplace / complète style.css + style_additions.css pour la partie responsive
   • Sidebar rétractable (desktop ET mobile)
   • Nav inférieure fixe sur téléphone
   • Settings : seul le Money Management est éditable (AutoTuner → read-only)
   • Signaux : onglet Alpaca/Actions intégré
   • Admin : pouvoirs étendus (ban temp, reset PIN, changement mode bloqué pour admins)
   • Clés API : champs sécurisés, autocomplete=off, show/hide toggle
   • Change PIN : page dédiée propre
   • PDF : bouton bien placé
   ══════════════════════════════════════════════════════════════════════════════ */

/* ─── VARIABLES ──────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w:       220px;
  --sidebar-w-mini:  64px;
  --sidebar-w-0:     0px;
  --header-h:        56px;
  --transition-sidebar: .22s cubic-bezier(.4,0,.2,1);
  --radius-pill:     999px;
}

/* ─── APP SHELL ──────────────────────────────────────────────────────────────── */
html, body { height: 100%; }
body.app-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.app-header {
  height: var(--header-h);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--bg-header, rgba(5,4,8,.97));
  border-bottom: 1px solid var(--border-soft);
  backdrop-filter: blur(14px);
  gap: 12px;
}

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

/* ── Bouton hamburger (visible desktop ET mobile) ─── */
#sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-md, 8px);
  flex-shrink: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
}
#sidebar-toggle:hover {
  background: rgba(255,255,255,.07);
  color: var(--text-main);
}
#sidebar-toggle svg { pointer-events: none; }

.logo {
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--gold, #f0b90b);
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

/* ─── LAYOUT ─────────────────────────────────────────────────────────────────── */
.app-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ─── SIDEBAR DESKTOP ────────────────────────────────────────────────────────── */
.left-nav {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(255,255,255,.025);
  border-right: 1px solid var(--border-soft);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition-sidebar);
  position: relative;
  z-index: 50;
}

/* État rétracté (desktop) */
body.sidebar-mini .left-nav {
  width: var(--sidebar-w-mini);
  padding: 14px 6px;
}
body.sidebar-mini .left-nav button span { display: none; }
body.sidebar-mini .left-nav button {
  justify-content: center;
  padding: 10px;
  text-align: center;
}

/* Séparateur de section */
.left-nav .nav-section-title {
  font-size: .65rem;
  color: var(--text-soft, #555);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 10px 12px 4px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition-sidebar);
}
body.sidebar-mini .left-nav .nav-section-title {
  opacity: 0;
  height: 0;
  padding: 0;
}

.left-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: var(--radius-md, 8px);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  width: 100%;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.left-nav button:hover {
  background: rgba(255,255,255,.06);
  color: var(--text-main);
}
.left-nav button.active {
  background: var(--gold-dim, rgba(240,185,11,.12));
  color: var(--gold, #f0b90b);
}
.left-nav button svg { flex-shrink: 0; }
.left-nav button span { overflow: hidden; transition: opacity var(--transition-sidebar); }

/* Overlay foncé quand sidebar ouverte en mobile overlay */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 149;
  backdrop-filter: blur(2px);
}
body.sidebar-overlay-open #sidebar-backdrop { display: block; }

/* ─── MAIN CONTENT ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px 60px;
  min-width: 0;
}

/* ─── RESPONSIVE — LARGE (1200px) ───────────────────────────────────────────── */
@media (max-width: 1200px) {
  .main-content { padding: 16px 18px 60px; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
}

/* ─── RESPONSIVE — TABLET (900px) ───────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 200px; }

  body:not(.sidebar-mini) .left-nav { width: var(--sidebar-w); }

  .settings-dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .dashboard-market-header { flex-wrap: wrap; gap: .5rem; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
}

/* ─── RESPONSIVE — TABLET SMALL (768px) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .header-right .logo-text { display: none; }

  /* Tableau historique compact */
  .table th:nth-child(4),
  .table td:nth-child(4) { display: none; } /* Entrée */

  .tabs { flex-wrap: wrap; gap: 4px; }
  .tab-button { flex: 1; min-width: 80px; text-align: center; padding: 6px 8px; font-size: 12px; }

  h1 { font-size: .95rem; }

  .settings-dashboard-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ─── RESPONSIVE — MOBILE (600px) ───────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Layout vertical */
  .app-layout { flex-direction: column; }

  /* Sidebar → slide-in overlay depuis la gauche */
  .left-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w) !important;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform var(--transition-sidebar);
    background: var(--bg-card, #161a23);
    border-right: 1px solid var(--border-soft);
    overflow-y: auto;
    padding: 12px 8px;
  }

  /* Quand le sidebar est ouvert en mobile */
  body.sidebar-mobile-open .left-nav { transform: translateX(0); }

  /* Main content */
  .main-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px 12px;
    min-height: 0;
  }

  /* Header compact */
  .app-header { height: 50px; padding: 0 12px; }
  .logo { font-size: .85rem; }

  /* KPI grid plein */
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .kpi-card { padding: 10px 12px; }
  .kpi-value { font-size: 1.15rem; }

  /* Cards */
  .card { border-radius: 10px; padding: 12px; }

  /* Dashboard market block */
  .dashboard-market-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .dashboard-market-header .btn-ghost { align-self: flex-start; }

  /* Tables */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 500px; }
  .table th, .table td { padding: 6px 8px; font-size: .8rem; }

  /* Overlays / Modals full screen mobile */
  .modal-box {
    width: 100vw;
    max-width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 80vh;
    overflow-y: auto;
  }
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .trading-overlay-box {
    width: 100vw !important;
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    margin: 0 !important;
  }
  .trading-overlay {
    align-items: flex-end !important;
  }

  /* Overlay onglets scroll horizontal */
  .overlay-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .overlay-tab  { font-size: .75rem; padding: .45rem .7rem; white-space: nowrap; }

  /* Settings card */
  .settings-card { padding: 12px; }
  .dual-fields { flex-direction: column; gap: .4rem; }
  .dual-fields input { width: 100%; }

  /* Signals page */
  #sig-chart-candles { height: 240px !important; }
  .sig-market-tabs { flex-wrap: nowrap; overflow-x: auto; }

  /* Admin table */
  .admin-table th:nth-child(5),
  .admin-table td:nth-child(5),
  .admin-table th:nth-child(6),
  .admin-table td:nth-child(6) { display: none; }

  /* History table compact */
  .table th:nth-child(3),
  .table td:nth-child(3) { display: none; }

  /* PDF export btn */
  .history-nav a[href*="export_month_pdf"] { margin-left: auto; }
}

/* ─── RESPONSIVE — VERY SMALL (380px) ───────────────────────────────────────── */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr 1fr !important; }
  .kpi-value { font-size: 1rem; }
  .logo { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   SETTINGS — MONEY MANAGEMENT (seule section éditable)
══════════════════════════════════════════════════════════════════════════════ */

/* Section Money Management mise en avant */
.settings-mm-only {
  max-width: 520px;
  margin: 0 auto;
}
.settings-mm-card {
  background: var(--card-bg, #161a23);
  border: 1px solid var(--gold-dim, rgba(240,185,11,.2));
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 0 0 1px rgba(240,185,11,.06) inset;
}
.settings-mm-card h3 {
  margin: 0 0 1rem;
  font-size: .82rem;
  color: var(--gold, #f0b90b);
  text-transform: uppercase;
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--border-soft);
}

/* Bannière lecture seule AutoTuner */
.autotuner-readonly-banner {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: rgba(77,163,255,.07);
  border: 1px solid rgba(77,163,255,.2);
  border-radius: 8px;
  padding: .6rem .9rem;
  font-size: .78rem;
  color: #4da3ff;
  line-height: 1.5;
  margin-bottom: .8rem;
}
.autotuner-readonly-grid {
  opacity: .45;
  pointer-events: none;
  user-select: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .5rem;
}
.autotuner-readonly-grid input,
.autotuner-readonly-grid select {
  cursor: not-allowed !important;
  background: var(--input-bg, #1e2230) !important;
}
.autotuner-section-title {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: .6rem;
}

/* ══════════════════════════════════════════════════════════════════════════════
   SIGNALS — Onglets SPOT / FUTURES / ACTIONS (Alpaca)
══════════════════════════════════════════════════════════════════════════════ */
.sig-market-tabs {
  display: flex;
  gap: .4rem;
  margin-bottom: .8rem;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: .4rem;
}
.sig-market-tab {
  padding: .35rem .9rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .05em;
  text-transform: uppercase;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.sig-market-tab:hover   { background: rgba(255,255,255,.05); color: var(--text-main); }
.sig-market-tab.active  {
  background: var(--gold-dim, rgba(240,185,11,.12));
  color: var(--gold, #f0b90b);
  border-color: rgba(240,185,11,.3);
}
.sig-market-tab[data-market="actions"].active {
  background: rgba(129,199,132,.1);
  color: #81c784;
  border-color: rgba(129,199,132,.35);
}

/* Zone Alpaca (actions) */
#sig-actions-zone .sig-scan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .6rem;
  margin-top: .8rem;
}
.sig-action-card {
  background: var(--card-bg, #161a23);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: .7rem .9rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  transition: border-color .15s;
}
.sig-action-card.signal-buy-card  { border-color: rgba(46,204,113,.35); }
.sig-action-card.signal-sell-card { border-color: rgba(231,76,60,.35); }
.sig-action-card:hover { border-color: var(--gold-dim, rgba(240,185,11,.3)); }
.sig-action-card .ac-sym   { font-size: .88rem; font-weight: 700; color: var(--text-main); }
.sig-action-card .ac-price { font-size: .78rem; color: var(--text-muted); }
.sig-action-card .ac-sig   { font-size: .72rem; margin-top: .2rem; }
.sig-action-card .ac-reason{ font-size: .7rem; color: var(--text-soft); margin-top: .2rem; line-height: 1.4; }
.sig-action-card .ac-meta  { display: flex; gap: .5rem; font-size: .7rem; color: var(--text-muted); flex-wrap: wrap; }

/* Timeframe alpaca (seule 1D dispo sur Alpaca) */
#sig-tf-alpaca-note {
  font-size: .75rem;
  color: var(--text-soft);
  font-style: italic;
  margin-bottom: .5rem;
}

/* ══════════════════════════════════════════════════════════════════════════════
   CLÉS API — Sécurité : show/hide, autocomplete off
══════════════════════════════════════════════════════════════════════════════ */
.api-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.api-field-wrap input {
  flex: 1;
  padding-right: 2.6rem !important;
  font-family: 'JetBrains Mono', 'Courier New', monospace !important;
  font-size: .82rem !important;
  letter-spacing: .06em;
}
.api-field-wrap input[type="text"][data-masked="1"] {
  -webkit-text-security: disc;
  text-security: disc;
}
.api-show-toggle {
  position: absolute;
  right: .5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: .2rem;
  display: flex;
  align-items: center;
  transition: color var(--transition-fast);
}
.api-show-toggle:hover { color: var(--text-main); }
.api-show-toggle svg { width: 15px; height: 15px; }

/* Badge sécurité sur les champs sensibles */
.field-secure-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .68rem;
  color: var(--text-soft);
  margin-top: .25rem;
}
.field-secure-badge svg { width: 10px; height: 10px; }

/* Avertissement LIVE rouge */
.api-live-warning {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: rgba(231,76,60,.08);
  border: 1px solid rgba(231,76,60,.25);
  border-radius: 8px;
  padding: .6rem .8rem;
  margin-bottom: .8rem;
  font-size: .78rem;
  color: #e74c3c;
  line-height: 1.45;
}

/* ══════════════════════════════════════════════════════════════════════════════
   ADMIN — Pouvoirs étendus
══════════════════════════════════════════════════════════════════════════════ */
.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th {
  padding: .5rem .75rem;
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
}
.admin-table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid rgba(255,255,255,.04);
  vertical-align: middle;
}
.admin-table tr:hover td { background: rgba(255,255,255,.025); }

/* Badges rôle */
.role-badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: var(--radius-pill);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.role-admin { background: rgba(240,185,11,.15); color: var(--gold, #f0b90b); border: 1px solid rgba(240,185,11,.3); }
.role-user  { background: rgba(255,255,255,.06); color: var(--text-muted);   border: 1px solid var(--border-soft); }

/* Badges mode */
.mode-badge-live { background: rgba(231,76,60,.12); color: #e74c3c; border: 1px solid rgba(231,76,60,.3); padding: .1rem .45rem; border-radius: var(--radius-pill); font-size: .68rem; font-weight: 700; }
.mode-badge-demo { background: rgba(46,204,113,.1); color: #2ecc71; border: 1px solid rgba(46,204,113,.25); padding: .1rem .45rem; border-radius: var(--radius-pill); font-size: .68rem; font-weight: 700; }

/* Ligne admin bloqué mode */
.admin-mode-locked {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  color: var(--text-soft);
  font-style: italic;
}
.admin-mode-locked svg { width: 11px; height: 11px; }

/* Actions admin */
.admin-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.admin-actions .btn-sm { padding: .25rem .6rem; font-size: .75rem; border-radius: 6px; cursor: pointer; border: none; }
.btn-edit-user   { background: rgba(77,163,255,.15); color: #4da3ff; border: 1px solid rgba(77,163,255,.25) !important; }
.btn-toggle-user { background: rgba(255,183,0,.1);   color: #ffb700; border: 1px solid rgba(255,183,0,.25) !important; }
.btn-delete-user { background: rgba(231,76,60,.1);   color: #e74c3c; border: 1px solid rgba(231,76,60,.25) !important; }
.btn-reset-pin   { background: rgba(156,39,176,.1);  color: #ce93d8; border: 1px solid rgba(156,39,176,.25) !important; }

/* Ban temporaire select */
.ban-duration-wrap {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.ban-duration-wrap select {
  font-size: .78rem;
  padding: .2rem .5rem;
  background: var(--input-bg, #1e2230);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
}

/* Stats rapides admin */
.admin-stat-mini {
  display: flex;
  gap: .2rem;
  font-size: .72rem;
  color: var(--text-soft);
  flex-direction: column;
}
.admin-stat-mini strong { color: var(--text-main); }

/* ══════════════════════════════════════════════════════════════════════════════
   CHANGE PIN — Page dédiée
══════════════════════════════════════════════════════════════════════════════ */
.pin-section-card {
  max-width: 400px;
  background: var(--card-bg, #161a23);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 1.4rem;
  margin: 1.5rem 0;
}
.pin-section-card h3 {
  margin: 0 0 1rem;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: .7rem;
}
.pin-field input {
  letter-spacing: .2em;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  text-align: center;
  width: 100%;
  max-width: 200px;
}

/* Lien "Changer mon PIN" dans la sidebar */
.nav-pin-link {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-pin-link a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius-md, 8px);
  font-size: 13px;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-pin-link a:hover { background: rgba(255,255,255,.06); color: var(--text-main); }
body.sidebar-mini .nav-pin-link a span { display: none; }
body.sidebar-mini .nav-pin-link a { justify-content: center; padding: 8px; }

/* ══════════════════════════════════════════════════════════════════════════════
   NOTIFICATIONS — Push subscribe button states
══════════════════════════════════════════════════════════════════════════════ */
#btn-push-subscribe {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .75rem;
  font-size: .8rem;
  white-space: nowrap;
}
#btn-push-subscribe.active { color: var(--gold, #f0b90b); }
#btn-push-subscribe.active svg { stroke: var(--gold, #f0b90b); }

/* Toast de notification in-app */
.push-toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  left: auto;
  width: min(340px, calc(100vw - 32px));
  background: var(--card-bg, #161a23);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: .9rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  z-index: 9999;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  animation: toast-in .3s ease;
}
.push-toast.hiding { animation: toast-out .25s ease forwards; }
@keyframes toast-in  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { from { opacity:1; transform:translateY(0); } to { opacity:0; transform:translateY(16px); } }
.push-toast-icon { font-size: 1.2rem; flex-shrink: 0; }
.push-toast-body { flex: 1; min-width: 0; }
.push-toast-title { font-size: .85rem; font-weight: 700; color: var(--text-main); }
.push-toast-msg   { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.push-toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  line-height: 1;
}

/* ══════════════════════════════════════════════════════════════════════════════
   PRINT — amélioration pour l'export PDF
══════════════════════════════════════════════════════════════════════════════ */
@media print {
  .app-header,
  .left-nav,
  #sidebar-backdrop,
  .btn-ghost,
  .modal-overlay,
  .trading-overlay { display: none !important; }
  .main-content { padding: 0 !important; }
  .page { display: block !important; }
  .page:not(.active) { display: none !important; }
}
