/* AVERO — feuille de style unique. Thèmes clair/sombre via [data-theme], couleur d'accent par entreprise via --accent. */
:root {
  --font: ui-sans-serif, -apple-system, "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #5d6470;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --info: #175cd3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 8px;
  --sidebar: 232px;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1f232b;
  --border: #2b3039;
  --text: #e8eaee;
  --muted: #9aa2af;
  --danger: #f97066;
  --warning: #fdb022;
  --success: #47cd89;
  --info: #84adff;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Mise en page ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; padding: 18px 20px; font-weight: 800; letter-spacing: .12em; font-size: 17px; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: var(--accent-contrast); display: grid; place-items: center; font-size: 13px; letter-spacing: 0; }
.tenant-name { padding: 0 20px 12px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-box { display: flex; flex-direction: column; font-size: 12px; padding: 0 6px; }
.user-box strong { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .spacer { min-width: 8px; }
.impersonate-bar { background: var(--warning); color: #fff; padding: 8px 32px; display: flex; gap: 12px; align-items: center; font-weight: 500; }
[data-theme="dark"] .impersonate-bar { color: #111; }
.impersonate-bar button { background: rgba(255, 255, 255, .2); border: 1px solid rgba(255, 255, 255, .5); color: inherit; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 11px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 36px; padding: 0; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=url], select, textarea {
  min-height: 36px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); width: 100%;
}
input[type=color] { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.notice { font-size: 12px; color: var(--muted); margin-top: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters > * { width: auto; }
.filters input[type=search] { min-width: 220px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.s-nouveau { color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent); }
.s-qualifie { color: #7a5af8; background: color-mix(in srgb, #7a5af8 12%, transparent); }
.s-rdv_pris, .s-confirme { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.s-client, .s-realise { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.s-perdu, .s-annule { color: var(--muted); background: var(--surface-2); }
.s-absent { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.s-paused { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 11px; color: var(--muted); margin-right: 4px; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table th button { background: none; border: 0; padding: 0; cursor: pointer; font-weight: inherit; color: inherit; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list a.item-link { color: inherit; text-decoration: none; display: flex; gap: 12px; align-items: center; flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.date-box { width: 46px; text-align: center; flex: none; border: 1px solid var(--border); border-radius: 6px; padding: 2px 0; }
.date-box .d { font-size: 17px; font-weight: 650; line-height: 1.2; }
.date-box .m { font-size: 10px; text-transform: uppercase; color: var(--muted); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }
.loading { padding: 40px; display: grid; place-items: center; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); font-size: 13px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

/* Fenêtres modales (élément <dialog>) */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.secret { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--surface-2); border: 1px dashed var(--border); padding: 10px 12px; border-radius: 6px; word-break: break-all; user-select: all; }

/* Graphique */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 2 4; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: color-mix(in srgb, var(--accent) 35%, transparent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .dot { fill: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .l-bar { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.legend .l-line { background: var(--accent); height: 3px; vertical-align: 2px; }

/* Agenda semaine */
.week { display: grid; grid-template-columns: 56px repeat(7, minmax(92px, 1fr)); min-width: 700px; }
.week-head { position: sticky; top: 0; background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 8px; font-size: 12px; font-weight: 600; text-align: center; }
.week-head.today { color: var(--accent); }
.week-hours { position: relative; }
.week-hours div { height: 48px; font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.week-col { position: relative; border-left: 1px solid var(--border); }
.week-col .slot { height: 48px; border-bottom: 1px solid var(--border); }
.week-col.closed { background: repeating-linear-gradient(45deg, transparent, transparent 6px, var(--surface-2) 6px, var(--surface-2) 7px); }
.appt { position: absolute; left: 3px; right: 3px; border-radius: 5px; padding: 3px 6px; font-size: 11px; overflow: hidden; cursor: pointer; border: 0; text-align: left; border-left: 3px solid currentColor; }
.appt strong { display: block; font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt span { color: var(--text); opacity: .8; }

/* Conversations */
.messenger { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 120px); min-height: 480px; overflow: hidden; }
.conv-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.conv-list .search { padding: 12px; border-bottom: 1px solid var(--border); }
.conv-items { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 10px; padding: 12px; border: 0; border-bottom: 1px solid var(--border); background: none; width: 100%; text-align: left; cursor: pointer; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.conv-item .meta { flex: 1; min-width: 0; }
.conv-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.thread-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.day-sep { align-self: center; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; margin: 10px 0; }
.bubble { max-width: min(70%, 560px); padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.bubble .who { font-size: 11px; font-weight: 600; margin-bottom: 2px; opacity: .75; }
.bubble .time { font-size: 10px; opacity: .65; text-align: right; margin-top: 2px; }
.bubble.client { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.agent { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-bottom-right-radius: 4px; }
.bubble.humain { align-self: flex-end; background: color-mix(in srgb, var(--warning) 16%, var(--surface)); border-bottom-right-radius: 4px; }
.bubble .media { font-style: italic; opacity: .8; }
.back-link { display: none; }

/* Fiche contact */
.contact-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.score { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; width: 120px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.score span { display: block; height: 100%; background: var(--accent); }
.note { padding: 10px 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: 0; }
.note p { margin: 0 0 4px; white-space: pre-wrap; }

/* Paramètres */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.hours-day { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: start; }
.hours-ranges { display: flex; flex-direction: column; gap: 6px; }
.hours-ranges .row input { width: 120px; }

/* Pages d'accès (connexion, installation) */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); padding: 28px; }
.auth-card .brand { padding: 0 0 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { display: flex; gap: 12px; justify-content: center; margin-top: 16px; font-size: 12px; flex-wrap: wrap; }
.auth-foot a, .legal-links a { color: var(--muted); }
.auth-foot select, .sidebar-foot select { width: auto; min-width: 96px; min-height: 28px; font-size: 12px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.legal-links { display: flex; gap: 10px; font-size: 11px; padding: 0 6px; flex-wrap: wrap; }

/* Pages légales */
.legal { max-width: 760px; margin: 0 auto; padding: 40px 24px 64px; font-size: 15px; line-height: 1.65; }
.legal h1 { margin-bottom: 8px; }
.legal h2 { margin: 28px 0 8px; }
.legal .todo { background: color-mix(in srgb, var(--warning) 18%, transparent); padding: 0 4px; border-radius: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .contact-grid { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
  .topbar .brand { padding: 0; }
  .content { padding: 18px 14px 40px; }
  .impersonate-bar { padding: 8px 14px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .messenger { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 140px); }
  .messenger.has-thread .conv-list { display: none; }
  .messenger:not(.has-thread) .conv-thread { display: none; }
  .back-link { display: inline-flex; }
  .bubble { max-width: 88%; }
  .dl { grid-template-columns: 96px minmax(0, 1fr); }
  .hide-sm { display: none; }
  .filters input[type=search] { min-width: 0; flex: 1 1 100%; }
  .hours-day { grid-template-columns: minmax(0, 1fr); }
  .hours-ranges .row input { width: auto; flex: 1 1 0; min-width: 0; }
  .dl dd { overflow-wrap: anywhere; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* Menu de statut dans les tableaux : assez large pour « Confirmada », « Realizada »… */
select.status-select { width: auto; min-width: 128px; }
/* Pied de la barre latérale : langue sur sa propre ligne si la place manque */
.sidebar-foot .row { flex-wrap: wrap; }
.sidebar-foot select { flex: 1 1 100%; }
