/* SAWKI WebSMS : Middleware SMS (thèmes clair et sombre) */
:root {
  --blue: #0389cf;
  --blue-dark: #0270aa;
  --navy: #0b3a5b;
  --ink: #1a2b3c;
  --muted: #64768a;
  --line: #e2e9f0;
  --bg: #f3f7fb;
  --tint: #eaf4fb;
  --card: #ffffff;
  --green: #2f8f4e;
  --green-bg: #e7f5ec;
  --amber: #b86a0c;
  --amber-bg: #fdf1e1;
  --red: #c93c3c;
  --red-bg: #fbe9e9;
  --grey-bg: #eef1f4;
  --surface: #ffffff;
  --input-line: #cfdbe6;
  --row-hover: #f8fbfd;
  --on-accent: #ffffff;
  --flash-ok-line: #c8e8d3;
  --flash-bad-line: #f2caca;
  --flash-warn-line: #f5d9b4;
  --wait-dot: #e0a43a;
  --logo-bg: transparent;
  color-scheme: light;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 58, 91, .06), 0 4px 14px rgba(11, 58, 91, .05);
  --sidebar: 248px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
}
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--navy); line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em; }
small, .muted { color: var(--muted); }

/* Structure */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh;
  background: linear-gradient(to right, var(--surface) calc(var(--sidebar) - 1px), var(--line) calc(var(--sidebar) - 1px), var(--line) var(--sidebar), var(--bg) var(--sidebar)); }
.sidebar {
  background: var(--surface); padding: 18px 14px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand img { width: 64px; height: auto; }
.brand-text strong { display: block; color: var(--navy); font-size: 1rem; }
.brand-text span { color: var(--muted); font-size: .8rem; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 14px 10px 4px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--ink); font-weight: 500; }
.nav a:hover { background: var(--tint); text-decoration: none; }
.nav a.active { background: var(--blue); color: var(--on-accent); }
.nav a.active svg { color: var(--on-accent); }
.nav svg { width: 18px; height: 18px; color: var(--blue); flex: none; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding: 14px 8px 0; font-size: .75rem; color: var(--muted);
  border-top: 1px solid var(--line); }
.sidebar-foot img { width: 96px; display: block; margin-bottom: 6px; opacity: .9; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .title { font-weight: 600; color: var(--navy); }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--tint); color: var(--blue-dark);
  display: grid; place-items: center; font-weight: 700; }
.menu-toggle { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--navy); }
.menu-toggle svg { width: 22px; height: 22px; display: block; }
.content { padding: 24px 28px 40px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .lead { color: var(--muted); margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Cartes et grilles */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 18px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.grid-2 { align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.9rem; font-weight: 700; color: var(--navy); line-height: 1.2; }
.kpi .sub { font-size: .8rem; color: var(--muted); }
.kpi.accent { background: var(--blue); border-color: var(--blue); }
.kpi.accent .label, .kpi.accent .sub, .kpi.accent .value { color: var(--on-accent); }
.kpi.warn .value { color: var(--red); }

/* Graphique en barres */
.bars { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 6px; align-items: end; height: 220px;
  padding-top: 8px; }
.bar-col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 42%; border-radius: 4px 4px 0 0; min-height: 2px; background: var(--blue); }
.bar.sent { background: var(--navy); opacity: .55; }
.bar-label { font-size: .7rem; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--row-hover); }
td.content-cell { max-width: 420px; word-break: break-word; }
.nowrap { white-space: nowrap; }

/* Pastilles */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--grey-bg); color: var(--muted); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.wait { background: var(--amber-bg); color: var(--amber); }
.pill.info { background: var(--tint); color: var(--blue-dark); }
.pill.bad { background: var(--red-bg); color: var(--red); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--tint); color: var(--navy);
  font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: var(--on-accent);
  font-size: .72rem; display: inline-grid; place-items: center; font-weight: 700; }

/* Boutons et formulaires */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--navy); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
  font-size: .9rem; white-space: nowrap; }
.btn:hover { border-color: var(--blue); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--on-accent); }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.btn svg { width: 16px; height: 16px; }
form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; color: var(--navy); }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.field .error, .errorlist { color: var(--red); font-size: .82rem; margin: 4px 0 0; padding: 0; list-style: none; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=search],
input[type=date], input[type=datetime-local], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--input-line); border-radius: 9px; font: inherit; background: var(--surface); color: var(--ink);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(3, 137, 207, .25); border-color: var(--blue); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 4px; width: 16px; height: 16px; }
.check label { font-weight: 500; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .f { min-width: 150px; }
.filters .f.grow { flex: 1; min-width: 220px; }
.filters label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

/* Messages flash */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; border: 1px solid; }
.flash.success { background: var(--green-bg); color: var(--green); border-color: var(--flash-ok-line); }
.flash.error { background: var(--red-bg); color: var(--red); border-color: var(--flash-bad-line); }
.flash.warning, .flash.info { background: var(--amber-bg); color: var(--amber); border-color: var(--flash-warn-line); }

/* Divers */
.kv { display: grid; grid-template-columns: 190px 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.sms { background: var(--tint); border-radius: 14px 14px 14px 4px; padding: 12px 14px; font-family: ui-monospace,
  Consolas, monospace; font-size: .9rem; word-break: break-all; color: var(--navy); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--blue); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.status-line { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.status-line:last-child { border-bottom: 0; }
.status-line .name { font-weight: 600; }
.status-line .when { margin-left: auto; font-size: .82rem; color: var(--muted); text-align: right; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--green); } .dot.bad { background: var(--red); } .dot.wait { background: var(--wait-dot); }
.status-line .when .pill { font-size: .72rem; padding: 1px 8px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: .88rem; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.note { background: var(--tint); border-radius: 10px; padding: 12px 14px; font-size: .88rem; color: var(--navy); }
.plan-step { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.plan-step:last-child { border-bottom: 0; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.examples button { font-size: .8rem; }
.flow-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.flow-row:last-child { border-bottom: 0; }

/* Pages d'authentification */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.auth-side { background: var(--blue); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .logo-card { background: #fff; border-radius: 18px; padding: 18px 22px; width: fit-content; }
.auth-side .logo-card img { width: 170px; display: block; }
.auth-side h1 { color: #fff; font-size: 2.1rem; margin-top: 28px; }
.auth-side p { color: #e3f2fb; max-width: 440px; font-size: 1.02rem; }
.auth-side .partners { display: flex; align-items: center; gap: 14px; font-size: .82rem; color: #d5ebf8; }
.auth-side .partners img { height: 56px; background: #fff; border-radius: 12px; padding: 6px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 1.4rem; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; }
.qr { display: flex; justify-content: center; padding: 10px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; margin: 12px 0; }
.qr svg { width: 200px; height: 200px; }

.error-page { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.error-page .code { font-size: 4rem; font-weight: 800; color: var(--blue); }

@media (max-width: 1100px) {
  .grid-main, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); background: var(--bg); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar); z-index: 20; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: block; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 32px; }
  .grid-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .bar-label { font-size: .55rem; }
  .bars { gap: 3px; }
  .page-head .actions { margin-left: 0; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 20px; }
  .auth-side h1 { font-size: 1.5rem; }
  .kv { grid-template-columns: 1fr; }
  .user-chip .who { display: none; }
}

/* v1.2 : projets, numéros courts */
.project-switch { display: flex; align-items: center; gap: 8px; }
.project-switch label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.project-switch select { min-width: 180px; padding: 6px 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 6px 0; }
.check-item { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; }
.check-item input { width: 16px; height: 16px; margin: 0; }
.sc-list { display: flex; flex-wrap: wrap; gap: 6px; }
.project-row h2 { margin: 0; }
.project-row .meta { color: var(--muted); font-size: .85rem; }
@media (max-width: 760px) {
  .project-switch label { display: none; }
  .project-switch select { min-width: 0; max-width: 140px; }
}
.kv.stack { grid-template-columns: 1fr; gap: 2px; }
.kv.stack dt { margin-top: 10px; font-size: .82rem; }
.kv.stack dt:first-child { margin-top: 0; }
.secret input { flex: 1; min-width: 0; }
.field .check-item { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; }

/* ---------------------------------------------------------------------------
   Thème sombre : choisi explicitement, ou « système » quand l'OS est en sombre
   --------------------------------------------------------------------------- */
:root[data-theme="dark"] {
  --blue: #2b96dc;
  --blue-dark: #7cc4f0;
  --navy: #e3edf6;
  --ink: #d6e1eb;
  --muted: #8ea3b6;
  --line: #263646;
  --bg: #0e1822;
  --tint: #16314a;
  --card: #15212d;
  --surface: #15212d;
  --green: #5cc27f;
  --green-bg: #15301f;
  --amber: #e8a548;
  --amber-bg: #36260f;
  --red: #f07777;
  --red-bg: #3a191b;
  --grey-bg: #1d2a37;
  --input-line: #314457;
  --row-hover: #1a2836;
  --flash-ok-line: #24533a;
  --flash-bad-line: #5c2a2d;
  --flash-warn-line: #5b4119;
  --wait-dot: #e8a548;
  --logo-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --blue: #2b96dc;
    --blue-dark: #7cc4f0;
    --navy: #e3edf6;
    --ink: #d6e1eb;
    --muted: #8ea3b6;
    --line: #263646;
    --bg: #0e1822;
    --tint: #16314a;
    --card: #15212d;
    --surface: #15212d;
    --green: #5cc27f;
    --green-bg: #15301f;
    --amber: #e8a548;
    --amber-bg: #36260f;
    --red: #f07777;
    --red-bg: #3a191b;
    --grey-bg: #1d2a37;
    --input-line: #314457;
    --row-hover: #1a2836;
    --flash-ok-line: #24533a;
    --flash-bad-line: #5c2a2d;
    --flash-warn-line: #5b4119;
    --wait-dot: #e8a548;
    --logo-bg: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
.brand img, .sidebar-foot img { background: var(--logo-bg); border-radius: 8px; padding: 2px; }
.qr { background: #ffffff; }
.bar.sent { background: var(--navy); }

/* Préférences : langue et thème */
.prefs { display: flex; align-items: center; gap: 6px; }
.prefs form { margin: 0; }
.pref-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 36px; height: 34px;
  padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; }
.pref-btn:hover { border-color: var(--blue); color: var(--blue-dark); }
.pref-btn svg { width: 17px; height: 17px; }
.auth-prefs { position: absolute; top: 18px; right: 18px; }
.auth-form { position: relative; }
@media (max-width: 760px) { .prefs .pref-btn span { display: none; } }
