/* ==========================================================================
   WhatsApp OTP Gateway — Admin Console
   Design language: operations-console. Monospace-forward type for data,
   status and navigation; humanist sans for prose. Signature element is the
   live "signal" pulse indicator that mirrors the WhatsApp connection state.
   ========================================================================== */

:root {
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Consolas, "Roboto Mono", monospace;
  --font-sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius-sm: 4px;
  --radius-md: 7px;
  --radius-lg: 10px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --accent: #e3ab4c;
  --accent-strong: #efc067;
  --accent-ink: #171208;

  --ok: #3ecf8e;
  --warn: #e3ab4c;
  --err: #e2664d;
  --neutral-signal: #6b7972;

  --sidebar-w: 232px;
  --header-h: 60px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35);
  --transition-fast: 120ms ease;
  --transition-med: 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

html[data-theme="dark"] {
  --bg: #0e1310;
  --bg-raised: #131a16;
  --surface: #171f1a;
  --surface-2: #1c2520;
  --border: #263129;
  --border-strong: #334137;
  --text: #eaf2ed;
  --text-dim: #a9b8ae;
  --text-faint: #708078;
  --overlay: rgba(6, 9, 7, 0.65);
}

html[data-theme="light"] {
  --bg: #f6f4ee;
  --bg-raised: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --border: #e1ddd0;
  --border-strong: #cfc9b7;
  --text: #16201a;
  --text-dim: #4d5a51;
  --text-faint: #7c8a80;
  --overlay: rgba(20, 24, 20, 0.4);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-2);
  color: var(--text);
}
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }

p { margin: 0 0 var(--space-3); color: var(--text-dim); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono { font-family: var(--font-mono); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------------------------------------------- */
/* App shell                                                               */
/* ---------------------------------------------------------------------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

.brand-name { font-family: var(--font-mono); font-size: 13px; font-weight: 600; line-height: 1.2; }
.brand-sub { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); letter-spacing: 0.04em; }

.sidebar-signal {
  margin: var(--space-3) var(--space-4);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-signal .signal-label { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.sidebar-signal .signal-state { font-family: var(--font-mono); font-size: 12px; font-weight: 600; }

.nav { flex: 1; padding: var(--space-2) var(--space-3); overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-item:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--accent); border: 1px solid var(--border-strong); }
.nav-item .nav-ico { width: 16px; text-align: center; opacity: 0.85; }

.nav-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-3) var(--space-3) var(--space-1);
}

.sidebar-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.topbar-title { font-family: var(--font-mono); font-size: 14px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.content { padding: var(--space-5); max-width: 1180px; width: 100%; margin: 0 auto; }

.mobile-menu-btn { display: none; }

/* ---------------------------------------------------------------------- */
/* Signal pulse — signature element                                       */
/* ---------------------------------------------------------------------- */

.pulse-dot {
  position: relative;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--neutral-signal);
  flex-shrink: 0;
}
.pulse-dot::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0;
}
.pulse-dot[data-signal="ready"] { background: var(--ok); color: var(--ok); }
.pulse-dot[data-signal="ready"]::after { animation: pulse-ring 2.2s ease-out infinite; }
.pulse-dot[data-signal="pending"],
.pulse-dot[data-signal="reconnecting"],
.pulse-dot[data-signal="loading"],
.pulse-dot[data-signal="initializing"] { background: var(--warn); color: var(--warn); }
.pulse-dot[data-signal="pending"]::after,
.pulse-dot[data-signal="reconnecting"]::after,
.pulse-dot[data-signal="loading"]::after,
.pulse-dot[data-signal="initializing"]::after { animation: pulse-ring 1.1s ease-out infinite; }
.pulse-dot[data-signal="error"] { background: var(--err); color: var(--err); }

@keyframes pulse-ring {
  0% { opacity: 0.55; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(1.8); }
}

.pulse-dot.lg { width: 16px; height: 16px; }
.pulse-dot.lg::after { inset: -10px; border-width: 2px; }

/* ---------------------------------------------------------------------- */
/* Cards / widgets                                                        */
/* ---------------------------------------------------------------------- */

.grid { display: grid; gap: var(--space-4); }
.grid-widgets { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }

@media (max-width: 980px) {
  .grid-widgets { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .grid-widgets { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.widget-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: var(--space-2);
}
.widget-value { font-family: var(--font-mono); font-size: 26px; font-weight: 700; }
.widget-sub { font-size: 12px; color: var(--text-faint); margin-top: var(--space-1); }
.widget-value.ok { color: var(--ok); }
.widget-value.warn { color: var(--warn); }
.widget-value.err { color: var(--err); }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.btn {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-danger { border-color: var(--err); color: var(--err); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { border-color: var(--border-strong); }

.btn-sm { padding: 6px 10px; font-size: 11.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; justify-content: center; }

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */

.field { margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: var(--space-2);
}
.field-hint { font-size: 12px; color: var(--text-faint); margin-top: var(--space-1); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="datetime-local"], select, textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  transition: border-color var(--transition-fast);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { resize: vertical; min-height: 72px; }

.checkbox-row { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; color: var(--text-dim); }
.checkbox-row input { width: auto; }

.input-copy { display: flex; gap: var(--space-2); }
.input-copy input { font-family: var(--font-mono); }

/* ---------------------------------------------------------------------- */
/* Badges / status pills                                                  */
/* ---------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  text-transform: uppercase;
  white-space: nowrap;
}
.badge::before { content: "▸"; opacity: 0.7; font-size: 9px; }
.badge-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border-strong)); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--border-strong)); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge-err { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border-strong)); background: color-mix(in srgb, var(--err) 10%, transparent); }
.badge-neutral { color: var(--text-dim); }

/* ---------------------------------------------------------------------- */
/* Tables                                                                  */
/* ---------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: var(--space-3) var(--space-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: var(--space-3); border-bottom: 1px solid var(--border); color: var(--text-dim); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
td.mono, th.mono { font-family: var(--font-mono); }
.table-empty { padding: var(--space-7) var(--space-4); text-align: center; color: var(--text-faint); }

.toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar .spacer { flex: 1; }
.toolbar select, .toolbar input { width: auto; min-width: 140px; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-4); font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); }

/* ---------------------------------------------------------------------- */
/* Login page                                                             */
/* ---------------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background:
    radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 45%),
    var(--bg);
}

.login-card { width: 100%; max-width: 380px; }

.login-brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); margin-bottom: var(--space-6); }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 19px; border-radius: var(--radius-md); }
.login-brand h1 { font-size: 16px; text-align: center; }
.login-brand .brand-sub { font-size: 11px; }

.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  box-shadow: var(--shadow-2);
}

.login-error {
  background: color-mix(in srgb, var(--err) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--err) 40%, var(--border-strong));
  color: var(--err);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-size: 12.5px;
  margin-bottom: var(--space-4);
  display: none;
}
.login-error.visible { display: block; }

.login-footnote { text-align: center; margin-top: var(--space-5); font-size: 11.5px; color: var(--text-faint); font-family: var(--font-mono); }

/* ---------------------------------------------------------------------- */
/* QR / device panel                                                      */
/* ---------------------------------------------------------------------- */

.device-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-6) var(--space-4); }
.device-hero .pulse-dot { margin-bottom: var(--space-4); }
.device-state-label { font-family: var(--font-mono); font-size: 18px; font-weight: 700; margin-bottom: var(--space-2); text-transform: uppercase; letter-spacing: 0.04em; }
.device-state-sub { color: var(--text-faint); font-size: 13px; margin-bottom: var(--space-5); max-width: 420px; }

.qr-frame {
  width: 240px; height: 240px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-5);
}
.qr-frame img { width: 100%; height: 100%; image-rendering: pixelated; }

.device-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; justify-content: center; }

.info-row { display: flex; justify-content: space-between; padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.info-row .v { font-family: var(--font-mono); }

/* ---------------------------------------------------------------------- */
/* Toasts                                                                  */
/* ---------------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
  max-width: 340px;
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: 13px;
  box-shadow: var(--shadow-2);
  animation: toast-in var(--transition-med);
}
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--err); }
.toast.info { border-left-color: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------- */
/* Modal / confirm dialog                                                 */
/* ---------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center; justify-content: center;
  z-index: 900;
  padding: var(--space-4);
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  width: 100%;
  max-width: 440px;
  padding: var(--space-5);
}
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }

/* ---------------------------------------------------------------------- */
/* Loading                                                                 */
/* ---------------------------------------------------------------------- */

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-faint); }
.empty-state .empty-ico { font-family: var(--font-mono); font-size: 28px; margin-bottom: var(--space-3); opacity: 0.5; }

/* ---------------------------------------------------------------------- */
/* Theme toggle                                                           */
/* ---------------------------------------------------------------------- */

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 14px;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------------- */
/* Utility                                                                 */
/* ---------------------------------------------------------------------- */

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.text-dim { color: var(--text-dim); }
.text-faint { color: var(--text-faint); font-size: 12px; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ---------------------------------------------------------------------- */
/* Responsive: bottom nav on small screens                                */
/* ---------------------------------------------------------------------- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-med);
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: flex; }
  .content { padding: var(--space-4); }
  .grid-widgets { grid-template-columns: 1fr 1fr; }
  .sidebar-scrim {
    display: none;
    position: fixed; inset: 0; background: var(--overlay); z-index: 190;
  }
  .sidebar-scrim.open { display: block; }
}

@media (max-width: 480px) {
  .grid-widgets { grid-template-columns: 1fr; }
  .qr-frame { width: 200px; height: 200px; }
  .topbar { padding: 0 var(--space-3); }
}
