:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-soft: #e8f8f1;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --info: #2563eb;
  --info-soft: #e8effe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a0e13;
  --surface: #111720;
  --surface-2: #181f2a;
  --border: #243040;
  --text: #e8eef5;
  --muted: #8a98ab;
  --primary: #10b981;
  --primary-hover: #34d399;
  --primary-soft: rgba(16, 185, 129, .13);
  --on-primary: #04130d;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .12);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, .13);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e13;
    --surface: #111720;
    --surface-2: #181f2a;
    --border: #243040;
    --text: #e8eef5;
    --muted: #8a98ab;
    --primary: #10b981;
    --primary-hover: #34d399;
    --primary-soft: rgba(16, 185, 129, .13);
    --on-primary: #04130d;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .13);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .12);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, .13);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 650; }
[hidden] { display: none !important; }
#root { min-height: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
.icon { display: inline-flex; flex: none; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 500; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon-only { width: 38px; padding: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--danger); }
.input { width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 42px; }
.input-wrap .toggle { position: absolute; right: 4px; top: 4px; }

.switch { position: relative; width: 44px; height: 26px; flex: none; border-radius: 999px; border: none; background: var(--border); transition: background .2s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch[disabled] { opacity: .5; cursor: not-allowed; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button { border: none; background: transparent; height: 32px; padding: 0 14px; border-radius: 8px; color: var(--muted); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--primary-soft); color: var(--primary); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-hero { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 48px 56px; color: #fff; background: radial-gradient(900px 500px at 10% -10%, rgba(255, 255, 255, .18), transparent 60%), radial-gradient(700px 500px at 100% 100%, rgba(20, 184, 166, .55), transparent 60%), linear-gradient(145deg, #064e3b, #059669 60%, #0d9488); }
.login-hero::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255, 255, 255, .13) 1px, transparent 1px); background-size: 22px 22px; mask-image: linear-gradient(180deg, transparent, #000 40%, transparent); pointer-events: none; }
.login-hero > * { position: relative; z-index: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary); color: #fff; }
.login-hero .brand .logo { background: rgba(255, 255, 255, .18); backdrop-filter: blur(6px); }
.hero-copy h1 { font-size: clamp(28px, 3.4vw, 42px); line-height: 1.12; letter-spacing: -.025em; font-weight: 700; max-width: 14em; }
.hero-copy p { margin-top: 14px; max-width: 30em; opacity: .85; font-size: 15px; }
.hero-points { margin: 28px 0 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.hero-points li { display: flex; gap: 12px; align-items: center; font-weight: 500; }
.hero-points .chip { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, .16); }
.login-hero small { opacity: .65; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 24px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 22px; }
.login-card h2 { font-size: 26px; letter-spacing: -.02em; }
.login-card form { display: grid; gap: 16px; }
.form-error { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100%; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--border); }
.sidebar .brand { padding: 4px 8px 6px; }
.nav { display: grid; gap: 3px; }
.nav-label { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 11px; height: 40px; padding: 0 11px; border-radius: 10px; color: var(--muted); font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--surface-2); min-width: 0; }
.avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 13px; color: var(--primary); background: var(--primary-soft); }
.user-chip .who { min-width: 0; line-height: 1.25; }
.user-chip .who b, .user-chip .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { font-size: 12px; color: var(--muted); }
.foot-actions { display: flex; gap: 8px; }
.foot-actions .btn { flex: 1; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 28px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.topbar .menu-btn { display: none; }
.page { width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px; display: grid; gap: 22px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 24px; letter-spacing: -.02em; }
.page-head p { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.back:hover { color: var(--text); }
.scrim { display: none; }

/* ---------- cards ---------- */
.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: 18px 20px 0; }
.card-head h3 { font-size: 15px; font-weight: 650; }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 18px 20px 20px; }
.card-body.flush { padding: 8px 0 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.stat { padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; }
.stat .chip { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.stat .chip.info { background: var(--info-soft); color: var(--info); }
.stat .chip.warn { background: var(--warn-soft); color: var(--warn); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value.sm { font-size: 18px; padding-top: 3px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.action-card { padding: 20px; display: grid; gap: 10px; transition: border-color .15s, transform .15s; }
.action-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.action-card .chip { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.action-card b { font-size: 15px; }
.action-card span { color: var(--muted); }
.action-card .more { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-weight: 500; margin-top: 4px; }

.row { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-top: 1px solid var(--border); }
.row:first-child { border-top: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row .lead { width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.row.link { cursor: pointer; transition: background .12s; }
.row.link:hover { background: var(--surface-2); }
.row.link:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.row.link:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; }
.search .icon { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search .input { padding-left: 38px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 10px 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--primary); border-color: var(--primary); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 20px; border-top: 1px solid var(--border); }
.setting:first-child { border-top: none; }
.setting b { display: block; font-weight: 600; }
.setting span { color: var(--muted); font-size: 13px; }
.form-row { display: flex; gap: 10px; }
.form-row .input { flex: 1; }
.kv { margin: 0; display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13px; padding: 12px 20px 16px 72px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; }
.waba-group + .waba-group { border-top: 1px solid var(--border); }
.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 11px; background: var(--info-soft); color: var(--info); font-size: 13px; }

/* ---------- states ---------- */
.empty { display: grid; place-items: center; gap: 10px; padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .chip { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); }
.empty b { color: var(--text); font-size: 15px; }
.skeleton { position: relative; overflow: hidden; border-radius: 10px; background: var(--surface-2); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 7%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 10px; max-width: calc(100vw - 36px); }
.toast { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); animation: rise .22s ease-out; }
.toast.bad { background: var(--danger); color: #fff; }
.toast .icon { color: var(--primary); }
.toast.bad .icon { color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- modal ---------- */
dialog.modal { width: min(460px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(8, 12, 18, .55); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-head h3 { font-size: 17px; letter-spacing: -.01em; }
.modal-head p { color: var(--muted); margin-top: 2px; }
.modal-body { padding: 18px 22px 22px; display: grid; gap: 18px; justify-items: center; }
.modal-body.form { justify-items: stretch; }
select.input { appearance: auto; }
.modal-body .segmented { justify-self: stretch; }
.modal-body .segmented button { flex: 1; justify-content: center; }
.pair-stage { width: 100%; min-height: 230px; display: grid; place-items: center; align-content: center; gap: 14px; text-align: center; }
.code-box { display: flex; gap: 10px; align-items: center; justify-content: center; }
.code-part { font-family: var(--mono); font-size: 34px; font-weight: 700; letter-spacing: .12em; padding: 12px 16px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.code-dash { color: var(--muted); font-size: 24px; }
.qr-img { width: 220px; height: 220px; border-radius: 14px; background: #fff; padding: 8px; border: 1px solid var(--border); image-rendering: pixelated; }
.timer { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.timer .bar { width: 90px; height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.timer .bar i { display: block; height: 100%; background: var(--primary); transition: width 1s linear; }
.steps { width: 100%; margin: 0; padding: 14px 16px 14px 34px; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: 13px; text-align: left; display: grid; gap: 4px; }
.steps b { color: var(--text); font-weight: 600; }
.state-icon { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.state-icon.bad { background: var(--danger-soft); color: var(--danger); }
.state-icon.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- responsive ---------- */
@media (max-width: 880px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { padding: 28px 24px 32px; gap: 28px; }
  .hero-points, .login-hero small { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; width: 272px; transform: translateX(-102%); visibility: hidden; transition: transform .22s ease, visibility .22s; }
  .app.nav-open .sidebar { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(8, 12, 18, .5); }
  .topbar { padding: 0 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .page { padding: 18px 16px 40px; }
  .kv { grid-template-columns: 1fr; padding-left: 20px; }
  .form-row { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
