/* Skalib — Portail propriétaire. Styles propres à la surface.
   Repose sur ../shared/tokens.css (thème sombre STABLE : .theme-dark).
   L'ambre (--ember) reste réservée à UNE seule action chaude par écran. */

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100vh; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* Utilitaires */
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.sk-mono, .mono { font-family: var(--font-mono); }
.stars { color: var(--ember); }

/* ============================ CONNEXION ============================ */
.login { 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: 32px 28px; display: flex; flex-direction: column; gap: 16px;
}
.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 6px; }
.login-brand h1 { font-size: 34px; margin: 4px 0 0; }
.login-tag { color: var(--muted); font-size: 13px; margin: 0; }
.login-note { color: var(--muted); font-size: 12px; margin: 4px 0 0; text-align: center; line-height: 1.4; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.field input, .field select, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: 14px;
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 3px solid var(--accent-cold); outline-offset: 1px; border-color: var(--accent-cold);
}
.form-err { color: var(--danger); font-size: 13px; margin: 0; }

/* ============================ COQUE APP ============================ */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.brand-name { font-size: 20px; margin: 0; }
.brand-tag { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.who { background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; }
.who-nm { font-weight: 600; font-size: 13.5px; }
.who-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text-dim); padding: 10px 12px;
  border-radius: 9px; font-size: 13.5px; font-weight: 500;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: color-mix(in srgb, var(--accent-cold) 16%, transparent); color: var(--accent-cold); }
.nav button:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: -2px; }
.nav .ic { width: 17px; height: 17px; flex: 0 0 auto; }
.nav .bn {
  margin-left: auto; font-family: var(--font-mono); font-size: 10px;
  background: var(--accent-cold); color: var(--night); padding: 1px 7px; border-radius: 8px;
}
.spacer { flex: 1; }
.logout { font-size: 12.5px; color: var(--text-dim); background: none; border: 1px solid var(--border); border-radius: 9px; padding: 9px; }
.logout:hover { color: var(--text); border-color: var(--muted); }
.logout:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }

.main { padding: 22px 28px 60px; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.propsel { display: flex; align-items: center; gap: 9px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 7px 9px 7px 13px; }
.propsel label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.propsel select { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 11px; font-size: 13px; font-weight: 600; }
.propsel select:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 1px; }

.banner { background: color-mix(in srgb, var(--danger) 14%, transparent); border: 1px solid var(--danger); color: var(--danger); border-radius: 11px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; }

.vtitle { font-family: var(--font-display); font-size: 24px; font-weight: 600; margin: 0 0 3px; letter-spacing: -.4px; }
.vsub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

/* ============================ COMPOSANTS ============================ */
/* Boutons : ambre (chaud) = .sk-btn (dans tokens) ; froid = .btn-cold */
.btn-cold { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 10px 18px; font-size: 13px; font-weight: 600; }
.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; }
.sk-btn.sm, .btn-cold.sm { padding: 7px 13px; font-size: 12.5px; }
.sk-btn:disabled { opacity: .6; cursor: progress; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .num { font-family: var(--font-mono); font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi.hl { border-color: var(--accent-cold); background: linear-gradient(160deg, color-mix(in srgb, var(--accent-cold) 12%, transparent), transparent); }
.kpi.hl .num { color: var(--accent-cold); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 17px; }
.panel h4 { font-family: var(--font-display); font-size: 15px; margin: 0 0 4px; }
.panel .ph { color: var(--muted); font-size: 12px; margin: 0 0 14px; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13px; gap: 10px; }
.row:last-child { border: none; }

.pill { font-size: 11px; padding: 2px 9px; border-radius: 7px; white-space: nowrap; display: inline-block; }
.pill.green { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.pill.cold  { background: color-mix(in srgb, var(--accent-cold) 18%, transparent); color: var(--accent-cold); }
.pill.amber { background: color-mix(in srgb, var(--ember) 18%, transparent); color: var(--ember); }
.pill.muted { background: var(--surface-2); color: var(--muted); }
.pill.danger{ background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* Tableaux */
.tablewrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbar { display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 7px 13px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tab.on { background: color-mix(in srgb, var(--accent-cold) 16%, transparent); border-color: var(--accent-cold); color: var(--accent-cold); }
.tab:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 1px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 14px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }

/* Cartes de chalets */
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.pcard .img { height: 120px; background: linear-gradient(135deg, var(--spruce-700), var(--spruce-900)); }
.pcard .b { padding: 15px 16px; }
.pcard h3 { font-family: var(--font-display); font-size: 16px; margin: 0 0 2px; }
.pcard .loc { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; gap: 10px; }
.kv:last-child { border: none; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; text-align: right; }

/* Ligne de transparence sur les factures */
.twoline { color: var(--accent-cold); font-size: 11px; }

/* Détail catalogue de service (transparence des prix) */
.svc-opt { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--border); border-radius: 11px; margin-bottom: 9px; background: var(--surface-2); }
.svc-opt:hover, .svc-opt.sel { border-color: var(--accent-cold); background: color-mix(in srgb, var(--accent-cold) 12%, transparent); }
.svc-opt:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 1px; }
.svc-opt .so-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.svc-opt .so-name { font-weight: 600; font-size: 14px; }
.svc-opt .so-ttc { font-family: var(--font-mono); font-weight: 700; }
.pricebreak { margin-top: 8px; font-size: 12px; }
.pricebreak .pb-line { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.pricebreak .pb-line b { color: var(--text); font-family: var(--font-mono); }
.pricebreak .pb-fee { color: var(--accent-cold); }
.pricebreak .pb-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px; color: var(--text); font-weight: 600; }

/* Messagerie */
.inbox { display: grid; grid-template-columns: 300px 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; height: calc(100vh - 200px); min-height: 440px; }
.ilist { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.isearch { padding: 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.isearch input { flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.isearch input:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 1px; }
.ithreads { overflow-y: auto; flex: 1; }
.ithread { display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; width: 100%; background: none; border-left: none; border-right: none; border-top: none; text-align: left; color: var(--text); }
.ithread:hover { background: var(--surface-2); }
.ithread.on { background: color-mix(in srgb, var(--accent-cold) 14%, transparent); }
.ithread:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: -2px; }
.iav { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 14px; color: var(--night); background: var(--accent-cold); flex: 0 0 auto; }
.ithread .top { display: flex; justify-content: space-between; gap: 6px; }
.ithread .nm { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ithread .tm { font-size: 10.5px; color: var(--muted-2); white-space: nowrap; }
.ithread .pv { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ithread .unread { width: 18px; height: 18px; border-radius: 50%; background: var(--ember); color: var(--night); font-size: 10px; font-weight: 700; display: grid; place-items: center; flex: 0 0 auto; font-family: var(--font-mono); }
.ipanel { display: flex; flex-direction: column; min-width: 0; }
.ihead { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 11px; }
.ihead .nm { font-weight: 600; }
.ihead .sub { font-size: 11.5px; color: var(--muted); }
.ichat { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; padding: 10px 13px; border-radius: 13px; font-size: 13px; 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: color-mix(in srgb, var(--accent-cold) 14%, transparent); border: 1px solid var(--accent-cold); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .t { font-size: 10px; color: var(--muted-2); margin-top: 4px; text-align: right; }
.icompose { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 9px; }
.icompose input { flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 11px; padding: 12px 14px; font-size: 13.5px; }
.icompose input:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 1px; }
.iempty { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }

/* Paramètres */
.setgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; gap: 14px; border-bottom: 1px solid var(--border); }
.toggle:last-child { border: none; }
.toggle .tg-lbl { font-size: 13px; }
.toggle .tg-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.switch { width: 44px; height: 24px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); position: relative; flex: 0 0 auto; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch[aria-checked="true"] { background: var(--accent-cold); border-color: var(--accent-cold); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--night); }
.switch:focus-visible { outline: 3px solid var(--accent-cold); outline-offset: 2px; }

/* Modale */
.overlay { position: fixed; inset: 0; background: rgba(5, 12, 12, .68); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; padding: 24px; }
.modal h3 { font-family: var(--font-display); margin: 0 0 12px; font-size: 20px; }
.modal-close { position: sticky; top: 0; float: right; background: none; border: none; color: var(--muted); font-size: 22px; line-height: 1; }
.modal-close:focus-visible { outline: 3px solid var(--accent-cold); }
.inv-table td { padding: 8px 4px; }
.inv-table .amt { text-align: right; font-family: var(--font-mono); }
.inv-table .tot { font-family: var(--font-mono); font-weight: 700; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions > * { flex: 1; }

/* Notifications */
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent-cold); border-radius: 10px; padding: 12px 16px; font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); max-width: 320px; }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--green); }

.empty { text-align: center; padding: 34px; color: var(--muted); font-size: 13px; }
.spinner { text-align: center; padding: 40px; color: var(--muted); font-size: 13px; }

/* Responsive */
@media (max-width: 1050px) { .grid2 { grid-template-columns: 1fr; } .kpis { grid-template-columns: repeat(2, 1fr); } .setgrid { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .spacer { display: none; }
  .inbox { grid-template-columns: 1fr; }
  .inbox .ipanel { display: none; }
  .inbox.openthread .ilist { display: none; }
  .inbox.openthread .ipanel { display: flex; }
}
