/* =============================================
   LA BOBINE STORIES — MAIN STYLESHEET
   Esthétique : Cinéma industriel / Éditorial
   ============================================= */

:root {
  /* Couleurs principales */
  --bg:           #0e0e0e;
  --bg-2:         #161616;
  --bg-3:         #1e1e1e;
  --border:       #2a2a2a;
  --border-light: #333333;

  /* Texte */
  --text:         #f0ede8;
  --text-muted:   #888880;
  --text-faint:   #555550;

  /* Accent — Orange Bobine */
  --accent:       #f5a623;
  --accent-dark:  #c4851a;
  --accent-glow:  rgba(245, 166, 35, 0.15);

  /* Statuts */
  --green:        #4caf7d;
  --red:          #e05c5c;
  --blue:         #5c8ee0;

  /* Sidebar */
  --sidebar-w:    220px;

  /* Typographie */
  --font-display: 'Bebas Neue', sans-serif;
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;

  /* Rayons */
  --radius:       6px;
  --radius-lg:    12px;

  /* Transitions */
  --ease:         cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  font-size: 14px;
  line-height: 1.6;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: relative;
  z-index: 10;
  /* Electron : la sidebar entiere est une zone de drag pour deplacer la fenetre */
  -webkit-app-region: drag;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.logo-mark {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-title {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 1px;
  color: var(--text);
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--accent);
  margin-top: 1px;
}

/* Nav links */
.nav-links {
  list-style: none;
  flex: 1;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Les liens doivent rester cliquables meme dans la zone de drag */
  -webkit-app-region: no-drag;
}

/* Logo non-draggable aussi pour cohérence */
.sidebar-logo {
  -webkit-app-region: no-drag;
}

.sidebar-footer {
  -webkit-app-region: no-drag;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: all 0.15s var(--ease);
  position: relative;
  letter-spacing: 0.2px;
}

.nav-item:hover {
  background: var(--bg-3);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  font-size: 11px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.nav-label {
  font-size: 13px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-version {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 1px;
}

/* ══════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── TOPBAR ── */
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--bg);
  flex-shrink: 0;
  /* Electron : la topbar permet aussi de deplacer la fenetre */
  -webkit-app-region: drag;
}

/* Les elements interactifs de la topbar restent cliquables */
.topbar .btn,
.topbar button,
.topbar input,
.topbar select {
  -webkit-app-region: no-drag;
}

.page-title {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--text);
  font-weight: 400;
  -webkit-app-region: no-drag;
}

/* ── PAGE CONTENT ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ══════════════════════════════════════
   BOUTONS
══════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s var(--ease);
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0e0e0e;
}
.btn-primary:hover { background: #f7b840; transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(224, 92, 92, 0.3);
}
.btn-danger:hover { background: rgba(224, 92, 92, 0.1); }

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

/* ══════════════════════════════════════
   CARTES
══════════════════════════════════════ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 16px;
  text-transform: uppercase;
}

/* ══════════════════════════════════════
   FORMULAIRES
══════════════════════════════════════ */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 9px 12px;
  transition: border-color 0.15s;
  outline: none;
  -webkit-appearance: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-control::placeholder { color: var(--text-faint); }

select.form-control { cursor: pointer; }

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  gap: 16px;
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ══════════════════════════════════════
   TABLEAU
══════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background 0.1s;
}

tbody tr:hover {
  background: var(--bg-3);
}

.td-mono {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.td-amount {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}

/* ══════════════════════════════════════
   BADGES / STATUTS
══════════════════════════════════════ */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge-green  { background: rgba(76, 175, 125, 0.15); color: var(--green); }
.badge-orange { background: rgba(245, 166, 35, 0.15); color: var(--accent); }
.badge-red    { background: rgba(224, 92, 92, 0.15);  color: var(--red); }
.badge-blue   { background: rgba(92, 142, 224, 0.15); color: var(--blue); }
.badge-gray   { background: var(--bg-3); color: var(--text-muted); }

/* ══════════════════════════════════════
   DASHBOARD STATS
══════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 3px;
  height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}

.stat-card:hover::after { opacity: 1; }

.stat-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 32px;
  letter-spacing: 1px;
  color: var(--text);
  line-height: 1;
}

.stat-value.accent { color: var(--accent); }

.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ══════════════════════════════════════
   SECTION HEADER (dans les pages)
══════════════════════════════════════ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--text-muted);
}

/* ══════════════════════════════════════
   SEARCH BAR
══════════════════════════════════════ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  max-width: 320px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-faint); }

/* ══════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-faint);
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: 14px;
  margin-bottom: 20px;
  color: var(--text-muted);
}

/* ══════════════════════════════════════
   MODAL
══════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s var(--ease);
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s var(--ease);
  overflow: hidden;
}

.modal-lg { max-width: 800px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 400;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.1s;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   TOAST
══════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.2s var(--ease);
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ══════════════════════════════════════
   DIVIDER
══════════════════════════════════════ */
.divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ══════════════════════════════════════
   ACTION BUTTONS (tableau)
══════════════════════════════════════ */
.actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ══════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ══════════════════════════════════════
   BOTTOM NAV MOBILE — masquee par defaut
══════════════════════════════════════ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 50;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
  -webkit-app-region: no-drag;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--text-faint);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-body);
  transition: color 0.15s;
  flex: 1;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-more-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--text-faint);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-body);
  transition: color 0.15s;
  flex: 1;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-more-btn.active { color: var(--accent); }
.mn-icon { font-size: 18px; line-height: 1; }
.mn-label { font-size: 9px; letter-spacing: 0.3px; white-space: nowrap; }

/* Drawer */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 60;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.15s var(--ease);
}
.mobile-drawer-overlay.open { display: block; }

.mobile-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-2);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  z-index: 70;
  padding: 12px 16px 32px;
  transform: translateY(100%);
  transition: transform 0.25s var(--ease);
  -webkit-app-region: no-drag;
}
.mobile-drawer.open { transform: translateY(0); }

.mobile-drawer-handle {
  width: 36px; height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.mobile-drawer-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--text-faint);
  margin-bottom: 12px;
  padding: 0 4px;
}
.mobile-drawer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.mobile-drawer-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-muted);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-drawer-item:active,
.mobile-drawer-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}
.mdi-icon { font-size: 22px; }
.mdi-label { font-size: 11px; font-weight: 500; }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }

  .page-content {
    padding: 14px 12px;
    padding-bottom: 80px;
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }

  .topbar {
    padding: 0 16px;
    -webkit-app-region: no-drag;
  }
  .page-title { font-size: 18px; letter-spacing: 1px; }
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Afficher la bottom nav uniquement sur mobile */
  .mobile-nav { display: flex; }
}

/* Empecher le drawer ferme d'intercepter les touches */
.mobile-drawer:not(.open) {
  pointer-events: none;
}

/* ══════════════════════════════════════
   IOS PWA — AJUSTEMENTS SPECIFIQUES
══════════════════════════════════════ */

/* Safe area pour iPhone avec encoche/Dynamic Island */
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar {
    padding-top: max(0px, env(safe-area-inset-top));
    height: calc(60px + env(safe-area-inset-top));
  }
  .mobile-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    height: calc(60px + env(safe-area-inset-bottom));
  }
  .page-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
  .mobile-drawer {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
}

/* Empecher le zoom auto sur les champs de formulaire iOS (font-size < 16px) */
@media (max-width: 600px) {
  input, select, textarea {
    font-size: 16px !important;
  }
  .form-label {
    font-size: 11px !important;
  }
}

/* Eviter le rebond de scroll iOS sur l'app entiere */
html, body {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* Curseur pointer sur tous les elements cliquables iOS */
button, label, .nav-item, .mobile-nav-item,
.mobile-nav-more-btn, .mobile-drawer-item {
  cursor: pointer;
}

/* ── ACTIONS EN COLONNE SUR MOBILE ── */
@media (max-width: 600px) {
  .actions {
    flex-wrap: wrap;
    gap: 4px;
  }
  .actions .btn {
    flex: 0 0 auto;
  }
}

/* ══════════════════════════════════════
   TABLEAU MOBILE — carte par ligne
══════════════════════════════════════ */
@media (max-width: 600px) {

  /* Transformer le tableau en liste de cartes */
  .table-wrapper table,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper td {
    display: block;
    width: 100%;
  }

  /* Masquer les en-têtes de colonnes */
  .table-wrapper thead {
    display: none;
  }

  /* Chaque ligne = une carte */
  .table-wrapper tbody tr {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 12px;
    position: relative;
  }
  .table-wrapper tbody tr:hover {
    background: var(--bg-2);
  }

  /* Masquer les cellules vides ou actions par defaut */
  .table-wrapper td {
    padding: 2px 0;
    border: none;
    font-size: 13px;
  }

  /* Masquer les colonnes peu utiles sur mobile */
  .table-wrapper td:nth-child(4),
  .table-wrapper td:nth-child(5) {
    display: none;
  }

  /* La cellule actions toujours visible et en bas */
  .table-wrapper td:last-child {
    display: block;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  /* Boutons en ligne qui wrappent */
  .table-wrapper .actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .table-wrapper .actions .btn {
    flex: 0 0 auto;
    font-size: 11px;
    padding: 5px 10px;
  }
}

/* Stat cards cliquables */
.stat-card[onclick] {
  transition: transform 0.15s var(--ease), border-color 0.15s;
  border: 1px solid var(--border);
}
.stat-card[onclick]:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.stat-card[onclick]:active {
  transform: translateY(0);
}
