/* Interface type WhatsApp — thèmes clair & sombre ([data-theme] sur <html>), accent bleu. */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eff1f4;
  --border: #e2e6ec;
  --text: #14171c;
  --muted: #6a7280;
  --accent: #2563eb;
  --accent-strong: #1e50cf;
  --accent-soft: rgba(37, 99, 235, .08);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, .1);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, .1);
  --bad: #dc2626;
  --bad-soft: rgba(220, 38, 38, .1);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --chat-bg: #eef0f4;
  --bubble-in: #ffffff;
  --bubble-out: #dbe7ff;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #0c1319;
  --surface: #111b21;
  --surface-2: #1f2c34;
  --border: #222d35;
  --text: #e9edf0;
  --muted: #8696a0;
  --accent: #3b82f6;
  --accent-strong: #60a5fa;
  --accent-soft: rgba(59, 130, 246, .14);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, .14);
  --warn: #f5a623;
  --warn-soft: rgba(245, 166, 35, .14);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --chat-bg: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #0b2d63;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ============ shell ============ */
.wa-body { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: 100vh; overflow: hidden; }
@media (max-width: 860px) { .wa-body { grid-template-columns: 320px minmax(0, 1fr); } }
@media (max-width: 620px) { .wa-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 38vh) minmax(0, 1fr); } }

.wa-side { display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); min-height: 0; }
.wa-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.wa-view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.wa-view.active { display: flex; }

/* ============ sidebar : entête ============ */
.side-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.side-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-avatar, .avatar-lg { width: 40px; height: 40px; flex: none; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #fff; font-weight: 800; font-size: 17px; display: flex; align-items: center; justify-content: center; }
.side-title { font-weight: 800; letter-spacing: -.2px; line-height: 1.2; }
.side-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.side-sub .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.side-sub.ok { color: var(--ok); } .side-sub.ok .dot { background: var(--ok); }
.side-sub.warn { color: var(--warn); } .side-sub.warn .dot { background: var(--warn); }
.side-sub.bad { color: var(--bad); } .side-sub.bad .dot { background: var(--bad); }
.side-actions { margin-left: auto; display: flex; gap: 6px; }

.icon-btn { appearance: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; border: none; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ onglets ============ */
.wa-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); }
.watab { appearance: none; cursor: pointer; flex: 1; padding: 10px 4px; background: none; border: none; font-size: 13px; font-weight: 800; letter-spacing: .2px; color: var(--muted); border-bottom: 2px solid transparent; }
.watab.active { color: var(--accent); border-bottom-color: var(--accent); }
.wa-tabpane { display: none; flex: 1; flex-direction: column; min-height: 0; }
.wa-tabpane.active { display: flex; }

/* ============ liste des discussions ============ */
.side-search { padding: 8px 10px; background: var(--surface); }
.side-search input { border-radius: 999px; background: var(--surface-2); border: none; padding: 8px 14px; }
.side-search input:focus { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.new-chat { appearance: none; cursor: pointer; margin: 2px 10px 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 12.5px; font-weight: 700; }
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.new-chat-row { display: flex; gap: 6px; padding: 0 10px 8px; }
.chat-list { flex: 1; overflow-y: auto; padding-bottom: 12px; }

.chat-row { display: flex; gap: 10px; align-items: center; padding: 7px 12px; cursor: pointer; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.active { background: var(--accent-soft); }
.chat-avatar { width: 44px; height: 44px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; }
.chat-mid { flex: 1; min-width: 0; border-bottom: 1px solid var(--border); padding: 6px 0; }
.chat-row.active .chat-mid, .chat-row:hover .chat-mid { border-bottom-color: transparent; }
.chat-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { color: var(--muted); font-size: 12.8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-side { flex: none; text-align: right; padding: 6px 0; }
.chat-time { font-size: 11.5px; color: var(--muted); }

/* ============ onglet statuts (liste) ============ */
.status-strip { padding: 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.my-status { display: flex; gap: 14px; align-items: center; background: none; border: none; cursor: pointer; padding: 4px; width: 100%; text-align: left; color: var(--text); }
.ring { position: relative; display: inline-block; flex: none; }
.ring .avatar-lg { width: 48px; height: 48px; }
.ring-plus { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface); }
.my-status-txt { font-size: 13px; text-align: left; }
.my-status-txt small { color: var(--muted); }
.list-label { padding: 12px 14px 6px; font-size: 11.5px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
.svc-list, .set-list { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.svc-row { display: flex; gap: 12px; align-items: center; padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.svc-row:last-child { border-bottom: none; }
.svc-row:hover { background: var(--surface-2); }
.svc-ico { width: 38px; height: 38px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; background: var(--surface-2); border: 1px solid var(--border); }
.svc-name { font-weight: 700; font-size: 14px; }
.svc-desc { color: var(--muted); font-size: 12.3px; }
.svc-state { margin-left: auto; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.svc-state.ok { background: var(--ok); }
.svc-state.warn { background: var(--warn); }
.svc-state.bad { background: var(--bad); }
.svc-state.off { background: var(--muted); }

/* ============ onglet paramètres (liste) ============ */
.set-row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row:hover { background: var(--surface-2); }
.set-row .set-ico { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 16px; flex: none; }
.set-row .set-name { font-weight: 700; }
.set-row .set-desc { color: var(--muted); font-size: 12.3px; }
.set-row .chev { margin-left: auto; color: var(--muted); }

/* ============ panneau discussion ============ */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.convo-id { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.convo-avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; }
.convo-name { font-weight: 800; font-size: 15.5px; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-meta { font-size: 12.3px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-actions { display: flex; align-items: center; gap: 8px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.chat-body { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.chat-bg { position: absolute; inset: 0; pointer-events: none; opacity: .55; background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 22px 22px; }
.empty-screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 24px; }
.empty-ico { font-size: 44px; opacity: .7; }
.empty-title { font-weight: 800; font-size: 21px; letter-spacing: -.4px; }
.empty-txt { color: var(--muted); max-width: 430px; font-size: 13.5px; }
.msg-scroll { position: absolute; inset: 0; overflow-y: auto; padding: 22px 7% 14px; }
.msg-date { text-align: center; margin: 4px 0 14px; }
.msg-date span { background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 600; padding: 2px 12px; border-radius: 999px; }

.bubble-row { display: flex; margin: 2px 0; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.in { justify-content: flex-start; }
.bubble { position: relative; max-width: min(560px, 78%); padding: 6px 9px 7px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; word-break: break-word; }
.bubble.out { background: var(--bubble-out); }
.bubble.in { background: var(--bubble-in); }
.bubble-row.in .bubble { border-top-left-radius: 2px; }
.bubble-row.out .bubble { border-top-right-radius: 2px; }
.bubble .b-sender { font-size: 12.5px; font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.bubble .b-text { white-space: pre-wrap; }
.bubble .b-meta { display: flex; align-items: baseline; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.bubble .b-time { font-size: 11px; color: var(--muted); }
.bubble .b-arrow { font-size: 11px; }
.bubble.kind-media .b-kind { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 4px 0 2px; }
.quote-inline { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 3px 8px; margin: 2px 0 6px; border-radius: 4px; font-size: 12.5px; color: var(--muted); }
.quote-inline b { color: var(--accent); }
.msg-reply { position: absolute; top: -20px; right: 4px; font-size: 15px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); cursor: pointer; border-radius: 50%; width: 26px; height: 26px; opacity: 0; box-shadow: var(--shadow); }
.bubble-row:hover .msg-reply { opacity: 1; }
.msg-reply:hover { color: var(--accent); border-color: var(--accent); }

/* ============ zone de saisie ============ */
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 12px; }
.quote-bar { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-left: 4px solid var(--accent); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; }
.quote-bar > div { flex: 1; min-width: 0; }
.quote-bar b { display: block; color: var(--accent); font-size: 12px; }
.quote-bar span { color: var(--muted); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-panel { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.attach-panel input { padding: 7px 10px; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea { flex: 1; resize: none; max-height: 130px; border-radius: 999px; padding: 10px 16px; }
.send-btn { appearance: none; cursor: pointer; width: 42px; height: 42px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; border: none; font-size: 17px; }
.send-btn:hover { background: var(--accent-strong); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ pages statuts / paramètres ============ */
.page-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.page-title { font-size: 17px; font-weight: 800; letter-spacing: -.3px; }
.page-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 40px; max-width: 1080px; width: 100%; margin: 0 auto; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 12px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.panel h2 .spacer { flex: 1; }
.panel p.sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.status-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 13.5px; }
.status-grid dt { color: var(--muted); }
.status-grid dd { margin: 0; font-weight: 600; word-break: break-all; }
.big-state { font-size: 18px; font-weight: 800; }

.set-group { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; overflow: hidden; box-shadow: var(--shadow); }
.set-group summary { cursor: pointer; list-style: none; padding: 14px 16px; font-weight: 800; font-size: 14.5px; display: flex; align-items: center; gap: 10px; }
.set-group summary::-webkit-details-marker { display: none; }
.set-group summary::after { content: '▸'; margin-left: auto; color: var(--muted); transition: transform .15s; }
.set-group[open] summary::after { transform: rotate(90deg); }
.set-body { padding: 2px 16px 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.set-links { display: flex; gap: 8px; flex-wrap: wrap; }
.sub-note { font-size: 12px; color: var(--muted); margin-left: 8px; }

/* ============ composants génériques ============ */
.btn { appearance: none; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 8px; font-size: 13px; font-weight: 700; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: transparent; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 7px; }

input, select, textarea { width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; font-size: 13.5px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; gap: 8px; align-items: flex-end; }
.inline .grow { flex: 1; }
label.field { display: block; margin-bottom: 11px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 700; }
.meter { font-size: 12.8px; color: var(--muted); }
.meter b { color: var(--text); }
.meter .used-warn { color: var(--warn); font-weight: 800; }

.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 999px; }
.badge.in { background: var(--ok-soft); color: var(--ok); }
.badge.out { background: var(--accent-soft); color: var(--accent); }
.banner { padding: 9px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.banner.online { border-color: transparent; background: var(--ok-soft); color: var(--ok); }
.banner.offline { border-color: transparent; background: var(--warn-soft); color: var(--warn); }

.winrow { display: grid; grid-template-columns: 96px 96px 1fr 30px; gap: 8px; align-items: center; margin-bottom: 8px; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.daybtn { width: 33px; height: 29px; border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 6px; font-size: 11px; font-weight: 800; cursor: pointer; }
.daybtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.win-del { background: none; border: none; color: var(--bad); cursor: pointer; font-size: 15px; padding: 0 4px; }

.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.qr-box img { width: 250px; height: 250px; border-radius: 6px; image-rendering: pixelated; }
.qr-hint { color: #475569; font-size: 12.5px; text-align: center; max-width: 280px; }
.qr-placeholder { width: 250px; height: 250px; display: flex; align-items: center; justify-content: center; color: #64748b; text-align: center; padding: 16px; font-size: 13.5px; }
.pair-code { font-size: 25px; font-weight: 800; letter-spacing: 5px; text-align: center; padding: 13px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-family: ui-monospace, Menlo, monospace; }

#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 10px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); font-size: 13.5px; animation: slide .18s ease; max-width: 540px; }
.toast.error { border-color: var(--bad); color: var(--bad); }
.toast.success { border-color: var(--ok); color: var(--ok); }
@keyframes slide { from { transform: translateY(-6px); opacity: 0; } }

.empty { color: var(--muted); text-align: center; padding: 22px 10px; font-size: 13px; }
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: rot .7s linear infinite; vertical-align: -2px; }
@keyframes rot { to { transform: rotate(360deg); } }
details.help { margin-top: 6px; color: var(--muted); font-size: 13px; }
details.help summary { cursor: pointer; font-weight: 700; }
details.help code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ============ rareté : l'attribut hidden doit toujours gagner ============ */
[hidden] { display: none !important; }

/* ============ page de connexion ============ */
.login-body {
  min-height: 100vh; position: relative;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 400px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 12px; }
.login-logo .mark {
  width: 36px; height: 36px; flex: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 18px;
}
.login-card h1 { margin: 0; font-size: 20px; letter-spacing: -.3px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }
.login-card .err { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }
.theme-corner { position: absolute; top: 16px; right: 16px; }
