@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f4f6f9;
  color: #1c2333;
}
a { text-decoration: none; color: inherit; }

.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 230px;
  background: #0b1220;
  color: #dfe6f0;
  padding: 24px 18px;
  flex-shrink: 0;
}
.admin-sidebar .brand { font-size: 16px; font-weight: 700; color: #fff; margin-bottom: 30px; padding: 0 8px; }
.admin-sidebar nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 4px;
  color: #b8c1d1;
}
.admin-sidebar nav a { transition: background .13s, color .13s; }
.admin-sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-sidebar nav a.active {
  background: rgba(111,168,220,0.16); color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 #6fa8dc;
}
.admin-sidebar .view-site { display: block; margin-top: 24px; padding: 10px 12px; font-size: 13px; color: #6fa8dc; }
.admin-sidebar form { margin-top: 18px; }
.admin-sidebar button.logout {
  width: 100%; padding: 10px; background: rgba(255,255,255,0.06); border: none; border-radius: 8px;
  color: #dfe6f0; font-size: 13px; cursor: pointer;
}

.admin-main { flex: 1; padding: 36px 44px; max-width: 1000px; }
.admin-main h1 { font-size: 24px; margin: 0 0 6px; }
.admin-sub { color: #6b7382; font-size: 14px; margin-bottom: 28px; }

.card { background: #fff; border-radius: 12px; padding: 24px; border: 1px solid #edf0f4; box-shadow: 0 1px 3px rgba(20,24,31,0.05); margin-bottom: 20px; }
.card > h3:first-child, .card > h2:first-child { margin-top: 0; }
.stat-row { display: flex; gap: 20px; margin-bottom: 24px; }
.stat-card { flex: 1; }
.stat-num { font-size: 30px; font-weight: 700; }
.stat-label { font-size: 13px; color: #6b7382; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #3a4152; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid #dde2ea; border-radius: 8px; font-size: 14px;
  font-family: inherit; margin-bottom: 16px; background: #fbfbfd;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input[type=text]:focus, input[type=email]:focus, input[type=tel]:focus, input[type=number]:focus, input[type=password]:focus, textarea:focus, select:focus {
  outline: none; border-color: #4a86c8; background: #fff;
  box-shadow: 0 0 0 3px rgba(74,134,200,0.15);
}
textarea { min-height: 90px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

.richtoolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.richtoolbar-btn {
  min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid #dde3ec; border-radius: 6px;
  background: #f8f9fb; color: #3a4152; font-size: 13px; font-family: inherit; cursor: pointer;
}
.richtoolbar-btn:hover { background: #eef1f5; }
.richtoolbar-size {
  height: 30px; border: 1px solid #dde3ec; border-radius: 6px; background: #f8f9fb;
  color: #3a4152; font-size: 12px; font-family: inherit; padding: 0 6px; cursor: pointer;
}
.richtoolbar-hint { font-size: 11px; color: #9aa2b2; }
:root[data-theme="dark"] .richtoolbar-btn,
:root[data-theme="dark"] .richtoolbar-size { background: #2a3548; color: #d3dae6; border-color: #3a4661; }
:root[data-theme="dark"] .richtoolbar-btn:hover { background: #333f56; }
:root[data-theme="dark"] .richtoolbar-hint { color: #7d8699; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit; line-height: 1.2;
  transition: background .15s, box-shadow .15s, transform .06s, border-color .15s;
  -webkit-user-select: none; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(74,134,200,0.35); }
.btn-primary { background: #4a86c8; color: #fff; box-shadow: 0 1px 2px rgba(74,134,200,0.35); }
.btn-primary:hover { background: #3f78b6; }
.btn-danger { background: #fbe6e6; color: #a13333; }
.btn-danger:hover { background: #f5d3d3; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost { background: #eef1f5; color: #3a4152; }
.btn-ghost:hover { background: #e3e8ef; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eef0f3; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #8a92a3; }
.actions-cell { display: flex; gap: 6px; }

.item-row { display: flex; align-items: flex-start; gap: 16px; padding: 16px 0; border-bottom: 1px solid #eef0f3; }
.item-row:last-child { border-bottom: none; }
.item-thumb { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #eef1f5; }
.item-body { flex: 1; }
.item-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-new { background: #e4f5e9; color: #206a3c; }
.badge-read { background: #eef1f5; color: #6b7382; }

.msg-unread { border-left: 3px solid #4a86c8; padding-left: 14px; background: #f7fafd; border-radius: 0 8px 8px 0; }

.upload-drop {
  border: 2px dashed #c9d2e0; border-radius: 12px; padding: 30px; text-align: center; color: #6b7382; margin-bottom: 16px;
}

/* ── Lignes éditables (réglages impression, etc.) ────────────────────────── */
.ps-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid #eef0f3;
}
.ps-row:last-child { border-bottom: none; }
.ps-row-fields {
  flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0;
}
.ps-row-fields input[type=text], .ps-row-fields input[type=number] {
  margin-bottom: 0; width: auto;
}
.ps-field-label { flex: 1 1 160px; min-width: 120px; }
.ps-field-price { width: 110px; flex: 0 0 auto; }
.ps-field-qty { width: 90px; flex: 0 0 auto; }
.ps-field-code { width: 130px; flex: 0 0 auto; text-transform: uppercase; }
.ps-field-discount { width: 80px; flex: 0 0 auto; }
.ps-field-note { flex: 1 1 160px; min-width: 140px; }
.ps-suffix { font-size: 13px; color: #6b7382; white-space: nowrap; }
.ps-checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #3a4152; font-weight: 500; white-space: nowrap; }
.ps-checkbox input { width: auto; margin: 0; accent-color: #4a86c8; }
.ps-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.ps-row-actions form { display: inline-flex; }
.ps-add-row { margin-top: 4px; padding-top: 14px; border-top: 1px dashed #dde2ea; }
.ps-empty { color: #8a92a3; font-size: 13px; padding: 8px 0; }

@media (max-width: 640px) {
  .ps-row { flex-wrap: wrap; }
  .ps-row-fields { width: 100%; }
  .ps-row-actions { width: 100%; justify-content: flex-end; }
}

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0b1220; }
.login-box { background: #fff; padding: 40px; border-radius: 14px; width: 340px; }
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box .admin-sub { margin-bottom: 24px; }
.error-msg { background: #fbe6e6; color: #a13333; padding: 11px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; margin-bottom: 16px; border: 1px solid #f3d0d0; }
.success-msg { background: #e4f5e9; color: #206a3c; padding: 11px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; margin-bottom: 16px; border: 1px solid #c5e8d1; }

/* ── Barre supérieure mobile (hamburger) ─────────────────────────────────── */
.admin-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* ── Responsive : téléphone / petites tablettes ──────────────────────────── */
@media (max-width: 900px) {
  .admin-shell { flex-direction: column; }

  .admin-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #0b1220; color: #fff; padding: 12px 16px;
    position: sticky; top: 0; z-index: 300;
  }
  .admin-topbar .brand { font-size: 15px; font-weight: 700; color: #fff; }
  .hamburger-btn {
    background: rgba(255,255,255,0.08); border: none; color: #fff; font-size: 20px;
    line-height: 1; padding: 8px 12px; border-radius: 8px; cursor: pointer;
  }

  .admin-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 80vw; max-width: 300px;
    transform: translateX(-100%); transition: transform .25s ease;
    z-index: 400; overflow-y: auto; padding-top: 18px;
  }
  .admin-sidebar.open { transform: translateX(0); }

  .sidebar-backdrop.visible {
    display: block; position: fixed; inset: 0; background: rgba(11,18,32,0.5); z-index: 390;
  }

  .admin-main { padding: 20px 16px; max-width: 100%; }
  .admin-main h1 { font-size: 20px; }

  #globalPreviewPanel { width: 100vw !important; }

  .field-grid { grid-template-columns: 1fr; }
  .stat-row { flex-direction: column; }

  .card { padding: 16px; border-radius: 10px; }

  table { display: block; }
  table thead { display: none; }
  table tbody, table tr, table td { display: block; width: 100% !important; }
  table tr { border-bottom: 2px solid #eef0f3; padding: 10px 0; }
  table td { border-bottom: none; padding: 4px 0; }
  table td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; font-weight: 700;
    text-transform: uppercase; color: #8a92a3; margin-bottom: 2px;
  }

  .item-row { flex-wrap: wrap; }
  .item-thumb { width: 72px; height: 72px; }
  .actions-cell { flex-wrap: wrap; }

  /* Cibles tactiles plus confortables au doigt (≈44px de haut) */
  .btn { padding: 12px 16px; min-height: 44px; }
  .btn-sm { padding: 9px 14px; font-size: 13px; min-height: 38px; }
  input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], select {
    padding: 12px 14px; font-size: 16px; /* 16px = évite le zoom auto iOS au focus */
  }
  /* Une action = pleine largeur quand elle est seule sur sa ligne de formulaire */
  .item-form .btn { flex: 1 1 auto; }
}

@media (max-width: 480px) {
  .admin-main { padding: 16px 12px; }
  .item-thumb { width: 64px; height: 64px; }
  .admin-main h1 { font-size: 19px; }
}

/* Filet de sécurité : un <label> en display:flex contenant une case à cocher
   suivie de texte long (parfois coupé par un <code> ou un <a> inline) éclate
   en colonnes illisibles sur mobile faute de flex-wrap. On force le retour
   à la ligne partout où ce motif apparaît, sans toucher aux labels normaux
   (ceux sans case à cocher, ex. "Titre", ne sont pas concernés). */
@media (max-width: 900px) {
  label:has(> input[type="checkbox"]) { flex-wrap: wrap; row-gap: 4px; }
}

/* Détail d'une commande de tirages : coordonnées client + tableau des photos
   côte à côte sur desktop, empilés sur mobile. */
.order-detail-grid { display: grid; grid-template-columns: 280px 1fr; gap: 24px; }
.order-detail-grid > * { min-width: 0; }
@media (max-width: 900px) {
  .order-detail-grid { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════════════════════
   MODE SOMBRE — tout est scopé sous [data-theme="dark"] : le mode clair (défaut)
   reste strictement inchangé. La palette de l'admin étant cohérente, on remappe
   les couleurs de classe ET les couleurs inline les plus fréquentes.
   ══════════════════════════════════════════════════════════════════════════ */
:root[data-theme="dark"] body { background: #0f1622; color: #e7ecf3; }
:root[data-theme="dark"] .admin-main h1 { color: #f2f5f9; }
:root[data-theme="dark"] .admin-sub { color: #9aa4b4; }
:root[data-theme="dark"] a { color: inherit; }

:root[data-theme="dark"] .card { background: #1a2334; border-color: #2b3648; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
:root[data-theme="dark"] .stat-num { color: #f2f5f9; }
:root[data-theme="dark"] .stat-label { color: #9aa4b4; }

:root[data-theme="dark"] label { color: #c7cfdb; }
:root[data-theme="dark"] input[type=text], :root[data-theme="dark"] input[type=email],
:root[data-theme="dark"] input[type=tel], :root[data-theme="dark"] input[type=number],
:root[data-theme="dark"] input[type=password], :root[data-theme="dark"] textarea, :root[data-theme="dark"] select {
  background: #232e42; border-color: #313d54; color: #e7ecf3;
}
:root[data-theme="dark"] input::placeholder, :root[data-theme="dark"] textarea::placeholder { color: #6b7688; }
:root[data-theme="dark"] input:focus, :root[data-theme="dark"] textarea:focus, :root[data-theme="dark"] select:focus {
  background: #26324a; border-color: #6fa8dc; box-shadow: 0 0 0 3px rgba(74,134,200,0.22);
}

:root[data-theme="dark"] .btn-ghost { background: #2a3548; color: #d3dae6; }
:root[data-theme="dark"] .btn-ghost:hover { background: #333f56; }
:root[data-theme="dark"] .btn-danger { background: #3a2226; color: #f0a9a9; }
:root[data-theme="dark"] .btn-danger:hover { background: #4a2a2f; }

:root[data-theme="dark"] th { color: #8892a0; }
:root[data-theme="dark"] th, :root[data-theme="dark"] td { border-bottom-color: #2b3648; }
:root[data-theme="dark"] .item-row, :root[data-theme="dark"] .ps-row { border-bottom-color: #2b3648; }
:root[data-theme="dark"] .item-thumb { background: #2a3548; }

:root[data-theme="dark"] .success-msg { background: #16311f; color: #7fd39b; border-color: #23492f; }
:root[data-theme="dark"] .error-msg { background: #3a2226; color: #f0a9a9; border-color: #572e33; }
:root[data-theme="dark"] .badge-read { background: #2a3548; color: #9aa4b4; }
:root[data-theme="dark"] .msg-unread { background: #17243a; }
:root[data-theme="dark"] .upload-drop { border-color: #3a465c; color: #9aa4b4; }

/* Remappage des couleurs inline récurrentes (gère avec et sans espace après ':') */
:root[data-theme="dark"] [style*="background:#fff"], :root[data-theme="dark"] [style*="background: #fff"],
:root[data-theme="dark"] [style*="background:#ffffff"] { background: #1a2334 !important; }
:root[data-theme="dark"] [style*="background:#f8f9fb"], :root[data-theme="dark"] [style*="background: #f8f9fb"],
:root[data-theme="dark"] [style*="background:#f4f6f9"], :root[data-theme="dark"] [style*="background:#fbfbfd"],
:root[data-theme="dark"] [style*="background:#f7fafd"] { background: #212c40 !important; }
:root[data-theme="dark"] [style*="background:#eef1f5"], :root[data-theme="dark"] [style*="background: #eef1f5"],
:root[data-theme="dark"] [style*="background:#eef0f3"], :root[data-theme="dark"] [style*="background:#f0f5fb"] { background: #2a3548 !important; }
:root[data-theme="dark"] [style*="color:#1c2333"], :root[data-theme="dark"] [style*="color: #1c2333"],
:root[data-theme="dark"] [style*="color:#1a2333"] { color: #e7ecf3 !important; }
:root[data-theme="dark"] [style*="color:#3a4152"], :root[data-theme="dark"] [style*="color: #3a4152"] { color: #c7cfdb !important; }
:root[data-theme="dark"] [style*="color:#6b7382"], :root[data-theme="dark"] [style*="color: #6b7382"],
:root[data-theme="dark"] [style*="color:#8a92a3"], :root[data-theme="dark"] [style*="color:#9aa2b2"] { color: #9aa4b4 !important; }
:root[data-theme="dark"] [style*="border:1px solid #e8ecf2"], :root[data-theme="dark"] [style*="border:1px solid #edf0f4"],
:root[data-theme="dark"] [style*="border:1px solid #d6e4f5"] { border-color: #2b3648 !important; }

/* Bouton de bascule de thème dans la barre latérale */
.theme-toggle-btn {
  width: 100%; padding: 9px 12px; margin-bottom: 12px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; color: #dfe6f0; font-size: 13px; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.1); }
