:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --key: #f1f2f4;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2a2e36;
    --key: #22262e;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.ico { width: 22px; height: 22px; flex: none; }
code { font-size: .9em; }

/* --- structure --- */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--card);
}
.top a { text-decoration: none; color: inherit; }
.top .muted { color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-right: auto; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a.active { background: var(--key); color: var(--text); }
.who { font-size: 14px; }
@media (max-width: 760px) { .brand .mono, .who { display: none; } .top { gap: 10px; padding: 12px 14px; } }
.brand .ico { color: var(--accent); }
.brand .muted { font-weight: 400; }

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status[data-state="ready"] .dot { background: var(--green); }
.status[data-state="busy"] .dot { background: var(--red); }
.status[data-state="connecting"] .dot { background: var(--amber); }

.grid {
  display: grid; grid-template-columns: 340px 1fr; gap: 20px;
  max-width: 1040px; margin: 24px auto; padding: 0 20px; align-items: start;
}
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.flash { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; }
.flash.error { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.flash.ok { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.flash.wide { max-width: 1000px; margin: 16px auto 0; }
.flash a { color: inherit; font-weight: 600; }
.small { font-size: 13px; }

/* --- boutons --- */
.btn {
  border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600;
  background: var(--key);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.success { background: var(--green); color: #fff; }
.btn.danger { background: var(--red); color: #fff; }

.round {
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--key); transition: transform .08s, filter .15s;
}
.round:active { transform: scale(.94); }
.round:hover { filter: brightness(1.06); }
.round.call { background: var(--green); color: #fff; }
.round.hangup { background: var(--red); color: #fff; }
.round.ghost { background: transparent; color: var(--muted); }
.round.ghost.on { background: var(--red); color: #fff; }
.round.small { width: 38px; height: 38px; }
.round.small .ico { width: 18px; height: 18px; }

.link {
  background: none; border: 0; padding: 0; color: var(--accent);
  text-decoration: none; font-size: 13px;
}
.link.danger { color: var(--red); }

/* --- téléphone --- */
.activate { text-align: center; padding: 4px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.activate p { margin: 0 0 12px; color: var(--muted); }

#number {
  width: 100%; border: 0; border-bottom: 2px solid var(--line); background: transparent;
  font-size: 26px; text-align: center; padding: 8px 4px; color: var(--text); outline: none;
  font-variant-numeric: tabular-nums;
}
#number:focus { border-color: var(--accent); }

.call-info { text-align: center; padding: 4px 0 8px; }
.call-info .peer { font-size: 24px; font-weight: 600; }
.call-info .timer { font-size: 18px; margin-top: 4px; }
.call-info .dtmf { min-height: 1.4em; color: var(--muted); letter-spacing: 2px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 8px; }
.keypad button {
  aspect-ratio: 1.35; border: 0; border-radius: 14px; background: var(--key);
  font-size: 24px; font-weight: 500; display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1; transition: transform .06s;
}
.keypad button:active { transform: scale(.95); }
.keypad small { font-size: 9px; letter-spacing: 1.5px; color: var(--muted); font-weight: 600; }

.actions { display: flex; justify-content: center; align-items: center; gap: 22px; }

/* --- listes --- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: -6px -6px 8px; padding: 0 0 8px; }
.tabs button {
  border: 0; background: none; padding: 8px 14px; border-radius: 10px; color: var(--muted); font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
}
.tabs button.active { background: var(--key); color: var(--text); }
.badge {
  background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; min-width: 20px;
  text-align: center;
}

.list { list-style: none; margin: 0; padding: 0; }
.item { padding: 14px 4px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.item-head .muted { font-size: 13px; margin-left: auto; }
.item audio { width: 100%; margin: 10px 0 6px; height: 36px; }
.item-actions { display: flex; gap: 16px; }
.dot-unread { width: 8px; height: 8px; border-radius: 50%; background: transparent; align-self: center; }
.vm.unread .dot-unread { background: var(--accent); }
.vm.unread strong { color: var(--accent); }

.item.call { display: flex; align-items: center; gap: 14px; }
.item.call .grow { flex: 1; min-width: 0; }
.item.call .muted { font-size: 13px; }
.item.call .dir { font-size: 18px; width: 22px; text-align: center; color: var(--green); }
.item.call.bad .dir, .item.call.bad strong { color: var(--red); }

.empty { color: var(--muted); text-align: center; padding: 30px 0; margin: 0; }

/* --- appel entrant --- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.incoming { width: min(360px, 92vw); text-align: center; display: grid; gap: 10px; padding: 28px; }
.incoming h2 { margin: 0; font-size: 26px; }
.incoming p { margin: 0; }
.incoming .row { display: flex; gap: 12px; justify-content: center; margin: 10px 0 4px; }
.incoming .row .btn { flex: 1; padding: 14px; }
.pulse {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 6px; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center; animation: pulse 1.2s infinite;
}
.pulse .ico { width: 32px; height: 32px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); }
  100% { box-shadow: 0 0 0 22px transparent; }
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 10px; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}

/* --- formulaires --- */
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input:not([type="checkbox"]), select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit;
  font-weight: 400; background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); font-size: 14px; }
.suffix, .prefix { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
.form { display: grid; gap: 14px; }
.fields { display: grid; gap: 14px; }
.fields.two { grid-template-columns: repeat(2, 1fr); }
.fields.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .fields.two, .fields.three { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.hint { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
details.hint { margin: 0; }
details summary { cursor: pointer; }
details ul { padding-left: 18px; line-height: 1.9; }

/* --- connexion --- */
.login-page { display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: min(400px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; }

/* --- réglages --- */
.settings {
  display: grid; grid-template-columns: 190px 1fr; gap: 24px;
  max-width: 1000px; margin: 24px auto; padding: 0 20px; align-items: start;
}
.settings-nav { position: sticky; top: 20px; display: grid; gap: 2px; }
.settings-nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.settings-nav a:hover { background: var(--key); color: var(--text); }
.settings-main { display: grid; gap: 18px; min-width: 0; }
.settings-main > .muted { margin: 0; }
.settings .card { scroll-margin-top: 20px; }
.settings h2 { margin: 0 0 16px; font-size: 18px; }
.settings h3 { margin: 22px 0 12px; font-size: 15px; }
@media (max-width: 760px) { .settings { grid-template-columns: 1fr; } .settings-nav { position: static; display: flex; flex-wrap: wrap; } }

table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.users th, table.users td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
table.users td.right { text-align: right; }
table.users form { margin: 0; }
