*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette industrielle */
  --navy-950: #081420;
  --navy-900: #0c1d30;
  --navy-800: #122943;
  --navy-700: #1b3a5c;
  --primary: #1a3c5e;
  --primary-light: #2e6db4;
  --accent: #22d3ee;
  --accent-deep: #0891b2;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;

  --ok: #16a34a;
  --ko: #dc2626;
  --douteux: #d97706;
  --en-cours: #2563eb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 16px rgba(15,23,42,0.06);
  --shadow-lg: 0 8px 24px rgba(15,23,42,0.10), 0 20px 48px rgba(15,23,42,0.10);
  --focus-ring: 0 0 0 3px rgba(8,145,178,0.22);
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }

code { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }

/* ════ Login ════ */
#login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(34,211,238,0.16), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(46,109,180,0.25), transparent 55%),
    linear-gradient(160deg, var(--navy-950) 0%, var(--navy-800) 100%);
  position: relative; overflow: hidden;
}
#login-page::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}

.login-card {
  position: relative; background: var(--surface); padding: 40px 36px 32px; border-radius: 18px;
  box-shadow: var(--shadow-lg); width: 392px; max-width: 100%;
  animation: card-in 0.45s cubic-bezier(0.21, 1.02, 0.55, 1) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }

.login-logo {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 16px; color: white;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(140deg, var(--navy-700), var(--accent-deep));
  box-shadow: 0 8px 20px rgba(8,145,178,0.35);
}
.login-logo svg { width: 30px; height: 30px; }
.login-card h2 { text-align: center; font-size: 22px; font-weight: 800; letter-spacing: 1.5px; color: var(--navy-900); }
.login-card h2 span { color: var(--accent-deep); }
.login-card p { text-align: center; color: var(--text-muted); margin: 4px 0 26px; font-size: 13px; }
.login-card label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 6px; margin-top: 14px; color: var(--text); }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: var(--surface-2); transition: border-color .15s, box-shadow .15s, background .15s;
}
/* Force form control text color to theme text so fields are readable in dark theme */
.login-card input, .login-card textarea, .login-card select, .form-field input, .form-field textarea, .form-field select, .filters input, .filters select { color: var(--text); }
.login-card input::placeholder, .login-card textarea::placeholder, .form-field input::placeholder, .form-field textarea::placeholder,
.filters input::placeholder, .filters select::placeholder { color: var(--text-muted); opacity: 0.85; }
.login-card input:focus { outline: none; border-color: var(--accent-deep); background: var(--surface); box-shadow: var(--focus-ring); }
#login-error { color: var(--ko); font-size: 13px; margin-top: 10px; text-align: center; min-height: 18px; font-weight: 500; }

.btn-primary {
  width: 100%; color: white; border: none; padding: 12px; border-radius: 10px;
  font-size: 15px; font-weight: 700; font-family: inherit; cursor: pointer; margin-top: 14px; letter-spacing: 0.2px;
  background: linear-gradient(135deg, var(--navy-700), var(--accent-deep));
  box-shadow: 0 4px 14px rgba(8,145,178,0.30);
  transition: transform .12s, box-shadow .15s, filter .15s;
}
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 6px 18px rgba(8,145,178,0.40); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ════ App layout ════ */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 100%);
  color: #cbd5e1; position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 18px; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; color: white;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(140deg, var(--navy-700), var(--accent-deep));
  box-shadow: 0 4px 12px rgba(8,145,178,0.35);
}
.brand-icon svg { width: 21px; height: 21px; }
.brand-name { font-size: 15.5px; font-weight: 800; letter-spacing: 1.2px; color: white; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--accent); }

.sidebar nav { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; flex: 1; border-top: 1px solid rgba(255,255,255,0.07); }
.sidebar nav button {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: none; border: none; color: #94a3b8; padding: 10px 12px; border-radius: 9px;
  cursor: pointer; font-size: 13.5px; font-weight: 600; font-family: inherit;
  transition: background .15s, color .15s; position: relative;
}
.sidebar nav button svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar nav button:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.sidebar nav button.active { background: rgba(34,211,238,0.12); color: var(--accent); }
.sidebar nav button.active::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}

.sidebar-footer { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,0.07); display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; color: var(--accent);
  background: rgba(34,211,238,0.12); border: 1px solid rgba(34,211,238,0.25);
  display: flex; align-items: center; justify-content: center;
}
.user-avatar svg { width: 15px; height: 15px; }
#user-info { font-size: 12px; font-weight: 600; color: #e2e8f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12); color: #cbd5e1;
  padding: 8px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600; font-family: inherit;
  transition: background .15s, color .15s, border-color .15s;
}
#btn-logout svg { width: 14px; height: 14px; }
#btn-logout:hover { background: rgba(220,38,38,0.16); border-color: rgba(220,38,38,0.40); color: #fca5a5; }

/* Settings button (sidebar) */
#btn-settings {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); color: #cbd5e1;
  padding: 8px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600; font-family: inherit;
  transition: background .12s, color .12s, border-color .12s;
}
#btn-settings svg { width: 14px; height: 14px; }
#btn-settings:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; border-color: rgba(255,255,255,0.14); }

/* Theme: dark mode overrides */
body[data-theme="dark"] {
  --bg: linear-gradient(160deg, var(--navy-950) 0%, var(--navy-800) 100%);
  --surface: #071023;
  --surface-2: #071725;
  --border: rgba(255,255,255,0.06);
  --text: #e6eef8;
  --text-muted: #9fb0c6;
}

main { flex: 1; padding: 28px 32px 48px; max-width: 1280px; min-width: 0; }

/* ════ Sections ════ */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-header h2 { font-size: 19px; font-weight: 800; color: var(--navy-900); letter-spacing: -0.2px; }

.period-title { color: var(--text-muted); font-size: 12px; font-weight: 700; margin: 26px 0 12px; text-transform: uppercase; letter-spacing: 1px; display: flex; align-items: center; gap: 10px; }
.period-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.period-title:first-of-type { margin-top: 0; }

/* ════ KPI cards ════ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 26px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 18px 16px;
  box-shadow: var(--shadow); border: 1px solid var(--border); position: relative; overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--navy-700), var(--accent-deep)); }
.kpi-card.ok::before { background: var(--ok); }
.kpi-card.ko::before { background: var(--ko); }
.kpi-card.douteux::before { background: var(--douteux); }
.kpi-card .label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; }
.kpi-card .value { font-size: 30px; font-weight: 800; margin: 6px 0 2px; color: var(--navy-900); letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.kpi-card .sub { font-size: 12px; color: var(--text-muted); }
.kpi-card.ok .value { color: var(--ok); }
.kpi-card.ko .value { color: var(--ko); }
.kpi-card.douteux .value { color: var(--douteux); }

.chart-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 18px; }
.bar-chart-row { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; margin-bottom: 12px; }
.bar-chart-row:last-child { margin-bottom: 0; }
.bar-chart-bar { height: 16px; border-radius: 999px; background: linear-gradient(90deg, var(--navy-700), var(--accent-deep)); min-width: 8px; }

/* Cartes tableau de bord (style maquette) */
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.dash-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dash-card-head h3 { font-size: 14px; font-weight: 700; color: var(--text); }
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 6px 0 4px; }
.hero-card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--hero-accent, var(--accent)); border-radius: var(--radius); padding: 15px 18px; box-shadow: var(--shadow); }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hero-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.hero-ico { color: var(--hero-accent, var(--accent)); display: flex; }
.hero-value { font-size: 30px; font-weight: 800; color: var(--text); line-height: 1.1; margin: 8px 0 4px; letter-spacing: -.5px; }
.hero-sub { font-size: 12px; color: var(--text-muted); }

/* ════ Table ════ */
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface-2); color: var(--text-muted); padding: 11px 16px; text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s; }
tbody tr:hover { background: #f1f6fb; }
tbody td { padding: 11px 16px; font-size: 13px; }
tbody tr:last-child { border-bottom: none; }

/* ════ Verdict badges ════ */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-OK { background: #dcfce7; color: #15803d; }
.badge-KO { background: #fee2e2; color: #b91c1c; }
.badge-DOUTEUX { background: #fef3c7; color: #b45309; }
.badge-EN_COURS { background: #dbeafe; color: #1d4ed8; }

/* ════ Sous-onglets (Inspections) ════ */
.subtabs {
  display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.subtab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border: none; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--text-muted); font-family: inherit; font-size: 13.5px; font-weight: 600;
  transition: background .15s, color .15s, box-shadow .15s;
}
.subtab svg { width: 16px; height: 16px; }
.subtab:hover { color: var(--text); background: var(--surface-2); }
.subtab.active {
  background: linear-gradient(135deg, var(--navy-700), var(--accent-deep));
  color: white; box-shadow: 0 2px 8px rgba(8,145,178,0.30);
}

/* ════ Formulaires d'inspection ════ */
.form-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; max-width: 720px;
}
.form-card h3 { font-size: 16px; font-weight: 700; color: var(--navy-900); margin-bottom: 6px; }
.form-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 18px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-field { margin-bottom: 14px; min-width: 200px; }
.form-field.grow { flex: 1; }
.form-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-field select, .form-field textarea, .form-field input:not([type="range"]) {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-field textarea { resize: vertical; }
.form-field select:focus, .form-field textarea:focus, .form-field input:not([type="range"]):focus { outline: none; border-color: var(--accent-deep); box-shadow: var(--focus-ring); }
.form-field input[type="range"] { width: 100%; accent-color: var(--accent-deep); margin-top: 10px; }
.btn-lg { padding: 11px 22px; font-size: 14px; border-radius: 10px; border: none; cursor: pointer; font-family: inherit; font-weight: 700; }

.capture-zone { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border); }
.capture-head { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 14px; }

/* ════ Filters & buttons ════ */
.filters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; align-items: flex-end; }
.filters label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 5px; }
.filters select, .filters input {
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 13px;
  font-family: inherit; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.filters select:focus, .filters input:focus { outline: none; border-color: var(--accent-deep); box-shadow: var(--focus-ring); }

.btn-sm {
  padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, transform .12s, box-shadow .15s;
}
.btn-sm:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn-sm:active { transform: translateY(1px); }
.btn-primary-sm {
  background: linear-gradient(135deg, var(--navy-700), var(--accent-deep));
  color: white; border-color: transparent; box-shadow: 0 2px 8px rgba(8,145,178,0.28);
}
.btn-primary-sm:hover { background: linear-gradient(135deg, var(--navy-700), var(--accent-deep)); filter: brightness(1.08); border-color: transparent; }

/* ════ Pagination ════ */
.pagination { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.pagination button {
  padding: 6px 13px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--surface);
  cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--text);
  transition: background .15s, border-color .15s;
}
.pagination button:hover:not(:disabled) { background: var(--surface-2); border-color: #cbd5e1; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ════ Modal ════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(8,20,32,0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  animation: overlay-in .18s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 16px; width: 720px; max-width: 100%; max-height: 88vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: modal-in .22s cubic-bezier(0.21, 1.02, 0.55, 1) both;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal::-webkit-scrollbar { width: 10px; }
.modal::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; border: 3px solid var(--surface); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 22px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--navy-900); }
.modal-close {
  background: var(--surface-2); border: 1px solid var(--border); width: 30px; height: 30px; border-radius: 8px;
  font-size: 17px; cursor: pointer; color: var(--text-muted); line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background .15s, color .15s;
}
.modal-close:hover { background: #fee2e2; color: var(--ko); border-color: #fecaca; }
.modal-body { padding: 22px; }
.modal-body h4 { font-weight: 700; }
.detail-row { display: flex; gap: 8px; margin-bottom: 7px; font-size: 13px; }
.detail-row .key { color: var(--text-muted); min-width: 140px; font-weight: 500; }

/* ════ Health ════ */
.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.health-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; transition: transform .15s, box-shadow .15s;
}
.health-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.health-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; position: relative; }
.health-dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(22,163,74,0.15); animation: pulse 2.2s ease-in-out infinite; }
.health-dot.ko { background: var(--ko); box-shadow: 0 0 0 4px rgba(220,38,38,0.15); }
.health-dot.unknown { background: #94a3b8; box-shadow: 0 0 0 4px rgba(148,163,184,0.15); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 4px rgba(22,163,74,0.15); } 50% { box-shadow: 0 0 0 7px rgba(22,163,74,0.07); } }

/* ════ Loading / empty ════ */
.loading { text-align: center; padding: 48px; color: var(--text-muted); }
.spinner {
  display: inline-block; width: 30px; height: 30px; border: 3px solid var(--border);
  border-top-color: var(--accent-deep); border-radius: 50%; animation: spin 0.7s linear infinite; margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center; padding: 36px; color: var(--text-muted); font-size: 13px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ════ Chart ════ */
.chart-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 18px; }

/* ════ Validation panel ════ */
.validation-panel { margin-top: 22px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.validation-panel h4 { color: var(--navy-900); margin-bottom: 12px; font-size: 14px; font-weight: 700; }
.validation-panel textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 13px; font-family: inherit; resize: vertical; margin-bottom: 8px; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.validation-panel textarea:focus { outline: none; border-color: var(--accent-deep); box-shadow: var(--focus-ring); }
.form-error { color: var(--ko); font-size: 12px; font-weight: 500; min-height: 16px; margin-bottom: 6px; }

/* ════ Verify result ════ */
.verify-box { margin-top: 14px; padding: 13px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; }
.verify-ok { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.verify-ko { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* ════ Photos d'inspection ════ */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.photo-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; transition: box-shadow .15s; }
.photo-cell:hover { box-shadow: var(--shadow); }
.photo-thumb { height: 100px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); overflow: hidden; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.photo-cell:hover .photo-thumb img { transform: scale(1.04); }
.photo-meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 6px 9px; font-size: 10px; color: var(--text-muted); }
.photo-del { background: none; border: none; color: var(--ko); font-size: 14px; cursor: pointer; line-height: 1; padding: 0 2px; border-radius: 4px; }
.photo-del:hover { background: #fee2e2; }
.photo-actions { display: flex; gap: 8px; margin-bottom: 10px; }
#camera-panel video { width: 100%; max-height: 320px; border-radius: 10px; background: #000; margin-bottom: 8px; }
.camera-error {
  margin: 6px 0 10px; padding: 14px 16px; border-radius: 10px; font-size: 13px; line-height: 1.6;
  background: #fef3c7; border: 1px solid #fde68a; color: #92400e;
}

/* ════ Toasts ════ */
#toast-container { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--navy-900); color: white; padding: 12px 16px; border-radius: 11px;
  border-left: 4px solid var(--accent); box-shadow: 0 8px 24px rgba(8,20,32,0.35);
  font-size: 13px; font-weight: 500; max-width: 380px; animation: toast-in 0.28s cubic-bezier(0.21, 1.02, 0.55, 1);
}
.toast-success { border-left-color: #4ade80; }
.toast-error { border-left-color: #f87171; }
.toast-out { opacity: 0; transform: translateX(12px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ════ Responsive ════ */
@media (max-width: 860px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0 8px; padding-right: 10px; }
  .brand { padding: 12px 14px; }
  .sidebar nav { flex-direction: row; border-top: none; padding: 8px 6px; overflow-x: auto; scrollbar-width: none; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav button { width: auto; white-space: nowrap; padding: 8px 12px; }
  .sidebar nav button.active::before { display: none; }
  .sidebar-footer { border-top: none; flex-direction: row; align-items: center; margin-left: auto; padding: 8px 4px; }
  #btn-logout span { display: none; }
  #btn-logout { padding: 8px 10px; }
  main { padding: 18px 16px 40px; }
}

/* ════ Téléphone : optimisation tactile ════ */
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px 14px 12px; }
  .kpi-card .value { font-size: 26px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 9px 11px; }
  .user-chip { display: none; }

  /* Navigation en barre inférieure — zone du pouce */
  .sidebar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    background: var(--navy-950); border-top: 1px solid rgba(255,255,255,0.08);
    justify-content: space-around; gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 20px rgba(8,20,32,0.45);
    overflow-x: visible;
  }
  .sidebar nav button { flex: 1 1 0; flex-direction: column; gap: 4px; padding: 8px 2px; font-size: 10.5px; white-space: normal; text-align: center; }
  .sidebar nav button svg { width: 21px; height: 21px; }
  .sidebar nav button.active { background: rgba(34,211,238,0.14); }
  main { padding: 16px 14px calc(88px + env(safe-area-inset-bottom)); }

  /* Anti-zoom iOS : champs à 16px minimum */
  .login-card input, .form-field input:not([type="range"]), .form-field select,
  .form-field textarea, .filters input, .filters select, .validation-panel textarea { font-size: 16px; }

  /* Cibles tactiles généreuses */
  .btn-lg { width: 100%; padding: 15px; font-size: 15px; }
  .btn-sm { padding: 12px 14px; font-size: 14px; }
  .btn-primary { padding: 15px; }
  .photo-actions { flex-wrap: wrap; }
  .photo-actions .btn-sm { flex: 1 1 45%; min-height: 48px; }
  .subtabs { display: flex; width: 100%; }
  .subtab { flex: 1; justify-content: center; padding: 12px 6px; }
  .form-card { padding: 18px 16px; }
  .form-row { flex-direction: column; gap: 0; }
  .form-field { min-width: 0; }
  .filters > div { flex: 1 1 100%; }
  .filters select, .filters input { width: 100%; }
  .filters button { width: 100%; }

  /* Modale en bottom sheet plein écran */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0;
    animation: sheet-in .26s cubic-bezier(0.21, 1.02, 0.55, 1) both;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-close { width: 38px; height: 38px; font-size: 19px; }
  .detail-row .key { min-width: 108px; }

  /* Toasts au-dessus de la barre de navigation */
  #toast-container { left: 14px; right: 14px; bottom: calc(80px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* Caméra plus haute sur écran vertical */
  #camera-panel video { max-height: 48vh; }

  /* Login compact */
  .login-card { padding: 30px 22px 26px; }
}
@keyframes sheet-in { from { transform: translateY(48px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Bandeau d'alerte compact (global — utilisé sur Dashboard et Traçabilité) */
.alert-banner{display:flex;align-items:center;gap:12px;background:rgba(217,119,6,.10);border:1px solid rgba(217,119,6,.30);border-radius:10px;padding:11px 14px}
.alert-banner-ico{font-size:16px;flex:none}
.alert-banner-txt{flex:1;min-width:0;font-size:.85rem;color:var(--text)}
.alert-banner-txt b{color:#d97706}
.alert-banner-cta{flex:none;padding:6px 13px;border-radius:7px;font-size:.78rem;font-weight:700;border:none;background:var(--primary-light);color:#fff;cursor:pointer}
.alert-banner-cta:hover{filter:brightness(1.08)}

/* ════ Optimisation mobile (compléments post-refontes 2a–10b) ════
   Placé en fin de fichier : les surcharges #tab-content gagnent sur les
   <style> injectés par app.js dans les écrans. */
@media (max-width: 860px) {
  /* Les en-têtes de groupe (Pilotage / Contrôle qualité / Gestion) n'ont
     pas de sens dans une barre horizontale. */
  .sidebar nav .nav-group { display: none !important; }
}
@media (max-width: 640px) {
  /* Barre basse : 11 onglets possibles -> défilement horizontal fluide
     au lieu de boutons écrasés/coupés. */
  .sidebar nav { justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sidebar nav button { flex: 1 0 64px; min-width: 64px; }

  /* Cartes de choix du mode d'inspection : une par ligne. */
  #tab-content .mode-cards { grid-template-columns: 1fr; }

  /* Segments d'onglets (période, traçabilité, CND) : pleine largeur. */
  #tab-content .period-seg, #tab-content .traca-seg, #tab-content .cnd-seg { display: flex; width: 100%; }
  #tab-content .period-seg button, #tab-content .traca-seg button, #tab-content .cnd-seg button { flex: 1; padding-left: 6px; padding-right: 6px; }

  /* Hero de facturation : empilé, bouton pleine largeur. */
  #tab-content .bill-hero { flex-direction: column; align-items: stretch; }
  #tab-content .bill-hero-btn { width: 100%; padding: 13px; }

  /* Bandeaux d'alerte : le CTA passe à la ligne sans écraser le texte. */
  #tab-content .alert-banner { flex-wrap: wrap; }
  #tab-content .alert-banner-cta { min-height: 40px; }

  /* Équipe : la recherche prend toute la largeur au-dessus des filtres. */
  #tm-search { max-width: none; flex: 1 1 100%; }

  /* Stepper IA compact. */
  #tab-content .ai-step-lbl { font-size: .72rem; }
  #tab-content .ai-stepper { gap: 5px; }

  /* Fil d'Ariane CND : sélecteurs bornés à l'écran. */
  #tab-content .cnd-crumb select { max-width: 38vw; }

  /* Grille du dashboard : boutons de la barre d'outils widgets plus tactiles. */
  .dwb-size button { padding: 6px 11px; }
  .dwb-hide { width: 34px; height: 32px; }
}
