/* Interface d'administration de l'IPBX : sobre et claire, mode sombre automatique.
   Pas de style en ligne (Content-Security-Policy) : tout est ici.
   Marque Nuvelys : violet #6D28D9, turquoise #0D9488, indigo nuit #1E1B4B, fond sombre #140F2E,
   gris #5F6B7A, police Montserrat (titres, menu, boutons). Contrastes vérifiés (WCAG AA) :
   texte blanc sur le violet, jamais sur le turquoise (3,7:1) ; les pastilles turquoise clair
   (#2DD4BF) portent un texte indigo nuit. */

@font-face { font-family: "Montserrat"; src: url("montserrat.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }

:root {
  --brand-violet: #6d28d9;
  --brand-teal: #0d9488;
  --brand-night: #1e1b4b;
  --font-head: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #f8f7fc;
  --border: #e3e1ef;
  --border-strong: #cdc9e0;
  --text: #1e1b4b;
  --muted: #5f6b7a;
  --accent: #6d28d9;
  --accent-hover: #5b21b6;
  --accent-weak: #f0e9fd;
  --on-accent: #ffffff;
  --ok: #067647;      --ok-bg: #ecfdf3;
  --warn: #a15c07;    --warn-bg: #fdf6e1;
  --danger: #c01048;  --danger-bg: #fff1f3;
  --off: #5f6b7a;     --off-bg: #eef0f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(30, 27, 75, .06);
  --sidebar: 236px;
  /* Menu latéral : indigo nuit, texte clair, entrée active marquée en turquoise. */
  --side-bg: #1e1b4b;
  --side-text: #ffffff;
  --side-muted: rgba(255, 255, 255, .74);
  --side-faint: rgba(255, 255, 255, .5);
  --side-hover: rgba(255, 255, 255, .08);
  --side-active: rgba(255, 255, 255, .12);
  --side-border: rgba(255, 255, 255, .12);
  --side-mark: #2dd4bf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #140f2e;
    --surface: #1c1640;
    --surface-2: #231c4d;
    --border: #2f2760;
    --border-strong: #403673;
    --text: #ece9f7;
    --muted: #a9a4c4;
    /* Violet clair, texte fond sombre : lisible sur fond sombre. */
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-weak: #2e2363;
    --on-accent: #140f2e;
    --ok: #4ade80;     --ok-bg: #102a1c;
    --warn: #fbbf24;   --warn-bg: #2d2610;
    --danger: #fb7185; --danger-bg: #331520;
    --off: #a9a4c4;    --off-bg: #261f52;
    --shadow: none;
    --side-bg: #0f0b24;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-family: var(--font-head); font-weight: 700; }
code { font: .85em ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; word-break: break-all; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- Structure : menu latéral + contenu ----------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--side-bg); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 2px 10px 16px; color: var(--side-text); }
.brand:hover { text-decoration: none; }
.logo { display: block; width: 172px; height: auto; }
.logo-mark { display: none; width: 46px; height: auto; }
.brand-sub { font-size: .78rem; font-weight: 500; color: var(--side-muted); line-height: 1.3; }
.brand-sub strong { color: var(--side-text); font-weight: 600; }
.nav-title { font-family: var(--font-head); font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--side-faint); padding: 14px 10px 4px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-muted); font-family: var(--font-head); font-size: .9rem; font-weight: 500; }
.nav-link:hover { background: var(--side-hover); color: var(--side-text); text-decoration: none; }
.nav-link.active { background: var(--side-active); color: var(--side-text); box-shadow: inset 3px 0 0 var(--side-mark); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--side-border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot form { margin: 0; }
.sidebar-foot button { width: 100%; }
.content { min-width: 0; padding: 28px 32px 48px; }
.content-inner { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; gap: 2px; }
  .brand { padding: 0 8px 0 0; }
  .brand .logo { display: none; }
  .brand .logo-mark { display: block; }
  .brand-sub, .nav-title { display: none; }
  .nav-link { white-space: nowrap; padding: 6px 9px; }
  .sidebar-foot { margin: 0; padding: 0; border: 0; flex-direction: row; }
  .sidebar-foot .nav-link span, .sidebar-foot button span { display: none; }
  .content { padding: 18px 16px 40px; }
}

/* --- En-tête de page ------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; font-weight: 700; }
.page-head .subtitle { color: var(--muted); margin: 6px 0 0; max-width: 680px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.crumb .icon { width: 15px; height: 15px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.title-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* --- Messages ------------------------------------------------------------------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); border: 1px solid transparent; }
.flash.notice { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.warning { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.flash.error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

/* --- Cartes ---------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 1rem; font-weight: 650; }
.card-head .desc { color: var(--muted); font-size: .875rem; margin: 2px 0 0; }
.card-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.card-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap; align-items: center; }
.card-foot .left { margin-right: auto; }
.card.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.card.danger-zone .card-head h2 { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }

/* --- Formulaires ----------------------------------------------------------------- */
form { margin: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
label, .label { font-size: .85rem; font-weight: 550; color: var(--text); }
.optional { color: var(--muted); font-weight: 400; }
.help { font-size: .8rem; color: var(--muted); margin: 0; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); }
input[type=file] { padding: 6px; }
input[type=time] { width: auto; padding: 5px 8px; min-height: 34px; }
textarea { resize: vertical; min-height: 76px; font-family: var(--mono, ui-monospace, monospace); font-size: .875rem; }
.card-head .badge { flex-shrink: 0; }
code.block { display: block; white-space: pre-wrap; word-break: break-all; }
.check { display: flex; gap: 9px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 3px; }
/* Choix exclusif présenté en cartes (type de standard). */
.choices { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.choices legend { padding: 0; margin-bottom: 6px; font-size: .85rem; font-weight: 550; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); font-weight: 400; cursor: pointer; }
.choice > span { display: flex; flex-direction: column; gap: 3px; }
.choice input { width: 16px; height: 16px; min-height: 0; margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); }
.choice:has(input:focus-visible) { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.when-auto { display: none; }
form:has(input[name=type][value=automatique]:checked) .when-auto { display: inline; }
form:has(input[name=type][value=automatique]:checked) .when-classic { display: none; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form > input, .inline-form > select { width: auto; flex: 1 1 160px; }
.toggle-form { display: inline; }

/* --- Boutons --------------------------------------------------------------------- */
button, .btn { font: inherit; font-family: var(--font-head); font-size: .9rem; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; min-height: 38px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn.secondary, button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover, button.secondary:hover { background: var(--surface-2); }
button.danger, .btn.danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
button.danger:hover { background: var(--danger-bg); }
button.solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
button.sm, .btn.sm { min-height: 30px; padding: 4px 10px; font-size: .85rem; }
button.icon-btn { min-height: 30px; width: 30px; padding: 0; background: transparent; border-color: var(--border); color: var(--muted); }
button.icon-btn:hover { background: var(--surface-2); color: var(--text); }
button.icon-btn .icon { width: 16px; height: 16px; }
.nav-link.as-button { width: 100%; background: transparent; border: 0; min-height: 0; justify-content: flex-start; color: var(--side-muted); font-weight: 500; }
.nav-link.as-button:hover { background: var(--side-hover); color: var(--side-text); }

/* --- Badges et états ------------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--off-bg); color: var(--off); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--accent-weak); color: var(--accent); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Tableaux et listes ------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { position: relative; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable a.row-link { color: var(--text); font-weight: 600; }
tr.clickable a.row-link::after { content: ""; position: absolute; inset: 0; }
td.end { text-align: right; color: var(--muted); width: 1%; white-space: nowrap; }
td.end .icon { width: 16px; height: 16px; }
.sub-line { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }

/* Listes ordonnées (membres, touches, numéros) */
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; }
.rows li { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows .pos { width: 26px; height: 26px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; font-size: .8rem; font-weight: 600; color: var(--muted); flex: none; }
.rows .grow { flex: 1; min-width: 0; }
.rows .acts { display: flex; gap: 4px; }
.rows .acts form { display: inline; }

/* Paires clé / valeur */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .875rem; }
dl.kv dd { margin: 0; min-width: 0; }

details > summary { cursor: pointer; color: var(--accent); font-weight: 550; }
details.reveal { display: inline-block; }
details.reveal > summary { font-weight: 500; }
details.guide { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
details.guide[open] > summary { margin-bottom: 8px; }
details.guide ol, details.guide ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

.empty { text-align: center; color: var(--muted); padding: 28px 20px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.empty strong { color: var(--text); }
.empty.compact { padding: 6px 0; text-align: left; align-items: flex-start; }

/* --- Tableau de bord --------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat .label { color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat .value small { font-size: 1rem; color: var(--muted); font-weight: 500; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* --- Pages spécifiques ------------------------------------------------------- */
table.schedule th, table.schedule td { padding: 8px 12px; }
table.schedule th[scope=row] { text-transform: none; font-size: .9rem; letter-spacing: 0; color: var(--text); background: transparent; }
.prompt { display: flex; flex-direction: column; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.prompt:first-child { padding-top: 0; }
.prompt:last-child { border-bottom: 0; padding-bottom: 0; }
.prompt audio { width: 100%; max-width: 420px; }
.state-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.state-banner.closed { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, var(--border)); color: var(--warn); }
.state-banner.active { background: var(--accent-weak); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }

/* Champs affichés selon le choix, sans JavaScript (:has) */
.when-ext, .key-field { display: none; }
form:has(select[name=fwd] option[value=ext]:checked) .when-ext { display: flex; }
form:has(select[name=new_kind] option[value=blf]:checked) .key-blf,
form:has(select[name=new_kind] option[value=closed]:checked) .key-closed,
form:has(select[name=new_kind] option[value=speed]:checked) .key-speed { display: flex; }
form:has(select[name=new_kind] option[value=forward]:checked) .key-fwd,
form:has(select[name=new_kind] option[value=forward]:checked):has(select[name=new_fwd] option[value=ext]:checked) .key-fwd-ext { display: flex; }
.mail-manual { display: none; }
form:has(#provider option[value="autre"]:checked) .mail-manual { display: grid; }

/* Connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.login-card .brand { padding: 0; }
.login-card .brand .brand-sub { color: var(--muted); }
.login-card .logo { width: 230px; }
/* Logo sur fond clair, ou version pour fond sombre en mode sombre. */
.logo-dark { display: none; }
@media (prefers-color-scheme: dark) { .login-card .logo-light { display: none; } .login-card .logo-dark { display: block; } }

/* Compléments */
.rows.flush { border: 0; border-radius: 0; }
.rows.flush li { padding: 11px 20px; }
.rows a { color: var(--text); }
a.stat { color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--border-strong); }
details > summary.card-head { list-style: none; border-bottom: 0; }
details > summary.card-head::-webkit-details-marker { display: none; }
details > summary.card-head h2::before { content: "+ "; color: var(--accent); }
details[open] > summary.card-head { border-bottom: 1px solid var(--border); }
details[open] > summary.card-head h2::before { content: "– "; }
.card-foot select, .card-foot input { width: auto; flex: 1 1 180px; }
.card-foot .left { margin-right: auto; }
h3.label { font-size: .9rem; }
td.end .inline-form { justify-content: flex-end; flex-wrap: nowrap; }
.card > .help { padding-top: 0; }

/* Deux colonnes empilées (page d'un poste) : pas de trous entre des cartes de hauteurs différentes. */
.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.columns > .col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1000px) { .columns, .grid-2 { grid-template-columns: 1fr; } }

/* Nom du client sous « IPBX » */
.plain-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; font-size: .875rem; }

/* Touches programmables : brouillon dans une seule forme. */
.card-body.stack, .key-add { display: flex; flex-direction: column; gap: 12px; }
.card-body.stack .flash { margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Application de bureau : code d'appairage, affiché une seule fois. */
.pair-code { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 12px 16px; margin-bottom: 16px; }
.pair-code p { margin: 0 0 8px; }
.pair-code .help { margin: 8px 0 0; }
.code-big { font-size: 1.4rem; letter-spacing: .12em; font-weight: 600; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.device-list li:first-child { border-top: 0; padding-top: 0; }
.device-list li > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.device-list .muted { font-size: .85rem; }

/* Photo de profil d'un poste (choisie dans l'application). */
.avatar-admin { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.avatar-admin img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar-admin span { flex: 1; font-size: .88rem; }

/* Droit de modifier l'annuaire (carte « Application de bureau » du poste). */
.editor-form { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Encadré d'information (page Annuaire : qui peut le modifier). */
.notice-box { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.notice-box p { margin: 0; }
.notice-box p + p { margin-top: 4px; }
