:root {
  --blue-900: #0b2f4d;
  --blue-700: #145a8c;
  --blue-600: #1a6fa8;
  --blue-500: #2482c4;
  --blue-50: #eaf3fa;
  --accent: #f2a13a;
  --accent-dark: #d98a1f;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #dde3ea;
  --text: #1c2733;
  --text-muted: #64748b;
  --danger: #cc4444;
  --danger-bg: #fbeaea;
  --success: #2f9e5f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 35, 60, 0.08), 0 1px 2px rgba(15, 35, 60, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue-900);
  color: white;
  padding: 0 24px;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--blue-900); font-weight: 800;
}
.brand-text strong { font-weight: 700; }

.topbar-nav { display: flex; gap: 4px; }
.nav-link {
  background: transparent; border: none; color: #cfe0ef; padding: 8px 14px;
  border-radius: 7px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-link.active { background: rgba(255,255,255,0.14); color: white; }

.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user #topbar-username { color: #cfe0ef; font-size: 13px; }
.topbar-user .btn-ghost { color: #cfe0ef; border-color: rgba(255,255,255,0.25); }
.topbar-user .btn-ghost:hover { background: rgba(255,255,255,0.08); color: white; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.users-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 28px; align-items: start; }
.users-col h2 { font-size: 15px; margin: 0 0 10px; }
.users-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.users-table th, .users-table td { text-align: left; padding: 8px 10px; font-size: 13px; border-bottom: 1px solid var(--border); }
.users-table th { background: var(--blue-50); color: var(--blue-900); font-weight: 600; }
.users-table tr:last-child td { border-bottom: none; }
.users-col .panel-footer { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 0; border: none; margin-top: 12px; }
.users-col .panel-footer input, .users-col .panel-footer select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
@media (max-width: 900px) { .users-layout { grid-template-columns: 1fr; } }

/* ---------- Layout ---------- */

main#app { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.view[hidden] { display: none; }

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.view-header h1 { font-size: 22px; margin: 0; }
.project-actions { display: flex; align-items: center; gap: 8px; }

.hint { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.hint code { background: #f0f1f3; border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; }

.import-panel { max-width: 900px; }
.import-panel textarea {
  width: 100%; font-family: "SF Mono", "Fira Code", Consolas, monospace; font-size: 12.5px;
  padding: 12px; border: 1px solid var(--border); border-radius: 8px; resize: vertical;
  color: var(--text); background: white; line-height: 1.5;
}
.import-panel textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-50); }

.import-method {
  background: var(--blue-50); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 16px;
}
.import-method h3 { margin: 0 0 6px; font-size: 15px; color: var(--blue-900); }
.import-method .hint { margin-bottom: 10px; }
.import-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.import-actions:last-child { margin-bottom: 0; }
.import-actions input[type="file"] {
  font-size: 13px; color: var(--text-muted); max-width: 260px;
}

.import-fallback {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 12px;
}
.import-fallback summary {
  cursor: pointer; font-weight: 600; color: var(--blue-700); font-size: 13.5px;
}
.import-fallback[open] summary { margin-bottom: 10px; }
.import-fallback textarea { margin-top: 8px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--blue-600); color: white; }
.btn-primary:hover { background: var(--blue-700); }
.btn-secondary { background: var(--blue-50); color: var(--blue-700); border-color: #cfe3f2; }
.btn-secondary:hover { background: #dcedf9; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; padding-left: 4px; }
.btn-ghost:hover { color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: #f0d0d0; }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-back { font-size: 13px; margin-bottom: 4px; }
.btn-upload { position: relative; }

/* ---------- Project cards / list ---------- */

.projects-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: start; }
.projects-col h2 { font-size: 14px; margin: 0 0 10px; color: var(--text-muted); }
.projects-col #projects-search { width: 100%; margin-bottom: 12px; }
@media (max-width: 900px) { .projects-layout { grid-template-columns: 1fr; } }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.project-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.1s, box-shadow 0.1s;
}
.project-card:hover { box-shadow: 0 4px 14px rgba(15,35,60,0.12); transform: translateY(-1px); }
.project-card h3 { margin: 0 0 4px; font-size: 15.5px; }
.td-badge {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--blue-700);
  background: var(--blue-50); border: 1px solid #cfe3f2; border-radius: 5px;
  padding: 1px 6px; vertical-align: middle;
}
.project-card .ref { color: var(--text-muted); font-size: 13px; margin: 0 0 10px; }
.project-card .meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-muted); }
.empty-state { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-link {
  background: none; border: none; padding: 10px 16px; cursor: pointer; font-size: 14px;
  color: var(--text-muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-link.active { color: var(--blue-700); border-bottom-color: var(--blue-600); }
.tab-panel[hidden] { display: none; }

/* ---------- Forms ---------- */

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.fieldset {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.fieldset-wide { grid-column: 1 / -1; }
.fieldset legend { padding: 0 4px; font-weight: 700; font-size: 13px; color: var(--blue-700); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=search] {
  font-family: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); background: white; font-weight: 400;
}
input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-50); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.checklist { display: flex; flex-wrap: wrap; gap: 14px 24px; }
.checkbox { flex-direction: row; align-items: center; gap: 7px; font-weight: 500; color: var(--text); }
.checkbox input { width: 16px; height: 16px; }

.panel-footer { margin-top: 18px; display: flex; justify-content: flex-end; }
.save-indicator { font-size: 12px; color: var(--success); margin-right: 8px; opacity: 0; transition: opacity 0.3s; }
.save-indicator.show { opacity: 1; }

/* ---------- Modules editor ---------- */

.modules-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modules-summary { font-size: 13px; color: var(--text-muted); margin-left: auto; }

.row-block {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 14px; overflow: hidden;
}
.row-block-header {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  background: var(--blue-50); border-bottom: 1px solid var(--border);
}
.row-block-title { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--blue-900); font-size: 13.5px; }
.row-block-count { font-weight: 500; color: var(--text-muted); font-size: 12.5px; }
.row-block-count.exceeds { color: var(--danger); font-weight: 700; }
.row-block-actions { display: flex; gap: 6px; }
.row-block-actions button {
  background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 9px;
  font-size: 12px; cursor: pointer; color: var(--text-muted);
}
.row-block-actions button:hover { color: var(--text); }

.modules-strip { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.module-chip {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 110px;
  background: #fbfcfe; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px;
  position: relative;
}
.module-chip:hover { border-color: var(--blue-500); }
.module-chip .chip-icon { width: 22px; height: 22px; opacity: 0.85; }
.module-chip .chip-icon.missing { width: 22px; height: 22px; border: 1.5px dashed var(--danger); border-radius: 4px; }
.module-chip .chip-id { font-weight: 700; font-size: 13px; }
.module-chip .chip-text { font-size: 10.5px; color: var(--text-muted); text-align: center; line-height: 1.25; max-width: 100px; }
.module-chip .chip-poles { font-size: 10px; color: var(--blue-600); font-weight: 600; }
.module-chip .chip-remove {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: white; border: none; font-size: 11px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.module-chip .chip-duplicate {
  position: absolute; top: -6px; left: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--blue-600); color: white; border: none; font-size: 10px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.module-chip:hover .chip-remove, .module-chip:hover .chip-duplicate { display: flex; }
.module-chip.pole-0 { opacity: 0.45; border-style: dashed; }

.add-module-btn {
  border: 1.5px dashed var(--border); border-radius: 8px; min-width: 90px; min-height: 78px;
  background: none; cursor: pointer; color: var(--text-muted); font-size: 20px;
}
.add-module-btn:hover { border-color: var(--blue-500); color: var(--blue-600); }

.no-rows { color: var(--text-muted); padding: 30px 0; text-align: center; }

/* ---------- Module edit form (inline) ---------- */

.module-edit-box {
  background: var(--card); border: 1px solid var(--blue-500); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.module-edit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.module-edit-grid label, .module-edit-grid .module-edit-field { font-size: 11.5px; }
.module-edit-icon-picker {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 10px; cursor: pointer; background: white;
}
.module-edit-icon-picker img { width: 24px; height: 24px; }
#me-icon-label.icon-suggested { color: var(--accent-dark); font-style: italic; }
.module-edit-footer { display: flex; justify-content: space-between; margin-top: 14px; }

/* ---------- Radio pills (choix Différentiel / Disjoncteur) ---------- */

.radio-pills { display: flex; gap: 8px; }
.radio-pill {
  display: flex !important; flex-direction: row; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 20px; padding: 7px 12px 7px 8px;
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text);
  background: white;
}
.radio-pill:has(input:checked) { border-color: var(--blue-500); background: var(--blue-50); color: var(--blue-700); }
.radio-pill input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio-pill .radio-dot {
  width: 15px; height: 15px; border-radius: 50%; border: 1.5px solid var(--border);
  display: inline-block; position: relative; flex-shrink: 0; background: white;
}
.radio-pill input:checked ~ .radio-dot,
.radio-pill input:checked + .radio-dot { border-color: var(--blue-600); }
.radio-pill input:checked ~ .radio-dot::after,
.radio-pill input:checked + .radio-dot::after {
  content: ""; position: absolute; inset: 2.5px; border-radius: 50%; background: var(--blue-600);
}

/* ---------- Type wheel (roue à défilement verticale, façon roue codeuse) ---------- */

.type-wheel { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 180px; }
.type-wheel-arrow {
  width: 26px; height: 20px; border-radius: 8px; border: 1px solid var(--border);
  background: white; display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 11px; line-height: 1; color: var(--text-muted); padding: 0;
}
.type-wheel-arrow:hover { border-color: var(--blue-500); color: var(--blue-600); }
.type-wheel-viewport {
  position: relative; width: 100%; height: 102px; /* 3 × 34px */
  overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: white;
}
.type-wheel-highlight {
  position: absolute; left: 0; right: 0; top: 34px; height: 34px;
  border-top: 1.5px solid var(--blue-500); border-bottom: 1.5px solid var(--blue-500);
  background: rgba(234, 243, 250, 0.55); pointer-events: none; z-index: 1;
}
.type-wheel-track {
  height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
  scroll-behavior: smooth;
}
.type-wheel-track::-webkit-scrollbar { display: none; }
.type-wheel-pad { height: 34px; scroll-snap-align: none; }
.type-wheel-item {
  height: 34px; display: flex; align-items: center; justify-content: center;
  scroll-snap-align: center; font-size: 13px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; user-select: none;
}
.type-wheel-item.is-selected { color: var(--blue-700); font-weight: 700; }
.type-other-input { margin-top: 8px; width: 100%; }

/* ---------- Generation ---------- */

.validation-report { margin-bottom: 18px; }
.validation-line { padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.validation-line.ok { background: #eaf7ef; color: #1e7a45; }
.validation-line.warn { background: var(--danger-bg); color: var(--danger); font-weight: 600; }

.gen-section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 10px; }
.gen-format-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 28px;
}
.gen-format-banner strong { font-size: 15px; }
.gen-format-banner p { margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.4; max-width: 480px; }
.gen-format-banner select {
  min-width: 280px; font-size: 14px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); background: white; font-family: inherit;
}
.generation-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.gen-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.gen-card h3 { margin: 0 0 6px; font-size: 15px; }
.gen-card p { margin: 0 0 14px; font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }
.gen-card-highlight { background: var(--blue-50); border-color: #bfdcef; }
.gen-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Attachments ---------- */

.attachments-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.attachment-block { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.attachment-block-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.attachment-block-header h3 { margin: 0; font-size: 15px; }
.attachment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; margin-top: 10px; }
.attachment-item {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; position: relative; background: #fbfcfe;
  aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center;
}
.attachment-item img { width: 100%; height: 100%; object-fit: cover; }
.attachment-item .pdf-badge { font-size: 11px; font-weight: 700; color: var(--blue-700); }
.attachment-item .att-remove {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(204,68,68,0.9); color: white; border: none; cursor: pointer; font-size: 12px;
}

/* ---------- Pictos grid ---------- */

.pictos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.picto-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.picto-card img { width: 32px; height: 32px; }
.picto-card .picto-missing { width: 32px; height: 32px; border: 1.5px dashed var(--danger); border-radius: 6px; }
.picto-card .picto-name { font-size: 11px; color: var(--text-muted); line-height: 1.25; }
.picto-card .picto-id { font-size: 10px; color: var(--blue-600); font-weight: 700; }

/* ---------- Modal ---------- */

.modal {
  position: fixed; inset: 0; background: rgba(11,47,77,0.45); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: white; border-radius: 12px; padding: 20px; width: 100%; max-width: 420px;
  max-height: 86vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal-box-wide { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-footer { display: flex; justify-content: flex-end; margin-top: 6px; }

/* Recherche/auto-remplissage d'un client déjà connu à la création d'un
   nouveau chantier (19/08/2026) — liste déroulante juste sous le champ
   "Nom du client", remontée légèrement (margin-top négatif) pour coller au
   champ malgré le "gap" du .modal-box. */
.np-client-field { position: relative; }
.client-suggestions {
  margin-top: -6px; border: 1px solid var(--border); border-radius: 8px;
  max-height: 180px; overflow-y: auto; background: white;
  box-shadow: 0 6px 18px rgba(15,35,60,0.12);
}
.client-suggestions[hidden] { display: none; }
.client-suggestion-item {
  padding: 8px 12px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid var(--border);
}
.client-suggestion-item:last-child { border-bottom: none; }
.client-suggestion-item:hover, .client-suggestion-item.is-active { background: var(--blue-50); }
.client-suggestion-item .cs-nom { font-weight: 600; }
.client-suggestion-item .cs-detail { color: var(--text-muted); font-size: 12px; margin-top: 1px; }
.np-client-hint { margin: -6px 0 0; font-size: 12px; color: var(--text-muted); }
.np-client-hint[hidden] { display: none; }

.icon-picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px;
  max-height: 50vh; overflow-y: auto; padding-top: 4px;
}
.icon-picker-item {
  border: 1.5px solid var(--border); border-radius: 8px; padding: 8px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px; background: #fbfcfe;
  position: relative;
}
.icon-picker-item:hover { border-color: var(--blue-500); }
.icon-picker-item.selected { border-color: var(--blue-600); background: var(--blue-50); }
.icon-picker-item img { width: 26px; height: 26px; }
.icon-picker-item .name { font-size: 9.5px; color: var(--text-muted); text-align: center; line-height: 1.2; }
.icon-picker-item .radio-dot {
  position: absolute; top: 6px; right: 6px; width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--border); background: white;
}
.icon-picker-item.selected .radio-dot { border-color: var(--blue-600); }
.icon-picker-item.selected .radio-dot::after {
  content: ""; position: absolute; inset: 2.5px; border-radius: 50%; background: var(--blue-600);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--blue-900); color: white; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .panel-grid { grid-template-columns: 1fr; }
  .attachments-grid { grid-template-columns: 1fr; }
  .module-edit-grid { grid-template-columns: repeat(2, 1fr); }
}
