/* ===== Thème Skeyetek — tons gris, mode sombre / mode clair =====
   Le mode est posé sur <html data-theme="dark|light"> par theme.js
   (choix mémorisé, sinon préférence système). */
:root, html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1b1e;            /* fond page : gris anthracite, pas noir */
  --card: #232327;          /* cartes */
  --card-2: #2a2a2f;        /* surfaces secondaires (toolbar, inputs) */
  --hover: #303036;
  --border: #38383f;
  --border-strong: #4c4c55;
  --text: #f3f3f4;
  --text-2: #d5d5da;
  --muted: #a3a3ac;
  --muted-2: #7d7d87;
  --primary: #f3f3f4;       /* boutons principaux : clair sur sombre */
  --primary-fg: #1b1b1e;
  --accent: #7ab4ff;
  --success: #5ad07f; --success-bg: rgba(90,208,127,.14);
  --warning: #f5c04a; --warning-bg: rgba(245,192,74,.14);
  --error: #f88b8b;   --error-bg: rgba(248,139,139,.14);
  --focus: rgba(243,243,244,.08);
  --header-bg: rgba(27,27,30,.82);
  --overlay: rgba(0,0,0,.6);
  --cart-bg: rgba(35,35,39,.94);
  --scroll: rgba(243,243,244,.14);
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --logo-filter: none;
  --r: 10px; --r-sm: 6px; --r-lg: 14px;
  --green: var(--success); --red: var(--error); --orange: var(--warning);
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f1f3;
  --card: #ffffff;
  --card-2: #f5f5f7;
  --hover: #ebebef;
  --border: #dedee3;
  --border-strong: #c3c3cb;
  --text: #1c1c21;
  --text-2: #3c3c45;
  --muted: #6c6c77;
  --muted-2: #8f8f9a;
  --primary: #1c1c21;
  --primary-fg: #ffffff;
  --accent: #2563eb;
  --success: #15803d; --success-bg: rgba(21,128,61,.10);
  --warning: #b45309; --warning-bg: rgba(180,83,9,.10);
  --error: #dc2626;   --error-bg: rgba(220,38,38,.10);
  --focus: rgba(28,28,33,.08);
  --header-bg: rgba(241,241,243,.85);
  --overlay: rgba(20,20,24,.45);
  --cart-bg: rgba(255,255,255,.95);
  --scroll: rgba(28,28,33,.18);
  --shadow: 0 6px 24px rgba(20,20,24,.10);
  --logo-filter: invert(1) brightness(.15);
}
.logo, .logo-lg { filter: var(--logo-filter); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }
.theme-toggle { background: transparent; border: 1px solid var(--border); color: var(--text-2); width: 36px; height: 36px; padding: 0 !important;
  border-radius: 999px !important; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1; }
.theme-toggle:hover { background: var(--hover); color: var(--text); border-color: var(--border-strong); }
.card, .admin-card, .toolbar, .brand-section, .login-card, .modal { box-shadow: var(--shadow); }

/* ===== Responsive : tablette et téléphone =====================================
   Les tableaux deviennent des fiches empilées sous 760 px (chaque ligne = une
   carte, chaque cellule « Intitulé : valeur » grâce à data-label posé par
   theme.js) ; entre 760 et 1000 px ils défilent horizontalement dans leur
   cadre, pour que la page elle-même ne défile jamais de côté. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* ===== Grand écran : la page occupe la largeur disponible pour que les tableaux
   larges (tarification, reliquats, commandes fournisseur…) tiennent sur une ligne
   sans défilement horizontal. Les cellules se replient plutôt que de déborder. */
@media (min-width: 1201px) {
  main { max-width: min(96vw, 2200px) !important; }
  html[data-embed] main { max-width: none !important; }
}
table { table-layout: auto; max-width: 100%; }
td { overflow-wrap: anywhere; }
th { overflow-wrap: normal; }
td.num, th.num { white-space: nowrap; }
.card, .admin-card, .brand-section { min-width: 0; }

@media (max-width: 1000px) {
  main { padding-left: 16px !important; padding-right: 16px !important; }
  header { padding-left: 16px !important; padding-right: 16px !important; gap: 10px !important; flex-wrap: wrap; }
  .total-box { max-width: none !important; }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  main { padding-top: 18px !important; padding-bottom: 96px !important; }
  header { padding-top: 10px !important; padding-bottom: 10px !important; }
  header .subtitle { display: none; }
  header .badge, header .pill { font-size: 11px; }
  header a, header button { padding: 7px 11px !important; font-size: 12.5px !important; }

  /* Cartes et cadres : jamais plus larges que l'écran */
  .card, .admin-card, .toolbar, .brand-section, .modal, .confirm { padding: 16px 14px !important; border-radius: 12px; }
  .card, .admin-card, .toolbar, .brand-section { margin-bottom: 14px; }
  .split { grid-template-columns: 1fr !important; }

  /* Formulaires : une ligne par champ, champs pleine largeur */
  .toolbar, .form-row, .row { flex-direction: column !important; align-items: stretch !important; gap: 10px !important; }
  .field, .grow, .toolbar .grow { min-width: 0 !important; width: 100%; }
  .field input, .field select, .field textarea, .toolbar input, .toolbar select, .form-row input, .form-row select, textarea { width: 100% !important; max-width: 100% !important; }
  .export-row, .form-row > .btn, .row > .btn { width: 100%; }
  .export-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .export-row .btn { width: 100%; }
  .std-check { align-self: flex-start; padding-bottom: 0 !important; }

  /* Onglets : défilent horizontalement plutôt que de casser la mise en page */
  .tabs-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .tabs { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    width: auto !important; max-width: 100%; min-width: 0; justify-content: flex-start; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; }

  /* Tableaux → fiches empilées */
  table.rwd, table.rwd tbody, table.rwd tr, table.rwd td { display: block; width: 100%; }
  table.rwd thead { display: none; }
  table.rwd tr { border: 1px solid var(--border); border-radius: 10px; background: var(--card-2);
    padding: 10px 12px; margin-bottom: 10px; }
  table.rwd tr:last-child { margin-bottom: 0; }
  table.rwd td { border: none !important; padding: 3px 0 !important; display: flex; gap: 12px;
    align-items: baseline; justify-content: space-between; text-align: right !important; white-space: normal !important;
    overflow-wrap: anywhere; min-width: 0; flex-wrap: wrap; }
  table.rwd .chip { border-radius: 8px; white-space: normal; }
  table.rwd td > * { min-width: 0; }
  table.rwd tbody tr:hover td { background: transparent; }
  table.rwd td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 500;
    text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: 0 0 auto; max-width: 45%; }
  table.rwd td[data-label=""]::before, table.rwd td.rwd-title::before { content: none; }
  table.rwd td.rwd-title { display: block; text-align: left !important; font-weight: 600; padding-bottom: 6px !important;
    margin-bottom: 4px; border-bottom: 1px solid var(--border) !important; }
  table.rwd td.rwd-title .ref, table.rwd td.rwd-title .desc, table.rwd td.rwd-title .hint { font-weight: 400; }
  table.rwd td.rwd-empty { display: none; }
  table.rwd td.rwd-title { order: -1; }
  table.rwd td[data-label="Sélection"] { justify-content: flex-start; gap: 8px; padding-bottom: 6px !important; }
  table.rwd td[data-label="Sélection"]::before { order: 1; }
  table.rwd td.rwd-actions { justify-content: flex-end; gap: 8px; padding-top: 8px !important; }
  table.rwd td .ref, table.rwd td .desc { text-align: right; }
  table.rwd td.rwd-title .ref, table.rwd td.rwd-title .desc { text-align: left; max-width: none; }
  table.rwd .qty-input, table.rwd .inline-input, table.rwd .label-input, table.rwd input, table.rwd select { width: auto !important; max-width: 55% !important; }
  table.rwd td.has-err { padding-bottom: 34px !important; }

  /* Divers */
  .desc { max-width: none !important; }
  .cart-bar { width: calc(100vw - 16px) !important; left: 8px !important; transform: none !important; flex-wrap: wrap; gap: 8px; padding: 12px 14px !important; }
  .modal { width: calc(100vw - 24px) !important; max-height: 88vh; }
  .login-card { width: calc(100vw - 32px) !important; max-width: 380px; padding: 28px 22px !important; }
  .check-grid { grid-template-columns: 1fr 1fr !important; }
  .promo-banner { flex-wrap: wrap; gap: 6px !important; padding: 12px 14px !important; }
  .total-box { grid-template-columns: 1fr auto; }
  #linesTable td:first-child { min-width: 0 !important; }
  iframe#prepFrame { min-height: 60vh; }
}
