/* =============================================================================
   QRFlash — feuille de style
   ========================================================================== */

:root {
  --bg:        #f6f7fb;
  --surface:   #ffffff;
  --surface-2: #f2f4f9;
  --border:    #e3e7f0;
  --text:      #171a21;
  --muted:     #6b7385;
  --accent:    #2b6cff;
  --accent-2:  #8b5cf6;
  --accent-soft:#eaf0ff;
  --ok:        #16a34a;
  --warn:      #d97706;
  --danger:    #dc2626;
  --radius:    12px;
  --radius-lg: 16px;
  --shadow:    0 1px 2px rgba(16,22,40,.05), 0 8px 24px rgba(16,22,40,.06);
  --shadow-sm: 0 1px 2px rgba(16,22,40,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --surface:   #161a21;
    --surface-2: #1c212a;
    --border:    #272d38;
    --text:      #e7eaf1;
    --muted:     #97a0b2;
    --accent-soft:#182444;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

/* L'attribut hidden doit toujours l'emporter sur les display:flex / grid ci-dessous. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
p  { margin: 0 0 10px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em;
       background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

.muted { color: var(--muted); }
.hint  { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

/* ---------- Marque ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 1px var(--accent);
}

/* ---------- Pages de connexion / installation ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 30px 28px; box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 18px; }
.auth-card form { margin-top: 18px; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-right { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; cursor: pointer; font: inherit; color: var(--muted);
  padding: 8px 12px; border-radius: 8px; font-weight: 550; white-space: nowrap; flex: none;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }

.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 4px 0 14px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; }
.row-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Formulaires ---------- */
label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 550; color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 450; color: var(--muted); }
label.check input { width: auto; margin: 0; }

input[type=text], input[type=email], input[type=url], input[type=password],
input[type=number], input[type=search], select, textarea {
  width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 84px; resize: vertical; }
.input-sm { width: 200px; margin: 0; padding: 7px 10px; font-size: 13px; }

input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
input[type=color] {
  -webkit-appearance: none; appearance: none; width: 40px; height: 32px;
  padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 5px; }
output { float: right; font-weight: 500; color: var(--muted); font-size: 12.5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 8px;
                font-size: 12.5px; color: var(--muted); margin: 0; }
.inline-field select { width: auto; margin: 0; padding: 5px 8px; font-size: 12.5px; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1e5ae6; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit;
           text-decoration: underline; padding: 0 2px; }

/* ---------- Alertes ---------- */
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }
.alert-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-ok  { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }
.alert-ok ol { margin: 8px 0 0 18px; padding: 0; }
@media (prefers-color-scheme: dark) {
  .alert-err { background: #2a1618; color: #fca5a5; border-color: #4c2226; }
  .alert-ok  { background: #10231a; color: #86efac; border-color: #1e4231; }
}

/* ---------- Statistiques (bandeau) ---------- */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.stat-label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { display: block; font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.stat-sm { font-size: 14px; font-weight: 550; margin-top: 8px; }
.stat-wide { grid-column: span 1; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 42px; margin-top: 8px; }
.spark i {
  flex: 1; background: var(--accent); opacity: .28; border-radius: 2px 2px 0 0; min-height: 2px;
  transition: opacity .12s;
}
.spark i.hot { opacity: .85; }

/* ---------- Cartes QR ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; gap: 14px; box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: #c9d3ea; box-shadow: var(--shadow); }
.card-qr {
  width: 92px; height: 92px; flex: none; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
}
.card-qr canvas, .card-qr svg { width: 100% !important; height: 100% !important; display: block; }
.card-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.card-title { font-weight: 600; font-size: 14.5px; margin: 0 0 3px; overflow: hidden;
              text-overflow: ellipsis; white-space: nowrap; }
.card-url { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis;
            white-space: nowrap; margin: 0 0 6px; }
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.card-actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.badge-muted { background: var(--surface-2); color: var(--muted); }
.badge-off   { background: #fff7ed; color: var(--warn); }
.badge-scans { background: #ecfdf5; color: var(--ok); }
@media (prefers-color-scheme: dark) {
  .badge-off { background: #2a2013; color: #fbbf24; }
  .badge-scans { background: #10231a; color: #4ade80; }
}

.empty {
  text-align: center; padding: 56px 20px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius-lg); background: var(--surface);
}

/* ---------- Éditeur ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 20px; align-items: start; }
.editor-panel { display: grid; grid-template-columns: 1fr; gap: 14px; min-width: 0; align-items: start; }

/* Sur grand écran, les réglages se répartissent sur deux colonnes. */
@media (min-width: 1180px) {
  .editor-panel { grid-template-columns: 1fr 1fr; }
  .editor-panel > .panel:first-child { grid-column: 1 / -1; }
  .editor-panel > .panel:nth-child(3) { grid-row: span 2; }
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.panel > h3 { margin-bottom: 14px; }

.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.type-opt {
  text-align: left; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; font: inherit; color: var(--text);
  display: flex; flex-direction: column; gap: 2px; transition: border-color .12s, background .12s;
}
.type-opt span { font-size: 12px; color: var(--muted); font-weight: 400; }
.type-opt:hover { border-color: #c9d3ea; }
.type-opt.is-active { border-color: var(--accent); background: var(--accent-soft); }
.type-opt.is-active span { color: var(--accent); }
.type-opt:disabled { opacity: .45; cursor: not-allowed; }

.color-block { padding: 12px 0; border-bottom: 1px solid var(--border); }
.color-block:last-of-type { border-bottom: 0; }
.color-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px;
              font-size: 13px; font-weight: 550; }
.seg { display: flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg-btn { border: 0; background: none; font: inherit; font-size: 12px; padding: 4px 10px;
           border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg-btn.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.color-grad { display: flex; gap: 8px; align-items: center; }
.color-grad select { width: auto; margin: 0; padding: 6px 8px; font-size: 12.5px; }
.color-grad input[type=range] { margin: 0; flex: 1; }

.presets { margin-top: 14px; }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.preset {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border);
  cursor: pointer; padding: 0; transition: transform .1s;
}
.preset:hover { transform: scale(1.08); }

.logo-row { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 14px; }
.logo-preview {
  width: 68px; height: 68px; flex: none; border-radius: 10px; border: 1px dashed var(--border);
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); overflow: hidden;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; }
.logo-actions .hint { width: 100%; margin: 0; }

/* ---------- Aperçu ---------- */
.editor-preview { min-width: 0; }
.preview-sticky { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.preview-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); min-height: 300px;
}
/* Damier affiché uniquement lorsque le fond du QR est transparent. */
.preview-box.is-transparent {
  background-image:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.preview-box canvas, .preview-box svg { max-width: 100%; height: auto !important; border-radius: 6px; }
.preview-meta { display: flex; gap: 6px; }

.quality { display: flex; flex-direction: column; gap: 6px; }
.q-item { font-size: 12.5px; line-height: 1.45; padding: 9px 11px; border-radius: 9px; border: 1px solid; }
.q-warn { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.q-err  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
@media (prefers-color-scheme: dark) {
  .q-warn { background: #2a2013; color: #fbbf24; border-color: #4a3a17; }
  .q-err  { background: #2a1618; color: #fca5a5; border-color: #4c2226; }
}
.preview-actions { display: flex; flex-direction: column; gap: 9px; }

/* ---------- Graphiques ---------- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
              height: 100%; position: relative; }
.chart .col i {
  display: block; background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9;
}
.chart .col:hover i { opacity: 1; }
.chart .col::after {
  content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: 11px; padding: 3px 7px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; margin-bottom: 4px;
}
.chart .col:hover::after { opacity: 1; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 42px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { display: block; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 4px;
            background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.bar-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Tableaux ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table td:last-child { text-align: right; }
.table td[colspan] { text-align: left; }
/* Table des derniers scans : colonnes serrées à gauche plutôt qu'étalées. */
#st-recent td { text-align: left; width: auto; }
#st-recent td:first-child { white-space: nowrap; width: 160px; color: var(--muted); }
#st-recent td:nth-child(2) { width: 130px; }

/* ---------- Modale ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(10,14,24,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: 100%; max-width: 440px; box-shadow: 0 24px 64px rgba(0,0,0,.3);
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between;
              padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); }
.modal-x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer;
           color: var(--muted); padding: 0 4px; }
.modal-body { padding: 20px; overflow: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 550; z-index: 200; box-shadow: 0 12px 32px rgba(0,0,0,.25);
  animation: rise .2s ease;
}
.toast.is-err { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; }
  .preview-sticky { position: static; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .brand strong { display: none; }
  .topbar-right .btn { max-width: 96px; overflow: hidden; text-overflow: ellipsis; display: block; }
  .tab { padding: 7px 8px; font-size: 12.5px; }
  .wrap { padding: 16px 12px 48px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .input-sm { width: 130px; }
  .cards { grid-template-columns: 1fr; }
}
