:root {
  --charcoal: #1B1D21;
  --panel: #232630;
  --panel-2: #2A2E39;
  --brass: #C6A15B;
  --brass-bright: #E4C482;
  --cream: #F4EFE4;
  --ink: #EDEAE1;
  --muted: #9A9CA6;
  --line: #383C48;
  --ok: #7FA688;
  --err: #C97B6B;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--charcoal);
  background-image: radial-gradient(ellipse 900px 500px at 15% -10%, rgba(198,161,91,0.12), transparent 60%);
  background-attachment: fixed;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  font-size: 15px;
}

.display { font-family: 'Fraunces', serif; }
.mono { font-family: 'IBM Plex Mono', monospace; }

a { color: var(--brass); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ---- Boutons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  background: var(--brass);
  color: var(--charcoal);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--brass-bright); }
.btn.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn.secondary:hover { color: var(--ink); border-color: var(--muted); background: transparent; }
.btn.danger {
  background: transparent;
  color: var(--err);
  border: 1px solid rgba(201,123,107,0.4);
}
.btn.danger:hover { background: rgba(201,123,107,0.12); border-color: var(--err); color: var(--err); }
.btn.small { padding: 7px 13px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Champs ---- */
input[type="text"], input[type="url"], input[type="password"], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: var(--panel-2);
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brass);
}
select option { background: var(--panel); color: var(--ink); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 11px; font-weight: 500; margin-bottom: 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

::placeholder { color: #6a6d78; opacity: 1; }

/* ---- Cartes / panneaux ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}

/* ---- Étiquettes ---- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge.statique { background: rgba(198,161,91,0.14); color: var(--brass-bright); border: 1px solid rgba(198,161,91,0.4); }
.badge.dynamique { background: rgba(127,166,136,0.14); color: var(--ok); border: 1px solid rgba(127,166,136,0.4); }
.badge.inactive { background: rgba(201,123,107,0.14); color: var(--err); border: 1px solid rgba(201,123,107,0.4); }

/* ---- Toast ---- */
#toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--brass);
  color: var(--charcoal);
  padding: 12px 18px;
  border-radius: 9px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  font-weight: 600;
  font-size: 13px;
  max-width: 340px;
  animation: slideIn 0.2s ease;
}
.toast.error { background: var(--err); color: #fff; }
.toast.success { background: var(--ok); color: var(--charcoal); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(13,14,17,0.72);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  color: var(--ink);
}
.modal h2 { margin-top: 0; font-size: 22px; font-family: 'Fraunces', serif; font-weight: 600; color: var(--cream); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---- Barres de stats ---- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.bars .bar { background: var(--brass); border-radius: 3px 3px 0 0; min-width: 6px; flex: 1; opacity: 0.85; }

.simple-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.simple-table th, .simple-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.simple-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }

.stat-counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 16px; }
.stat-box { text-align: center; }
.stat-box .value { font-size: 25px; font-weight: 600; color: var(--cream); font-family: 'Fraunces', serif; }
.stat-box .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state h3 { color: var(--cream); margin-bottom: 6px; font-family: 'Fraunces', serif; font-weight: 600; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  color: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
}
.chip b { font-weight: 600; color: var(--brass); }

/* ---- Cadre supérieur ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto;
  max-width: 1080px;
  padding: 34px 20px 22px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 6px;
}
.topbar h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 28px;
  margin: 0;
  color: var(--cream);
  line-height: 1.1;
}
.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Galerie ---- */
main.app-main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.toolbar-title { font-weight: 700; font-size: 15px; color: var(--cream); }
.toolbar-sub { color: var(--muted); font-size: 12.5px; font-family: 'IBM Plex Mono', monospace; }
.toolbar input { width: 260px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

/* ---- Plaque / carte QR ---- */
.plaque {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.plaque:hover { border-color: var(--brass); transform: translateY(-2px); }
.plaque::before, .plaque::after {
  content: '';
  position: absolute;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--line);
  top: 10px;
}
.plaque::before { left: 10px; }
.plaque::after { right: 10px; }

.plaque-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.qr-chip {
  background: var(--cream);
  border-radius: 10px;
  padding: 10px;
  display: inline-flex;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.qr-chip img { width: 64px; height: 64px; display: block; }
#qr-preview .qr-chip img { width: 150px; height: 150px; }
.plaque-name {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--cream);
  margin-top: 12px;
}
.plaque-link { font-size: 12px; color: var(--muted); word-break: break-all; margin-top: 4px; font-family: 'IBM Plex Mono', monospace; }
.plaque-serial {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--brass);
  letter-spacing: 0.08em;
  margin-top: 6px;
}
.serial-chip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--brass);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  letter-spacing: 0.05em;
}
.plaque-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
}
.plaque-foot b { color: var(--brass); font-weight: 600; }

/* ---- Détails ---- */
.detail-thumb { text-align: center; }
.detail-thumb .qr-chip { padding: 14px; }
.detail-thumb .qr-chip img { width: 170px; height: 170px; }
.detail-thumb .dl-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.detail-meta { flex: 1; min-width: 260px; }
.detail-meta .meta-line { font-size: 13.5px; margin: 4px 0 8px; color: var(--ink); }
.detail-meta .meta-line b { color: var(--muted); font-weight: 500; }

.detail-stats-title { margin: 22px 0 10px; font-size: 16px; color: var(--cream); font-family: 'Fraunces', serif; font-weight: 600; }

.section-title { font-weight: 600; padding: 14px 16px 4px; color: var(--cream); font-size: 13.5px; }

/* ---- Apparence du QR ---- */
#qr-preview .qr-chip canvas,
#qr-preview .qr-chip svg,
.detail-thumb .qr-chip canvas,
.detail-thumb .qr-chip svg,
.qr-chip .qr-render canvas,
.qr-chip .qr-render svg { display: block; border-radius: 6px; }

.style-section {
  margin: 4px 0 2px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.style-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--cream);
  margin-bottom: 12px;
}
.row-style { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-style .field:first-child:nth-last-child(1) { grid-column: 1 / -1; }
.hint-style { font-size: 12px; color: var(--muted); margin: 4px 0 0; line-height: 1.5; }

input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--brass); }