/* Skalib — Back-office. Styles propres à la surface admin.
   Repose sur les tokens partagés (../shared/tokens.css) ; thème sombre stable.
   Règle de charte : l'ambre (--ember) est réservé à UNE action chaude par écran. */

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }

/* Boutons froids (actions secondaires) — l'ambre reste rare */
.btn-cold {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 9px 16px; font-family: var(--font-body); font-size: 13px;
  font-weight: 600; cursor: pointer; transition: border-color .15s, color .15s;
}
.btn-cold:hover { border-color: var(--accent-cold); color: var(--accent-cold); }
.btn-cold:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }
.btn-cold.sm { padding: 5px 11px; font-size: 12px; }

.link-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-family: var(--font-body); font-size: 13px; padding: 4px; text-align: left;
}
.link-btn:hover { color: var(--text); }
.link-btn:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }

/* ============================ ÉCRAN DE CONNEXION ============================ */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 34px 30px; display: flex; flex-direction: column; gap: 16px;
}
.login-brand { text-align: center; margin-bottom: 8px; }
.login-word { font-size: 40px; }
.login-tag { color: var(--text-dim); font-size: 13px; margin: 6px 0 0; }
.login-btn { width: 100%; margin-top: 6px; }
.login-error {
  color: var(--danger); font-size: 13px; margin: 0;
  background: rgba(232,121,90,.12); border: 1px solid var(--danger);
  border-radius: 10px; padding: 9px 12px;
}

/* Champs de formulaire (partagés) */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field > span { font-weight: 500; }
input, select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 12px;
  font-family: var(--font-body); font-size: 14px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent-cold); outline-offset: 1px; border-color: var(--accent-cold);
}
textarea { resize: vertical; min-height: 72px; }

/* ============================ ENVELOPPE APP ============================ */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.brand-word { font-size: 26px; }
.brand-sub {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--muted);
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: block; width: 100%; text-align: left; background: transparent;
  border: none; color: var(--text-dim); padding: 10px 14px; border-radius: 10px;
  font-family: var(--font-body); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: -2px; }
.nav-item[aria-current="page"] {
  background: var(--surface-2); color: var(--accent-cold);
  box-shadow: inset 3px 0 0 var(--accent-cold);
}
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.role-badge {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}

.main { padding: 28px 32px 64px; overflow: hidden; }
.main:focus { outline: none; }

/* ============================ EN-TÊTES DE VUE ============================ */
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.view-title { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.02em; }
.view-sub { color: var(--text-dim); font-size: 14px; margin: 0; max-width: 60ch; }
.view-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============================ CARTES KPI ============================ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .num { font-family: var(--font-mono); font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.kpi.accent { border-color: var(--accent-cold); }
.kpi.accent .num { color: var(--accent-cold); }

.section-title { font-family: var(--font-display); font-size: 17px; margin: 26px 0 12px; font-weight: 600; }

/* ============================ PANNEAUX & TABLEAUX ============================ */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-bar h3 { font-family: var(--font-display); font-size: 15px; margin: 0; font-weight: 600; }
.panel-body { padding: 18px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 12px 16px; color: var(--muted); font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.mono, .mono { font-family: var(--font-mono); }
.num-cell { font-family: var(--font-mono); text-align: right; white-space: nowrap; }

/* Badges / pastilles d'état */
.badge {
  font-family: var(--font-mono); font-weight: 700; padding: 3px 9px; border-radius: 8px;
  font-size: 12px; display: inline-block; min-width: 40px; text-align: center;
  background: var(--surface-2); color: var(--text);
}
.badge.red { background: rgba(232,121,90,.16); color: var(--danger); }
.badge.green { background: rgba(111,207,151,.16); color: var(--green); }
.badge.amber { background: rgba(240,160,90,.16); color: var(--ember); }
.pill {
  font-size: 11.5px; padding: 3px 10px; border-radius: 999px; display: inline-block;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border);
}
.pill.cold { color: var(--accent-cold); border-color: var(--accent-cold); }

/* Statut cliquable (avancer une intervention) */
.status-btn {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 5px 10px;
}
.status-btn:hover { border-color: var(--accent-cold); color: var(--accent-cold); }
.status-btn:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }

/* Menu déroulant compact dans les cellules */
select.inline { width: auto; min-width: 140px; padding: 6px 10px; font-size: 13px; }

/* ============================ CRM — pipeline (kanban) ============================ */
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.pcol { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.pcol h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; display: flex; justify-content: space-between; }
.pcol h4 span { font-family: var(--font-mono); background: var(--surface-2); padding: 0 7px; border-radius: 7px; color: var(--text); }
.pcard { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.pcard .pn { font-weight: 600; font-size: 13.5px; }
.pcard .pm { font-size: 12px; color: var(--muted); margin: 4px 0 10px; word-break: break-word; }
.pcard .pactions { display: flex; flex-direction: column; gap: 8px; }

/* ============================ Cartes (prestataires / candidatures) ============================ */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card h3 { font-family: var(--font-display); font-size: 16px; margin: 0 0 4px; }
.card .meta { font-size: 12.5px; color: var(--muted); margin: 2px 0; }
.card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.card .card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Sous-onglets */
.subtabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.subtab {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 999px; padding: 7px 16px; font-family: var(--font-body); font-size: 13px;
  font-weight: 600; cursor: pointer;
}
.subtab[aria-selected="true"] { border-color: var(--accent-cold); color: var(--accent-cold); }
.subtab:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }

/* ============================ Dispatch (classement) ============================ */
.disp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px;
}
.disp-row.best { border-color: var(--accent-cold); }
.disp-row .dl { display: flex; flex-direction: column; gap: 3px; }
.disp-row .dname { font-weight: 600; font-size: 14px; }
.disp-row .dmeta { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.disp-row .dscore { font-family: var(--font-mono); font-weight: 700; color: var(--accent-cold); font-size: 16px; }

/* ============================ Réglages ============================ */
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.config-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.config-row:last-child { border-bottom: none; }
.config-row label { font-size: 13.5px; }
.config-row input { width: 120px; text-align: right; font-family: var(--font-mono); }
.preview-total { font-family: var(--font-mono); color: var(--accent-cold); font-weight: 700; }

/* ============================ Messagerie ============================ */
.inbox { display: grid; grid-template-columns: 320px 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; height: calc(100vh - 190px); min-height: 420px; }
.thread-list { border-right: 1px solid var(--border); overflow-y: auto; }
.thread {
  display: block; width: 100%; text-align: left; background: transparent; border: none;
  border-bottom: 1px solid var(--border); padding: 14px 16px; cursor: pointer; color: var(--text);
}
.thread:hover { background: var(--surface-2); }
.thread[aria-current="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent-cold); }
.thread:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: -3px; }
.thread .ttop { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.thread .tsubject { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread .tcat { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.thread .tprev { font-size: 12.5px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread .unread { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--ember); color: #1a0f06; font-size: 10px; font-weight: 700; font-family: var(--font-mono); }
.chat-panel { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.chat-head .cs { font-weight: 600; }
.chat-head .cc { font-size: 12px; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 74%; padding: 10px 13px; border-radius: 13px; font-size: 13.5px; line-height: 1.5; }
.msg.in { background: var(--surface-2); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: rgba(70,180,193,.14); border: 1px solid var(--accent-cold); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .mt { font-size: 10px; color: var(--muted); margin-top: 4px; }
.compose { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 9px; }
.compose input { flex: 1; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); }

/* ============================ Fenêtres modales ============================ */
.overlay {
  position: fixed; inset: 0; background: rgba(5,12,13,.72);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  max-width: 560px; width: 100%; max-height: 88vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-family: var(--font-display); font-size: 19px; margin: 0; }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-close:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Bloc mot de passe temporaire renvoyé par l'API */
.temp-pw { background: var(--surface-2); border: 1px dashed var(--accent-cold); border-radius: 10px; padding: 14px; }
.temp-pw code { font-family: var(--font-mono); font-size: 16px; color: var(--accent-cold); }

/* Facture — détail */
.inv-table td { padding: 8px 10px; }
.inv-total { font-family: var(--font-mono); font-weight: 700; font-size: 17px; }

/* ============================ Utilitaires ============================ */
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.loading { text-align: center; color: var(--muted); padding: 40px 20px; }
[hidden] { display: none !important; }

/* ============================ Toasts ============================ */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 90; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent-cold);
  border-radius: 10px; padding: 12px 16px; font-size: 13.5px; max-width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: toast-in .2s ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--green); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ============================ Responsive ============================ */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .nav-item { width: auto; }
  .main { padding: 20px 16px 48px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox .chat-panel { display: none; }
  .inbox.open .thread-list { display: none; }
  .inbox.open .chat-panel { display: flex; }
}
