/* ============================================
   CRM BATILUX — Style
   Couleurs inspirées du logo Les Guides de Romandie
   ============================================ */
:root {
  --primary: #8B0000;
  --primary-dark: #6b0000;
  --primary-light: #a52a2a;
  --bg: #f6f4f0;
  --surface: #ffffff;
  --border: #e5e0d8;
  --text: #2a2a2a;
  --text-muted: #6b6b6b;
  --success: #2d8a4f;
  --warning: #d97706;
  --danger: #c1272d;
  --info: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; padding: 16px 0; }
.brand h1 { font-size: 16px; font-weight: 700; color: var(--primary); }
.brand small { color: var(--text-muted); font-size: 11px; }
.logo-mark {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: bold;
  position: relative;
}
.logo-mark::before { content: "+"; font-size: 20px; }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--primary); color: white; }
.nav a.hidden { display: none; }

/* Filtres pays */
.country-filter { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 3px; gap: 2px; }
.country-filter button { background: transparent; border: none; padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.country-filter button.active { background: var(--primary); color: white; }
.country-filter button:hover:not(.active) { background: var(--bg); color: var(--text); }
.flag-ch::before { content: "🇨🇭 "; }
.flag-fr::before { content: "🇫🇷 "; }

/* Badges factures */
.badge-brouillon { background: #f3f4f6; color: #4b5563; }
.badge-envoyee   { background: #dbeafe; color: #1e40af; }
.badge-payee     { background: #d1fae5; color: #065f46; }
.badge-annulee   { background: #fee2e2; color: #991b1b; }

/* Avancement client (badges colorés) */
.avancement {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.avancement-gray   { background: #f3f4f6; color: #6b7280; }
.avancement-yellow { background: #fef3c7; color: #92400e; }
.avancement-orange { background: #ffedd5; color: #c2410c; }
.avancement-blue   { background: #dbeafe; color: #1e40af; }
.avancement-green  { background: #d1fae5; color: #065f46; }
.avancement-red    { background: #fee2e2; color: #991b1b; }

/* Pays-card double colonne */
.pays-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pays-card { padding: 18px; border-left: 4px solid var(--primary); }
.pays-card.ch { border-left-color: #dc2626; }
.pays-card.fr { border-left-color: #1e40af; }
@media (max-width: 700px) { .pays-grid { grid-template-columns: 1fr; } }
.user-menu { display: flex; align-items: center; gap: 12px; padding: 12px 0; position: relative; }
.user-menu #user-name { font-size: 13px; }

/* Bell + notifications */
.bell-btn { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; padding: 0; }
.bell-btn:hover { background: var(--surface); }
.bell-count { position: absolute; top: -4px; right: -4px; background: var(--danger); color: white; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.bell-count.hidden { display: none; }
.notif-panel { position: absolute; top: 56px; right: 32px; width: 380px; max-height: 480px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,.12); z-index: 50; }
.notif-panel.hidden { display: none; }
.notif-panel-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: #fff8f0; border-left: 3px solid var(--primary); }
.notif-item .notif-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.notif-item .notif-msg { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.notif-item .notif-time { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* Équipe / Par commercial */
.commercial-card { padding: 18px; border-left: 4px solid var(--primary); cursor: pointer; transition: all 0.15s; }
.commercial-card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.commercial-card .role-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; background: var(--bg); color: var(--text-muted); }
.commercial-card.admin { border-left-color: #c1272d; }
.commercial-card.directeur { border-left-color: #2563eb; }
.commercial-card.editeur { border-left-color: #d97706; }
.commercial-card.commercial { border-left-color: #2d8a4f; }

/* Settings sub-tabs */
.settings-layout { display: grid; grid-template-columns: 240px 1fr; gap: 24px; align-items: start; }
.settings-tabs { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.settings-tab { display: block; padding: 10px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); margin-bottom: 2px; }
.settings-tab:hover { background: var(--bg); }
.settings-tab.active { background: var(--primary); color: white; font-weight: 600; }
.perm-matrix { width: 100%; border-collapse: collapse; }
.perm-matrix th, .perm-matrix td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: center; font-size: 13px; }
.perm-matrix th:first-child, .perm-matrix td:first-child { text-align: left; }
.perm-matrix th { background: var(--bg); font-weight: 600; font-size: 11px; text-transform: uppercase; color: var(--text-muted); }
.perm-matrix .group-row { background: #faf7f1; font-weight: 700; color: var(--primary); }
.perm-matrix input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
@media (max-width: 900px) { .settings-layout { grid-template-columns: 1fr; } }

/* Main */
main { padding: 32px; max-width: 1400px; margin: 0 auto; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); }
.kpi-sub { font-size: 12px; color: var(--text-muted); }
.kpi.primary .kpi-value { color: var(--primary); }
.kpi.success .kpi-value { color: var(--success); }
.kpi.warning .kpi-value { color: var(--warning); }

/* KPI dual currency (CHF + EUR sur même carte) */
.kpi-dual { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.kpi-currency { display: flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 700; }
.kpi-currency strong { font-weight: 700; }
.flag-mini { font-size: 14px; }
.kpi.primary .kpi-currency strong { color: var(--primary); }
.kpi.success .kpi-currency strong { color: var(--success); }
.kpi.warning .kpi-currency strong { color: var(--warning); }

/* Sections */
.section { margin-bottom: 24px; }
.section-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between;
}

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th { font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { cursor: pointer; transition: background 0.1s; }
.table tbody tr:hover { background: var(--bg); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-prospect { background: #f1ecd8; color: #8a6d00; }
.badge-envoye   { background: #dbeafe; color: #1e40af; }
.badge-signe    { background: #d1fae5; color: #065f46; }
.badge-paye     { background: #dcfce7; color: #14532d; }
.badge-annule   { background: #fee2e2; color: #991b1b; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--text);
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover { filter: brightness(0.9); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.1);
}
.field textarea { min-height: 80px; resize: vertical; }
.actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.search {
  flex: 1; padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
  position: relative; background: var(--surface);
  border-radius: 10px; padding: 28px;
  max-width: 720px; width: 92%; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none;
  font-size: 30px; line-height: 1; cursor: pointer; color: var(--text-muted);
}
.modal h2 { margin-bottom: 18px; font-size: 20px; }

/* Pipeline */
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.pipeline-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.pipeline-col h3 { font-size: 13px; margin-bottom: 12px; display: flex; justify-content: space-between; }
.pipeline-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer; font-size: 12px;
  transition: all 0.1s;
}
.pipeline-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.pipeline-card .societe { font-weight: 600; margin-bottom: 4px; }
.pipeline-card .montant { color: var(--primary); font-weight: 700; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: white;
  padding: 12px 20px; border-radius: 8px;
  z-index: 200; box-shadow: var(--shadow);
  animation: slideIn 0.2s;
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Activité */
.activity-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 32px; height: 32px;
  background: var(--bg);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.activity-content { flex: 1; }
.activity-content .desc { font-weight: 500; }
.activity-content .meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Misc */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-2 { margin-top: 16px; }
.row-gap { display: grid; gap: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab { padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500; color: var(--text-muted); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.hidden { display: none !important; }
/* Hamburger : caché par défaut, visible dès qu'on passe en responsive */
.nav-toggle { display: none; }

/* ============================================
   RESPONSIVE — tablette & téléphone
   ============================================ */

/* Tablette + téléphone (≤900px) : on passe en mode mobile avec hamburger */
@media (max-width: 900px) {
  /* === Header restructuré === */
  .header {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 12px;
    gap: 10px;
  }
  .brand { flex: 1; justify-content: space-between; padding: 8px 0; gap: 10px; }
  .brand > div:nth-child(2) { flex: 1; }
  .brand h1 { font-size: 15px; }
  .brand small { font-size: 10px; }
  .logo-mark { width: 36px; height: 36px; flex-shrink: 0; }

  /* Hamburger bien visible à droite du logo */
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--primary); color: white; border: 0;
    padding: 10px 16px; border-radius: 6px;
    font-size: 22px; font-weight: 700; line-height: 1;
    cursor: pointer; flex-shrink: 0;
    min-width: 50px; min-height: 44px;
  }
  .nav-toggle:active { opacity: 0.8; }

  /* Nav verticale repliable */
  .nav {
    flex-direction: column; width: 100%;
    background: white; border: 1px solid var(--border);
    border-radius: 8px; padding: 8px; gap: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  }
  .nav.collapsed { display: none; }
  .nav a {
    padding: 14px 14px; border-radius: 6px;
    background: #f9f9f9; font-weight: 500;
    border: 1px solid transparent; font-size: 15px;
  }
  .nav a.active { background: var(--primary); color: white; }

  /* User menu sous le header */
  .user-menu {
    width: 100%; justify-content: space-between;
    padding-top: 8px; border-top: 1px dashed var(--border);
  }
  #user-name { font-size: 12px; }

  /* Layout général + KPI */
  main { padding: 12px; }
  .pipeline { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .cards-grid { grid-template-columns: 1fr 1fr !important; }
  .pays-grid { grid-template-columns: 1fr !important; }
}

/* Téléphone uniquement (≤640px) */
@media (max-width: 640px) {
  body { font-size: 14px; }
  main { padding: 10px; }
  .section-title { font-size: 14px; }
  .card { padding: 12px; border-radius: 6px; }

  /* Panneau notifications plein largeur */
  .notif-panel { width: 92vw !important; max-width: 92vw !important; right: 4vw; }

  /* Tableaux compacts + scroll horizontal */
  .table { font-size: 12px; }
  .table th, .table td { padding: 6px 4px; }
  .card { overflow-x: auto; }
  .table th:nth-child(n+5), .table td:nth-child(n+5) { display: none; }

  /* KPIs : 1 par ligne */
  .cards-grid { grid-template-columns: 1fr !important; gap: 8px; }
  .kpi-label { font-size: 11px; }
  .kpi-value { font-size: 18px; }

  /* Formulaires */
  .field input, .field select, .field textarea { font-size: 16px; padding: 10px; } /* 16px évite le zoom auto iOS */
  .actions { flex-wrap: wrap; gap: 6px; }
  .btn { padding: 10px 12px; font-size: 13px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }

  /* Modale plein écran */
  .modal-content {
    width: 96vw !important; max-width: 96vw !important;
    max-height: 95vh !important;
    padding: 14px !important; margin: 2vh auto;
    border-radius: 8px;
  }

  /* Pipeline kanban */
  .pipeline-col { padding: 10px; }
  .pipeline-card { padding: 8px; font-size: 12px; }

  /* Settings : onglets horizontaux scrollables */
  .settings-layout { grid-template-columns: 1fr !important; }
  .settings-tabs { display: flex; flex-direction: row; overflow-x: auto; gap: 6px; padding: 0 0 8px; border-bottom: 1px solid var(--border); }
  .settings-tab { white-space: nowrap; padding: 8px 10px; border-radius: 6px; background: #f5f5f5; }
  .settings-tab.active { background: var(--primary); color: white; }

  /* Tableau BDC pricing : scroll horizontal */
  .bdc-pricing-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .bdc-pricing-wrapper table { min-width: 600px; }

  /* Activité récente */
  .activity-item { padding: 8px 6px; }
  .activity-item .desc { font-size: 12px; }
  .activity-item .meta { font-size: 10px; }
}
