:root {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-light: #fff7ed;
  --primary-soft: #fed7aa;
  --accent: #f97316;
  --bg: #f8f7f4;
  --bg-muted: #f1efe9;
  --surface: #ffffff;
  --surface-alt: #fdfcfa;
  --text: #1c1917;
  --text-strong: #0c0a09;
  --muted: #78716c;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --ring: 0 0 0 3px rgba(234, 88, 12, 0.18);
  --shadow-xs: 0 1px 1px rgba(28, 25, 23, 0.04);
  --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 8px -2px rgba(28, 25, 23, 0.08), 0 2px 4px -2px rgba(28, 25, 23, 0.05);
  --shadow-lg: 0 10px 20px -4px rgba(28, 25, 23, 0.10), 0 4px 8px -4px rgba(28, 25, 23, 0.06);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  background-color: #ff8c42;
  background-image:
    url("/static/images/pv-side-left.svg"),
    url("/static/images/pv-side-right.svg"),
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.55) 2px, transparent 3px),
    radial-gradient(circle at 28% 72%, rgba(255,255,255,0.45) 3px, transparent 4px),
    radial-gradient(circle at 42% 12%, rgba(255,255,255,0.5)  1.5px, transparent 2.5px),
    radial-gradient(circle at 55% 38%, rgba(255,255,255,0.4)  2.5px, transparent 3.5px),
    radial-gradient(circle at 38% 88%, rgba(255,255,255,0.55) 2px, transparent 3px),
    radial-gradient(circle at 65% 62%, rgba(255,255,255,0.35) 4px, transparent 5px),
    radial-gradient(circle at 18% 48%, rgba(255,255,255,0.5)  1.5px, transparent 2.5px),
    radial-gradient(circle at 48% 58%, rgba(255,236,210,0.6)  3px, transparent 4px),
    radial-gradient(circle at 22% 32%, rgba(255,236,210,0.5)  2px, transparent 3px),
    radial-gradient(circle at 58% 82%, rgba(255,255,255,0.4)  2.5px, transparent 3.5px),
    radial-gradient(circle at 33% 25%, rgba(255,255,255,0.45) 1.8px, transparent 2.8px),
    radial-gradient(circle at 8%  78%, rgba(255,255,255,0.4)  3px, transparent 4px),
    radial-gradient(circle at 50% 92%, rgba(255,236,210,0.5)  2px, transparent 3px),
    radial-gradient(at 15% 20%, #ffb088 0, transparent 55%),
    radial-gradient(at 85% 10%, #ff8c42 0, transparent 50%),
    radial-gradient(at 90% 80%, #ffd6a5 0, transparent 55%),
    radial-gradient(at 20% 90%, #ff6b35 0, transparent 45%),
    linear-gradient(135deg, #ff6b35 0%, #ff8c42 50%, #ffa94d 100%);
  background-position:
    left 32px bottom 60px,
    right 140px center,
    0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0,
    0 0, 0 0, 0 0, 0 0,
    0 0;
  background-size:
    420px auto,
    420px auto,
    auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto,
    auto, auto, auto, auto,
    auto;
  background-repeat:
    no-repeat,
    no-repeat,
    no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat,
    no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, no-repeat,
    no-repeat, no-repeat, no-repeat, no-repeat,
    no-repeat;
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--primary-soft); color: var(--text-strong); }

.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  color: var(--text);
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  color: var(--text-strong);
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
  margin-right: auto;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.topbar .brand::before {
  content: "";
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.35);
}
.topbar .brand.has-logo::before { display: none; }
.topbar .brand-logo {
  max-height: 90px;
  max-width: 300px;
  object-fit: contain;
  display: block;
  margin: -22px 0;
}
.topbar { overflow: visible; }
.login-logo {
  display: block;
  margin: 0 auto 0.8rem;
  max-height: 160px;
  max-width: 100%;
  object-fit: contain;
}
body::after {
  content: "";
  position: fixed;
  left: 140px;
  top: 160px;
  width: 280px;
  height: 280px;
  background-image: url("/static/images/pv-tampon.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transform: rotate(-14deg);
  opacity: 0.85;
  filter: drop-shadow(0 4px 14px rgba(124, 45, 18, 0.18));
  pointer-events: none;
  z-index: 0;
}
.topbar, .container, .login-card { position: relative; z-index: 1; }

/* Décor (SVG fond + tampon) : visible seulement au-dessus de 1500px,
   sinon ils se superposent au contenu (centré dans 1100px max). */
@media (max-width: 1500px) {
  body {
    background-image:
      radial-gradient(at 15% 20%, #ffb088 0, transparent 55%),
      radial-gradient(at 85% 10%, #ff8c42 0, transparent 50%),
      radial-gradient(at 90% 80%, #ffd6a5 0, transparent 55%),
      radial-gradient(at 20% 90%, #ff6b35 0, transparent 45%),
      linear-gradient(135deg, #ff6b35 0%, #ff8c42 50%, #ffa94d 100%) !important;
    background-position: 0 0, 0 0, 0 0, 0 0, 0 0 !important;
    background-size: auto, auto, auto, auto, auto !important;
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat !important;
  }
  body::after { display: none; }
}
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
}
.site-footer {
  max-width: 1100px;
  margin: 3rem auto 1.5rem;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted, #78716c);
  border-top: 1px solid rgba(0,0,0,0.06);
}
.site-footer a { color: var(--muted, #78716c); }
.site-footer a:hover { color: var(--primary, #ea580c); }
.cookie-notice {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1917;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.85rem;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  z-index: 9999;
  max-width: 600px;
}
.cookie-notice[hidden] { display: none !important; }
.cookie-notice a { color: #fdba74; }
.cookie-notice button { background: #fff; color: #1c1917; border: 0; padding: 0.35rem 0.7rem; border-radius: 4px; font-size: 0.82rem; cursor: pointer; flex-shrink: 0; }
.empty-illu {
  display: block;
  margin: 0 auto 1.5rem;
  width: 100%;
  max-width: 220px;
  height: auto;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.08));
}
@media (max-width: 640px) {
  .empty-illu { max-width: 160px; }
}
.topbar .brand-suffix {
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}
.topbar-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-height: 38px;
  max-width: 140px;
  object-fit: contain;
  pointer-events: none;
}
.topbar nav { display: flex; gap: 0.15rem; align-items: center; }
.topbar nav a {
  color: var(--primary);
  text-decoration: none;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.topbar nav a:hover { background: var(--bg-muted); color: var(--primary-dark); }
.topbar nav a.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  padding: 0.45rem 0.9rem;
  margin-left: 0.5rem;
}
.topbar nav a.btn-primary:hover {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}
.topbar .logout { color: var(--muted); font-size: 0.88rem; margin-left: 0.3rem; }
.topbar .logout:hover { color: var(--danger); background: transparent; }

.container { max-width: 1100px; margin: 2rem auto; padding: 0 1.5rem; }

h1 {
  margin: 0 0 1.2rem;
  color: var(--primary-dark);
  font-weight: 700;
  letter-spacing: -0.025em;
  font-size: 1.5rem;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid var(--primary-soft);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 0.8rem 1.2rem;
  box-shadow: var(--shadow-xs);
}
/* H1 qui sont déjà dans un container stylé (ex: editor-header) : pas de double traitement */
.editor-header h1, .login-card h1 { background: transparent; border: none; padding: 0; box-shadow: none; margin: 0; }
h2 { color: var(--text-strong); font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 0.45rem; letter-spacing: -0.015em; font-size: 1.2rem; margin-top: 1.8rem; }
h3 { color: var(--text-strong); font-weight: 600; letter-spacing: -0.01em; font-size: 1rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.search-bar { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
.search-bar input[type="search"] {
  flex: 1;
  min-width: 250px;
  padding: 0.6rem 0.8rem 0.6rem 2.3rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") 0.75rem center no-repeat;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-bar input[type="search"]:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }

button, .btn-primary, .btn-secondary, .btn-danger {
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  line-height: 1.3;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
  user-select: none;
}
button:active, .btn-primary:active, .btn-secondary:active, .btn-danger:active { transform: translateY(1px); }
button:focus-visible, .btn-primary:focus-visible, .btn-secondary:focus-visible, .btn-danger:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-primary, button[type="submit"] {
  background: linear-gradient(180deg, var(--accent) 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  border-color: rgba(234, 88, 12, 0.4);
  text-decoration: none;
}
.btn-primary:hover, button[type="submit"]:hover {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  text-decoration: none;
}
.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary-soft);
  box-shadow: var(--shadow-xs);
  font-weight: 500;
}
.btn-secondary:hover {
  background: #ffedd5;
  border-color: var(--primary);
  color: var(--primary-dark);
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.15);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-danger:hover { background: #b91c1c; color: #fff; text-decoration: none; }
.link-danger { background: transparent; color: var(--danger); padding: 0; border: none; cursor: pointer; font: inherit; }
.link-danger:hover { text-decoration: underline; }

table.list {
  width: 100%;
  background: var(--surface);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
table.list th, table.list td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
table.list th {
  background: linear-gradient(180deg, var(--bg-muted) 0%, var(--bg) 100%);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.05em;
}
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { transition: background 0.1s; }
table.list tbody tr:hover td { background: var(--primary-light); }
table.list .actions a { margin-right: 0.9rem; color: var(--primary); text-decoration: none; font-weight: 500; }
table.list .actions a:hover { text-decoration: underline; }

.empty {
  background: var(--surface);
  padding: 3rem 2rem;
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
}
.empty a { font-weight: 500; }

.form {
  background: var(--surface);
  padding: 1.8rem;
  border-radius: var(--radius);
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 500; color: var(--text-strong); font-size: 0.88rem; }
.form input, .form select, .form textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: normal;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 0.95rem;
}
.form input:hover, .form select:hover, .form textarea:hover { border-color: var(--border-strong); }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.form input[type="file"] { padding: 0.4rem; background: var(--bg-muted); border-style: dashed; cursor: pointer; }
.form input[type="file"]:hover { background: var(--primary-light); border-color: var(--primary); }
.form input[type="color"] { padding: 2px; height: 40px; cursor: pointer; }
.form .actions { display: flex; gap: 0.5rem; margin-top: 0.3rem; }

.alert { background: #fef2f2; border: 1px solid #fecaca; border-left: 3px solid var(--danger); padding: 0.75rem 1rem; color: var(--danger); border-radius: var(--radius-sm); font-size: 0.92rem; }
.hint { color: var(--muted); font-size: 0.88rem; }

.top-actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; align-items: center; flex-wrap: wrap; }

dl.details {
  background: var(--surface);
  padding: 1.8rem 2rem;
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.85rem 1.4rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
dl.details dt { font-weight: 500; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
dl.details dd { margin: 0; color: var(--text-strong); font-size: 0.95rem; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.9rem; }
.photo-grid img { width: 100%; height: 200px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.signature { max-width: 300px; background: var(--surface); padding: 0.6rem; border: 1px solid var(--border); border-radius: 8px; }

.search-bar input[type="search"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.18); }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  padding: 2.8rem 2.5rem;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 30px 80px rgba(28, 25, 23, 0.28), 0 10px 30px rgba(28, 25, 23, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.5);
}
.login-card h1 {
  margin: 0 0 0.3rem;
  text-align: center;
  color: var(--text-strong);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}
.login-card h1::before {
  content: "";
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.4);
}
.login-card .subtitle { text-align: center; color: var(--muted); margin-top: 0; margin-bottom: 1.8rem; font-size: 0.92rem; }
.login-card form { display: flex; flex-direction: column; gap: 1rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 500; color: var(--text-strong); font-size: 0.88rem; }
.login-card input {
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.login-card button { padding: 0.8rem; font-weight: 600; margin-top: 0.5rem; font-size: 0.98rem; }

/* Form row (2 colonnes) */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* Signature pad */
.signature-wrap { background: #fff; border: 2px dashed var(--border); border-radius: 8px; padding: 4px; max-width: 480px; margin-top: 0.3rem; }
.signature-wrap canvas { width: 100%; height: 200px; display: block; border-radius: 6px; touch-action: none; cursor: crosshair; }

/* Photos preview */
.photos-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; margin-top: 0.5rem; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .rm { position: absolute; top: 4px; right: 4px; background: rgba(220,38,38,0.95); color: #fff; border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 1rem; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.photo-thumb .rm:hover { background: #b91c1c; }
.photo-thumb .keep-box { position: absolute; bottom: 4px; left: 4px; right: 4px; background: rgba(255,255,255,0.92); border-radius: 4px; padding: 3px 6px; font-size: 0.75rem; display: flex; align-items: center; gap: 4px; color: var(--text); flex-direction: row; font-weight: 500; margin: 0; }
.photo-thumb .keep-box input { margin: 0; }

/* Lightbox */
#lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 9999; align-items: center; justify-content: center; cursor: zoom-out; }
#lightbox.open { display: flex; }
#lightbox img { max-width: 95%; max-height: 95vh; object-fit: contain; border-radius: 8px; }
#lightbox .close { position: absolute; top: 20px; right: 30px; color: #fff; font-size: 2.5rem; cursor: pointer; }

/* PV settings sections */
.form h2 { margin: 1.2rem 0 0.2rem; font-size: 1.05rem; color: var(--primary); border-bottom: none; padding: 0; }
.form h2:first-of-type { margin-top: 0; }
.photo-grid img { cursor: zoom-in; }

/* Éditeur de template */
.editor-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
  flex-wrap: nowrap;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  border: 1px solid var(--primary-soft);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 0.5rem 0.8rem;
  box-shadow: var(--shadow-xs);
}
.editor-header h1 { margin: 0; color: var(--primary-dark); font-size: 1.05rem; white-space: nowrap; }
.editor-header .actions { margin-left: auto; display: flex; align-items: center; gap: 0.35rem; flex-wrap: nowrap; }
.editor-header .actions .btn-primary,
.editor-header .actions .btn-secondary { padding: 0.35rem 0.6rem; font-size: 0.82rem; white-space: nowrap; }
.editor-name {
  font-size: 0.88rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 220px;
  flex: 0 0 auto;
  color: var(--text-strong);
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.editor-name:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.save-status { font-size: 0.8rem; color: var(--muted); min-width: 0; white-space: nowrap; text-align: right; }

/* Éditeur de tableau dans le panneau de propriétés */
.table-editor { margin-top: 0.4rem; overflow-x: auto; }
.table-editor table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
.table-editor th, .table-editor td { border: 1px solid var(--border); padding: 2px; position: relative; }
.table-editor th { background: #fff7ed; font-weight: 600; }
.table-editor input[type="text"] { width: 100%; border: none; background: transparent; padding: 3px 4px; font-size: 0.82rem; outline: none; }
.table-editor input[type="text"]:focus { background: #fff; box-shadow: inset 0 0 0 1px var(--primary); }
.table-editor .icon-btn { background: transparent; border: none; cursor: pointer; color: var(--muted); font-size: 0.95rem; padding: 0 4px; }
.table-editor .icon-btn:hover { color: var(--danger); }
.table-editor #tbl-add-col { color: var(--primary); font-weight: bold; }
.table-editor #tbl-add-row { margin-top: 2px; }
.save-status.ok { color: #059669; }
.save-status.err { color: var(--danger); }
.save-status.dirty { color: #d97706; }

.editor-layout { display: grid; grid-template-columns: 360px 1fr; gap: 1rem; align-items: stretch; height: calc(100vh - 140px); min-height: 560px; }
.editor-left { display: flex; flex-direction: column; gap: 1rem; min-height: 0; }

.editor-blocks {
  background: linear-gradient(180deg, #fff7ed 0%, #fff 100%);
  border: 1px solid var(--primary-soft);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-y: auto;
  flex: 0 0 auto;
  max-height: 50%;
  box-shadow: var(--shadow-xs);
}
.blocks-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; padding-bottom: 0.7rem; border-bottom: 1px solid var(--primary-soft); }
.blocks-toolbar h2 { color: var(--primary-dark) !important; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--primary-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 100;
  display: none;
  padding: 0.35rem;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, padding-left 0.1s;
}
.dropdown-menu button:hover { background: var(--primary-light); color: var(--primary-dark); padding-left: 1rem; }

/* Menu thème */
.theme-menu { padding: 0.8rem; min-width: 240px; }
.theme-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-bottom: 0.8rem; }
.theme-preset { width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); cursor: pointer; border: 2px solid transparent; box-shadow: var(--shadow-xs); padding: 0; transition: transform 0.1s, box-shadow 0.1s; }
.theme-preset:hover { transform: scale(1.08); border-color: #fff; box-shadow: var(--shadow-md); padding-left: 0; }
.theme-custom { display: flex; flex-direction: column; gap: 0.4rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.theme-custom label { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; color: var(--text); font-weight: 500; gap: 0.5rem; padding: 0 !important; }
.theme-custom label:hover { background: transparent !important; padding-left: 0 !important; color: var(--text) !important; }
.theme-custom input[type="color"] { width: 40px; height: 28px; border: 1px solid var(--border); border-radius: 4px; padding: 2px; cursor: pointer; }

/* Presets dans la sidebar (global-settings) */
#theme-section .theme-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin-bottom: 0.5rem; }

.blocks-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.block-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.06s;
}
.block-item:hover { border-color: var(--primary); box-shadow: 0 2px 6px rgba(234, 88, 12, 0.12); }
.block-item.selected { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.15); }
.block-item.hidden { opacity: 0.45; }
.block-item .drag { cursor: grab; color: var(--muted); user-select: none; }
.block-item .drag:active { cursor: grabbing; }
.block-item .type-badge { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-size: 0.7rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.block-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block-item .icon-btn { background: transparent; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.block-item .icon-btn:hover { background: var(--bg); color: var(--text); }
.block-item .del:hover { color: var(--danger); }

.global-settings { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.8rem; }
.global-settings summary { cursor: pointer; font-weight: 500; color: var(--text); padding: 0.3rem 0; }

.props-panel {
  background: linear-gradient(180deg, #fff 0%, #fff7ed 100%);
  border: 1px solid var(--primary-soft);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 1rem;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 200px;
  box-shadow: var(--shadow-xs);
}
.props-panel h3 { margin: 0 0 0.8rem; font-size: 1rem; color: var(--primary); }
.props-panel .pp { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.7rem; font-size: 0.88rem; color: var(--text); font-weight: 500; }
.props-panel .pp input[type="checkbox"] { margin-right: 0.4rem; align-self: start; }
.props-panel .pp:has(input[type="checkbox"]) { flex-direction: row; align-items: center; font-weight: 400; }
.props-panel .pp input[type="text"], .props-panel .pp input[type="number"], .props-panel .pp select, .props-panel .pp textarea { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-weight: normal; color: var(--text); background: var(--surface); }
.props-panel .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.pp-section { margin: 1rem 0 0.5rem; font-size: 0.75rem; font-weight: 700; color: var(--primary-dark); text-transform: uppercase; letter-spacing: 0.06em; border-top: 1px solid var(--primary-soft); padding-top: 0.7rem; }
.pp-section:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.align-buttons { display: flex; gap: 0.3rem; margin-bottom: 0.7rem; }
.align-buttons button { flex: 1; padding: 0.5rem; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; cursor: pointer; font-size: 1rem; color: var(--muted); }
.align-buttons button:hover { border-color: var(--primary); color: var(--primary); }
.align-buttons button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.color-row { flex-direction: row !important; align-items: center !important; justify-content: space-between; font-weight: 500; }
.color-row-inner { display: inline-flex; align-items: center; gap: 0.4rem; }
.color-row input[type="color"] { width: 44px; height: 30px; padding: 2px; border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }

.preview-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; height: 100%; }
.preview-header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--border); background: var(--bg); font-size: 0.9rem; font-weight: 500; }
.preview-wrap iframe { flex: 1; width: 100%; border: none; background: #e5e7eb; }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.link-muted { background: transparent; color: var(--muted); padding: 0; border: none; cursor: pointer; font: inherit; text-decoration: underline; }
.link-muted:hover { color: var(--primary); }
.badge-default { background: #d1fae5; color: #065f46; padding: 3px 8px; border-radius: 4px; font-size: 0.78rem; font-weight: 500; }

@media (max-width: 760px) {
  .editor-layout { grid-template-columns: 1fr; height: auto; }
  .editor-blocks { max-height: none; }
  .preview-wrap { min-height: 600px; }
}

/* ====== Mobile ====== */
@media (max-width: 720px) {
  html { font-size: 17px; }
  body { line-height: 1.5; }
  .container { margin: 0.8rem 0 1.5rem; padding: 0 0.9rem; max-width: 100%; width: 100%; }
  h1 { font-size: 1.4rem; margin: 0 0 0.9rem; padding: 0.6rem 0.8rem; }
  h2 { font-size: 1.1rem; margin-top: 1.3rem; }

  /* Topbar : brand fixe, nav pleine largeur avec scroll horizontal */
  .topbar { padding: 0.55rem 0.8rem; flex-wrap: wrap; gap: 0.4rem; }
  .topbar .brand { font-size: 1.05rem; margin-right: 0.5rem; }
  .topbar .brand::before { width: 20px; height: 20px; }
  .topbar-logo { display: none; }
  .topbar nav { flex: 1 1 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0.15rem; padding: 0.25rem 0; }
  .topbar nav::-webkit-scrollbar { height: 4px; }
  .topbar nav a { padding: 0.45rem 0.7rem; font-size: 0.9rem; flex-shrink: 0; white-space: nowrap; }
  .topbar nav a.btn-primary { padding: 0.45rem 0.8rem; margin-left: 0.25rem; }
  .topbar .logout { font-size: 0.85rem; padding: 0.45rem 0.6rem; }

  /* Formulaires : plein largeur, plus aérés */
  .form { padding: 1rem; max-width: 100%; gap: 0.9rem; border-radius: var(--radius); }
  .form label { font-size: 0.95rem; gap: 0.3rem; }
  .form input, .form select, .form textarea,
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"],
  select, textarea {
    font-size: 16px; /* évite le zoom auto iOS */
    padding: 0.7rem 0.8rem;
    min-height: 44px; /* cible tactile confortable */
  }
  textarea { min-height: 88px; }
  .form-row { grid-template-columns: 1fr !important; gap: 0.9rem; }
  .form .actions { flex-wrap: wrap; }
  .form .actions .btn-primary, .form .actions .btn-secondary, .form .actions .btn-danger { flex: 1 1 auto; min-width: 120px; }

  /* Boutons en général : cibles tactiles 44px minimum */
  .btn-primary, .btn-secondary, .btn-danger {
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Bandeau éditeur template : blocks empilés proprement */
  .editor-header { flex-wrap: wrap; padding: 0.6rem 0.8rem; gap: 0.45rem; }
  .editor-header h1 { font-size: 1.05rem; flex: 1 1 100%; white-space: normal !important; }
  .editor-name { width: 100%; flex: 1 1 100%; font-size: 16px; }
  .editor-header .actions { flex: 1 1 100%; flex-wrap: wrap; gap: 0.35rem; }
  .editor-header .actions .btn-primary,
  .editor-header .actions .btn-secondary { padding: 0.45rem 0.7rem; font-size: 0.85rem; min-height: 40px; flex: 1 1 auto; }
  .save-status { flex: 1 1 100%; text-align: left; min-width: 0; }

  /* Éditeur : layout vertical, plus de grille 360/1fr */
  .editor-layout { grid-template-columns: 1fr !important; height: auto !important; }
  .editor-blocks { max-height: none; padding: 0.7rem; }
  .blocks-toolbar { margin-bottom: 0.6rem; padding-bottom: 0.5rem; }
  .preview-wrap { min-height: 70vh; }
  .preview-header { padding: 0.5rem 0.7rem; font-size: 0.9rem; }

  /* Listes PV/Clients : table responsive */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; white-space: nowrap; }
  .top-actions { gap: 0.4rem; }
  .top-actions .btn-primary, .top-actions .btn-secondary, .top-actions .btn-danger { flex: 1 1 auto; min-width: 110px; }

  /* Détails PV */
  dl.details { padding: 0.8rem 1rem; }
  dl.details dt { font-size: 0.8rem; }
  dl.details dd { margin-left: 0; font-size: 0.95rem; }

  /* Photos preview compactes */
  .photos-preview { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 0.5rem; }

  /* Signature pad */
  .signature-wrap { max-width: 100%; padding: 3px; }
  .signature-wrap canvas { height: 200px; }

  /* Panneau props (éditeur template) */
  .props-panel { padding: 0.7rem; }
  .pp { font-size: 0.95rem; }
}

/* ====== Très petits écrans ====== */
@media (max-width: 420px) {
  .topbar nav a { padding: 0.4rem 0.55rem; font-size: 0.85rem; }
  .editor-header .actions .btn-primary,
  .editor-header .actions .btn-secondary { flex: 1 1 calc(50% - 0.35rem); }
}
