/* ================================================================
   CostVision — Charte PeopleOS Minimaliste
   3 couleurs : Navy Blue, Amber Gold, Light Gray
   ================================================================ */

/* ── Variables (PeopleOS) ── */
:root {
  --navy-blue: #1e3a5f;
  --amber-gold: #c17817;
  --light-gray: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-disabled: #94a3b8;
  --border-color: #e2e8f0;
  --bg-white: #ffffff;
  --bg-light: #f8fafc;

  --primary: var(--navy-blue);
  --accent: var(--amber-gold);
  --surface: var(--light-gray);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.1);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', Monaco, monospace;

  /* Sémantiques (neutres pour états) */
  --success: #16a34a;
  --warning: #d97706;
  --error: #dc2626;
  --info: #1e3a5f;

  /* Compatibilité noms existants */
  --bg-app: var(--bg-light);
  --bg-sidebar: var(--navy-blue);
  --bg-panel: var(--bg-white);
  --bg-card: var(--bg-white);
  --bg-input: var(--bg-light);
  --bg-hover: #e2e8f0;
  --bg-selected: #cbd5e1;
  --gold: var(--amber-gold);
  --gold-light: #d97706;
  --gold-dark: #9f6314;
  --gold-bg: #fef3e2;
  --gold-bg-strong: #fef3c7;
  --text-bright: var(--text-primary);
  --border: var(--border-color);
  --border-light: #e2e8f0;
  --border-active: var(--navy-blue);
  --success-bg: #f0fdf4;
  --warning-bg: #fffbeb;
  --error-bg: #fef2f2;
  --blue-bg: #e0e9f4;
  --sidebar-width: 240px;
  --sidebar-collapsed: 56px;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-light);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--navy-blue); text-decoration: none; }
a:hover { color: var(--amber-gold); }

/* ================================================================
   LAYOUT : Sidebar + Contenu
   ================================================================ */

.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar (Navy Blue — Charte) ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--navy-blue);
  border-right: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: width 0.25s ease;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.18);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand { display: flex; flex-direction: column; }

.sidebar-brand-name {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 16px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  text-decoration: none;
  position: relative;
}

.sidebar-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.sidebar-link.active {
  background: rgba(193, 120, 23, 0.25);
  color: #fef3c7;
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--amber-gold);
  border-radius: 0 2px 2px 0;
}

.sidebar-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.sidebar-count {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  line-height: 1.4;
}

/* ── Contenu principal ── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  padding: 32px 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ================================================================
   PANNEAUX / SECTIONS (Charte : fond blanc, bordure, radius 16–20px)
   ================================================================ */

.panel,
.section {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy-blue);
}

.panel-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

.section-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.section-desc {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* ================================================================
   BOUTONS (Charte)
   ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--navy-blue);
  color: #fff;
}
.btn-primary:hover { background: #152945; transform: translateY(-1px); }

.btn-accent {
  background: var(--amber-gold);
  color: #fff;
}
.btn-accent:hover { background: #9f6314; transform: translateY(-1px); }

.btn-secondary {
  background: #fff;
  color: var(--navy-blue);
  border: 2px solid var(--navy-blue);
}
.btn-secondary:hover { background: var(--bg-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--navy-blue); }

.btn-danger {
  background: var(--error);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; transform: translateY(-1px); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 6px 10px; font-size: 14px; }

.btn-group { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ================================================================
   ZONE DROP FICHIER
   ================================================================ */

.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  background: var(--bg-light);
  cursor: pointer;
  transition: all 0.2s ease;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--navy-blue);
  background: #e0e9f4;
}

.drop-zone .hint { color: var(--text-muted); font-size: 14px; margin-top: 8px; }

/* ================================================================
   GRILLE DE CARTES
   ================================================================ */

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

.card-value {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.card-value .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.card-value .value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-value .badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.badge-conf-high { background: var(--success-bg); color: var(--success); }
.badge-conf-mid { background: var(--warning-bg); color: var(--warning); }
.badge-conf-low { background: var(--error-bg); color: var(--error); }

/* ================================================================
   TABLEAUX (En-têtes Navy — Charte)
   ================================================================ */

.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data-table th,
table.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

table.data-table th {
  background: var(--navy-blue);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

table.data-table tbody tr:hover {
  background: var(--bg-light);
}

table.data-table td {
  color: var(--text-primary);
}

table.data-table td.num,
table.data-table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ================================================================
   TABLEUR (page édition devis)
   ================================================================ */

.tableur-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.tableur-table th {
  background: var(--navy-blue);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.2);
}

.tableur-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.tableur-table .cell-ro {
  background: #1e293b;
  color: #e2e8f0;
  padding: 8px 12px;
  font-size: 13px;
}

.tableur-table .cell-calc {
  background: #0f172a;
  color: #e2e8f0;
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 12px;
  text-align: right;
}

.tableur-table .cell-edit { padding: 4px 6px; }

.tableur-table .cell-edit input {
  width: 100%;
  max-width: 110px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #f1f5f9;
  font-family: var(--font-mono);
  font-size: 12px;
}

.tableur-table .cell-edit input:focus {
  outline: none;
  border-color: var(--amber-gold);
  box-shadow: 0 0 0 2px rgba(193, 120, 23, 0.2);
}

.tableur-table .cell-edit input.cell-modifie {
  background: #fef3c7;
  border-color: var(--amber-gold);
  color: var(--text-primary);
}

.tableur-table tfoot td {
  font-weight: 700;
  background: var(--bg-light);
  color: var(--text-primary);
  font-family: var(--font-mono);
  padding: 10px 12px;
  border-top: 2px solid var(--border-color);
}

/* Colonne Famille (indicative) masquée dans l'éditeur devis */
.tableur-table th.col-famille-masquee,
.tableur-table td.col-famille-masquee {
  display: none;
}

/* ================================================================
   BADGES (Charte : primary, accent, neutral)
   ================================================================ */

.badge-famille {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.badge-GOUVERNANCE { background: #3b82f6; }
.badge-BIO_PHYSIQUE { background: #22c55e; }
.badge-POLLUTION { background: #ef4444; }
.badge-SOCIAL { background: #f59e0b; }
.badge-EDD_RISQUES { background: #f97316; }
.badge-SIG_DATA { background: #8b5cf6; }
.badge-SUPPORT { background: #64748b; }

.badge-statut {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.badge-CALCULE { background: var(--blue-bg); color: var(--navy-blue); }
.badge-EN_REVISION { background: var(--warning-bg); color: var(--warning); }
.badge-VALIDE { background: var(--success-bg); color: var(--success); }
.badge-SOUMIS { background: #fef3e2; color: var(--amber-gold); }
.badge-GAGNE { background: var(--success-bg); color: var(--success); }
.badge-PERDU { background: var(--error-bg); color: var(--error); }
.badge-BROUILLON { background: var(--bg-light); color: var(--text-muted); }
.badge-ARCHIVE { background: var(--bg-light); color: var(--text-disabled); }

/* ================================================================
   MONTANT TTC, RÉCAP
   ================================================================ */

.recap-devis {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
}

.montant-ttc-big {
  font-size: 32px;
  font-weight: 800;
  color: var(--navy-blue);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.montant-ttc-big .devise {
  font-size: 18px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ================================================================
   INCERTITUDES
   ================================================================ */

.incertitudes-box {
  background: #fef3e2;
  border: 1px solid rgba(193, 120, 23, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
}

.incertitudes-box h4 {
  color: var(--amber-gold);
  margin-bottom: 8px;
  font-size: 14px;
}

/* ================================================================
   ALERTES (neutres / sémantiques légers)
   ================================================================ */

.alertes-list { margin-top: 12px; }

.alerte-item {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  font-size: 14px;
}

.alerte-p1 { background: var(--error-bg); border-left: 4px solid var(--error); color: #991b1b; }
.alerte-p2 { background: var(--warning-bg); border-left: 4px solid var(--warning); color: #92400e; }
.alerte-p3 { background: var(--bg-light); border-left: 4px solid var(--text-muted); color: var(--text-secondary); }

/* ================================================================
   TRACES
   ================================================================ */

.traces-box {
  background: #0f172a;
  border: 1px solid var(--border-color);
  padding: 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12px;
  color: #e2e8f0;
  max-height: 280px;
  overflow-y: auto;
}

.traces-box .trace-line { margin-bottom: 4px; }

/* ================================================================
   SYNTHÈSE FINANCIÈRE
   ================================================================ */

.synthese-financiere {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.synthese-table { max-width: 500px; }

.synthese-table td {
  padding: 10px 16px;
  font-size: 14px;
}

.synthese-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.synthese-table .syn-total {
  font-weight: 800;
  background: var(--navy-blue);
  color: #fff;
  font-size: 15px;
}

.synthese-table .syn-total td {
  color: #fff;
  font-size: 14px;
  border-top: 2px solid rgba(255,255,255,0.2);
}

.repartition-famille { margin-top: 12px; }
.repartition-famille ul { margin: 4px 0; list-style: none; }

/* ================================================================
   TAGS
   ================================================================ */

.tags-devis {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--navy-blue);
}

.tag-pill .tag-remove { cursor: pointer; opacity: 0.8; }
.tag-pill .tag-remove:hover { opacity: 1; }

/* ================================================================
   MODALES
   ================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.hide { display: none !important; }

.modal-box {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.modal-box h3 {
  margin-bottom: 16px;
  font-size: 18px;
  color: var(--text-primary);
}

.modal-box .modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-box textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
}

.modal-box textarea:focus {
  outline: none;
  border-color: var(--navy-blue);
}

.modal-large { max-width: 560px; }

/* ================================================================
   ONGLETS
   ================================================================ */

.param-tabs, .tabs-sites {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.param-tab, .tab-site {
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 14px;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
}

.param-tab:hover, .tab-site:hover { color: var(--navy-blue); }
.param-tab.active, .tab-site.active {
  color: var(--navy-blue);
  border-bottom-color: var(--navy-blue);
}

.param-panel { margin-top: 16px; }
#badge-modifs {
  background: var(--amber-gold);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
}

/* ================================================================
   ÉDITEUR TABLEUR — spécifiques
   ================================================================ */

.editer-section .section-desc {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compteur-modifs {
  background: #fef3c7;
  color: #92400e;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 12px;
}

.tableur-section { margin-bottom: 32px; }
.tableur-section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--navy-blue);
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.param-row label {
  min-width: 90px;
  font-size: 14px;
  color: var(--text-secondary);
}

.param-row input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text-primary);
  font-size: 13px;
  text-align: right;
}

.param-row input:focus {
  outline: none;
  border-color: var(--navy-blue);
}

.param-montant {
  margin-left: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.synthese-editer {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-light);
  border-radius: var(--radius-md);
}

.synthese-editer p { margin: 4px 0; font-size: 14px; }

.cell-annotation { cursor: pointer; padding: 4px; color: var(--text-muted); }
.cell-annotation.has-comment { color: var(--amber-gold); }

/* ================================================================
   UTILITAIRES
   ================================================================ */

.text-muted { color: var(--text-muted); }
.text-bright { color: var(--text-primary); }
.text-gold { color: var(--amber-gold); }
.mono { font-family: var(--font-mono); }
.hide { display: none !important; }
.loading { opacity: 0.5; pointer-events: none; }
.text-right { text-align: right; }

/* ================================================================
   FOOTER
   ================================================================ */

.footer {
  border-top: 1px solid var(--border-color);
  background: var(--bg-white);
  padding: 16px 24px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-left: var(--sidebar-width);
}

/* ================================================================
   IMPRESSION
   ================================================================ */

@media print {
  .sidebar, .btn-group, .btn, .footer, .tabs-sites, .cell-annotation,
  .modal-overlay, .tag-remove, .compteur-modifs {
    display: none !important;
  }
  .main-content { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .section, .panel, .recap-devis, .synthese-financiere {
    background: #fff !important;
    border-color: #ccc !important;
    box-shadow: none !important;
  }
  .montant-ttc-big { color: #000 !important; }
  table.data-table th { background: #1e3a5f !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 900px) {
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .sidebar-brand,
  .sidebar .sidebar-section-label,
  .sidebar-link span:not(.sidebar-icon),
  .sidebar-count,
  .sidebar-brand-sub,
  .sidebar-footer { display: none; }
  .sidebar-link { justify-content: center; padding: 10px; }
  .main-content { margin-left: var(--sidebar-collapsed); }
  .footer { margin-left: var(--sidebar-collapsed); }
}

@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .footer { margin-left: 0; }
  .main { padding: 20px 16px; }
  .cards-grid { grid-template-columns: 1fr; }
}
