/* ============================================================
   SMART4 Outil de Devis — Styles specifiques a l'application

   Ce fichier contient les styles de composants propres a l'outil
   de devis, qui ne font PAS partie du theme centralise Smart4_Theme.
   Le theme (tokens.css + components.css) gere les elements generiques
   (cards, boutons, formulaires, navbar, etc.).
   ============================================================ */

/* --- Reset & Base --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

:root {
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: var(--font-body);
}

/* --- Header --- */
header {
  background: var(--nav-bg);
  color: var(--text-primary);
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 56px;
  border-bottom: 1px solid var(--nav-border, var(--border));
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

/* --- Tables generiques --- */
table {
  width: 100%;
  border-collapse: collapse;
}
table th {
  background: var(--table-header-bg);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
table td {
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--table-border);
  color: var(--text-primary);
}
table tr:hover td {
  background: var(--accent-light);
}

/* --- Scrollbar personnalisee --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { opacity: 0.8; }

/* --- Select option styling --- */
.form-row select option,
select option {
  background: var(--bg-card);
  color: var(--text-primary);
}


/* ============================================================
   TRADES (metiers) — Cartes de configuration par metier
   ============================================================ */
.trade-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: all 0.15s;
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}
.trade-card.active {
  border-color: var(--trade-active-border);
  background: var(--trade-active-bg);
}
.trade-card.inactive {
  opacity: 0.45;
}
.trade-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.trade-header label {
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}
.trade-header input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}
.trade-config { display: none; }
.trade-card.active .trade-config { display: block; }
.trade-subtotal {
  text-align: right;
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  margin-top: 8px;
}


/* ============================================================
   RESUME — Panneau lateral de synthese du devis
   ============================================================ */
.summary { position: sticky; top: 80px; }
.summary-line {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}
.summary-line .label { color: var(--text-muted); flex: 1; min-width: 0; padding-right: 8px; }
.summary-line > span:not(.label), .summary-line > [id] { flex-shrink: 0; white-space: nowrap; }
.summary-line.total {
  font-size: 15px;
  font-weight: 700;
  color: var(--summary-total-color);
  border-top: 2px solid var(--summary-total-color);
  padding-top: 12px;
  margin-top: 8px;
}
.summary-line.total .label { color: var(--summary-total-color); }
.summary-line.annual {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}


/* ============================================================
   TIER DETAIL — Detail des tranches tarifaires
   ============================================================ */
.tier-detail { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.tier-detail table { width: 100%; margin-top: 4px; }
.tier-detail th {
  background: var(--table-header-bg);
  padding: 4px 8px;
  font-size: 11px;
  text-align: left;
  color: var(--text-secondary);
}
.tier-detail td {
  padding: 4px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--table-border);
  color: var(--text-secondary);
}


/* ============================================================
   SAUVEGARDE REF — Confirmation apres enregistrement
   ============================================================ */
.saved-ref {
  background: var(--accent-light);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
  text-align: center;
}
.saved-ref .ref {
  font-size: 20px;
  font-weight: 700;
  color: var(--success);
}


/* ============================================================
   RECHERCHE ENTREPRISE — Champ de recherche + dropdown resultats
   ============================================================ */
.search-wrapper { position: relative; }
.search-wrapper input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  font-size: 14px;
  font-family: var(--font-body);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.search-wrapper input:focus {
  border-color: var(--input-focus);
  outline: none;
  box-shadow: 0 0 0 3px var(--input-focus-shadow);
}
.search-wrapper .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
}
.search-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 var(--radius-input) var(--radius-input);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-card-hover);
  display: none;
}
.search-results.visible { display: block; }
.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--table-border);
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--accent-light); }
.search-result-item .sr-name {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
}
.search-result-item .sr-details {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.search-result-item .sr-siret {
  font-size: 11px;
  color: var(--text-muted);
}
.search-loading {
  padding: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.search-no-result {
  padding: 12px;
  text-align: center;
  color: var(--error);
  font-size: 13px;
}


/* ============================================================
   COMPANY SELECTED — Affichage de l'entreprise selectionnee
   ============================================================ */
.company-selected {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 12px;
  position: relative;
}
.company-selected .cs-name {
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
}
.company-selected .cs-details {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.5;
}
.company-selected .cs-badge {
  display: inline-block;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}


/* ============================================================
   VUE CLIENT — Style allegee pour les pages publiques
   ============================================================ */
.client-view {
  --shadow-card: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 1px 2px rgba(0,0,0,0.04);
  --radius: 10px;
}


/* ============================================================
   SELECTEUR DE THEME — Modal de changement de theme
   ============================================================ */
.theme-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.2s;
}
.theme-picker-overlay.visible {
  opacity: 1;
}
.theme-picker {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 480px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.theme-picker h2 {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}
.theme-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.theme-option {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  gap: 16px;
}
.theme-option:hover {
  border-color: var(--border-hover);
}
.theme-option.active {
  border-color: var(--accent);
  background: var(--accent-light);
}
.theme-option-preview {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.theme-option-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(128,128,128,0.2);
}
.theme-option-info {
  flex: 1;
}
.theme-option-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.theme-option-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.theme-picker-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.theme-picker-close:hover {
  color: var(--text-primary);
}

/* ============================================================
   CONTACT — Formulaire contact dans le simulateur
   ============================================================ */
.contact-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.contact-grid input {
  padding: 8px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input, 4px);
  font-size: 13px;
  background: var(--bg-input, white);
  color: var(--text-primary);
}
.contact-grid input:focus {
  border-color: var(--input-focus, var(--accent));
  outline: none;
}

/* Bouton supprimer dans company-selected */
.company-selected .cs-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--error, #c62828);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
}
.company-selected .cs-remove:hover {
  color: var(--error, #e53935);
}

/* Vérification en cours (spinner) */
.cs-checking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 4px 0;
}
.cs-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: cs-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes cs-spin {
  to { transform: rotate(360deg); }
}

/* Badge de risque affiché sous le nom de l'entreprise */
.cs-risk {
  margin: 5px 0 3px;
}
.risk-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 10px;
  letter-spacing: 0.01em;
}
.risk-badge.risk-green   { background: #d4edda; color: #155724; }
.risk-badge.risk-yellow  { background: #fff3cd; color: #856404; }
.risk-badge.risk-orange  { background: #fde8d0; color: #7c3a00; }
.risk-badge.risk-red     { background: #f8d7da; color: #721c24; }
.risk-badge.risk-unknown { background: #fff3cd; color: #856404; font-weight: 400; }

/* Bloc BLOQUÉ — remplace la fiche entreprise */
.cs-blocked-container {
  border-color: var(--error, #c62828) !important;
  background: #fff5f5 !important;
}
.cs-blocked {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cs-blocked-icon {
  font-size: 22px;
  line-height: 1;
}
.cs-blocked-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--error, #c62828);
}
.cs-blocked-reason {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}
.cs-blocked-company {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.cs-blocked-retry {
  margin-top: 6px;
  align-self: flex-start;
  font-size: 12px;
  padding: 5px 12px;
}

/* Toast warning (non-bloquant) */
.toast.warning { background: #e65100; }


/* --- Responsive --- */
@media (max-width: 768px) {
  header { padding: 0 12px; }
}
