/* ==========================================================================
   WhatsApp Bridge — dashboard styles

   Self-hosted on purpose: no CDN, no external fonts, no build step. The
   previous version pulled Tailwind and Lucide from the network, so the whole
   UI broke on a server without outbound internet access.
   ========================================================================== */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --accent: #128c7e;
  --accent-hover: #0e7268;
  --accent-soft: #e6f4f1;

  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);

  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2437;
  --border: #253048;
  --border-strong: #33415c;

  --text: #e8edf5;
  --text-muted: #93a3bc;
  --text-faint: #64748b;

  --accent: #25d366;
  --accent-hover: #1fb955;
  --accent-soft: #12301f;

  --ok: #4ade80;
  --ok-soft: #14311f;
  --warn: #fbbf24;
  --warn-soft: #382a0d;
  --danger: #f87171;
  --danger-soft: #3a1717;
  --info: #60a5fa;
  --info-soft: #16263f;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

/* Baseline for every inline icon.
   Without this an SVG with only a viewBox either stretches to fill its flex
   parent (a 20px title icon rendered at 293px) or collapses to zero width
   inside an inline-flex pill. Component rules below override the size; this
   guarantees a sane result for any icon added later. */
svg {
  width: 1em;
  height: 1em;
  flex: none;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  /* Subtle depth so the gate reads as a distinct surface, not a blank page. */
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.login__card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-xl);
  padding: 36px 32px;
  text-align: center;
}

.login__logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.login__logo svg { width: 32px; height: 32px; }

.login__title { margin: 0 0 6px; font-size: 21px; font-weight: 700; }
.login__sub { margin: 0 0 26px; color: var(--text-muted); font-size: 14px; }
.login__form { text-align: start; }

.login__error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.login__hint {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.7;
}

/* ----------------------------------------------------------------- header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand__mark {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.brand__mark svg { width: 21px; height: 21px; }
.brand__text { min-width: 0; }
.brand__title { font-size: 15.5px; font-weight: 700; line-height: 1.3; }
.brand__sub { font-size: 12px; color: var(--text-muted); line-height: 1.3; }

.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

.server-state {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ layout */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 24px 64px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
}

.section-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.section-head .spacer { flex: 1; }

/* ------------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat__icon {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
}

.stat__icon svg { width: 21px; height: 21px; }
.stat__icon--ok { background: var(--ok-soft); color: var(--ok); }
.stat__icon--info { background: var(--info-soft); color: var(--info); }
.stat__icon--warn { background: var(--warn-soft); color: var(--warn); }
.stat__icon--accent { background: var(--accent-soft); color: var(--accent); }

.stat__value { font-size: 22px; font-weight: 700; line-height: 1.15; }
.stat__label { font-size: 12.5px; color: var(--text-muted); }

/* ------------------------------------------------------------------- cards */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: rise 0.25s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card__head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.card__id {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--mono);
  word-break: break-all;
  line-height: 1.4;
}

.card__phone {
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--mono);
  direction: ltr;
  text-align: start;
}

.card__body { padding: 14px 18px; display: grid; gap: 12px; flex: 1; }

.meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.meta svg { width: 14px; height: 14px; flex: none; }

.card__foot {
  padding: 12px 18px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ------------------------------------------------------------------ quota */

.quota { display: grid; gap: 7px; }

.quota__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.quota__row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ok);
  transition: width 0.4s ease;
}

.bar__fill--warn { background: var(--warn); }
.bar__fill--danger { background: var(--danger); }

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.pill svg { width: 13px; height: 13px; }

.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--danger { background: var(--danger-soft); color: var(--danger); }
.pill--muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.pill--info { background: var(--info-soft); color: var(--info); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.dot--live { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; flex: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn--icon { padding: 8px; }
.btn--icon svg { width: 17px; height: 17px; }

.btn--block { width: 100%; }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--grow { flex: 1 1 auto; }

/* ------------------------------------------------------------------ forms */

.field { margin-bottom: 16px; }

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field__hint { margin-top: 6px; font-size: 12px; color: var(--text-muted); line-height: 1.55; }

.input,
.textarea,
.select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.textarea--mono { font-family: var(--mono); font-size: 13px; direction: ltr; text-align: start; }
.input--ltr { direction: ltr; text-align: start; font-family: var(--mono); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: 13.5px;
}

.check input { margin-top: 3px; accent-color: var(--accent); flex: none; }

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  animation: fade 0.15s ease-out;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal__box {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-xl);
  animation: rise 0.2s ease-out;
}

.modal__box--wide { max-width: 660px; }

.modal__head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
}

.modal__head > svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
}

.modal__title { margin: 0; font-size: 16.5px; font-weight: 700; }
.modal__body { padding: 20px 22px; }

.modal__foot {
  padding: 14px 22px 20px;
  display: flex;
  gap: 9px;
  justify-content: flex-end;
}

.modal__close {
  margin-inline-start: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.modal__close:hover { background: var(--surface-2); color: var(--text); }
.modal__close svg { width: 19px; height: 19px; }

/* --------------------------------------------------------------------- qr */

.qr {
  text-align: center;
  padding: 8px 0 4px;
}

.qr img {
  width: 260px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  /* The QR is rendered dark-on-light; keep it readable in dark mode. */
  background: #fff;
  padding: 10px;
}

.qr__steps {
  margin: 18px 0 0;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  text-align: start;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.9;
}

.qr__steps ol { margin: 0; padding-inline-start: 20px; }

/* ---------------------------------------------------------------- results */

.result-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.result-list {
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface-2);
}

.result-row svg { width: 15px; height: 15px; flex: none; }
.result-row--ok { color: var(--ok); }
.result-row--bad { color: var(--danger); }
.result-row span { color: var(--text); font-family: var(--mono); direction: ltr; }
.result-row em { color: var(--text-muted); font-style: normal; font-size: 12px; margin-inline-start: auto; }

/* ------------------------------------------------------------------ alert */

.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.65;
  margin-bottom: 16px;
}

.alert svg { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.alert--warn { background: var(--warn-soft); color: var(--warn); }
.alert--info { background: var(--info-soft); color: var(--info); }
.alert b { display: block; margin-bottom: 2px; }

/* ------------------------------------------------------------------ empty */

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 70px 20px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.empty svg { width: 46px; height: 46px; color: var(--text-faint); margin-bottom: 14px; }
.empty h3 { margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0 0 20px; color: var(--text-muted); font-size: 13.5px; }

/* ---------------------------------------------------------------- skeleton */

.skeleton {
  height: 210px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border: 1px solid var(--border);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ------------------------------------------------------------------ toast */

.toasts {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 90;
  display: grid;
  gap: 9px;
  max-width: min(400px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--info);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: slide 0.22s ease-out;
}

@keyframes slide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.toast svg { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast--success { border-inline-start-color: var(--ok); }
.toast--success svg { color: var(--ok); }
.toast--error { border-inline-start-color: var(--danger); }
.toast--error svg { color: var(--danger); }
.toast--warn { border-inline-start-color: var(--warn); }
.toast--warn svg { color: var(--warn); }
.toast--info svg { color: var(--info); }

/* ----------------------------------------------------------------- helpers */

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); direction: ltr; }
.stack { display: grid; gap: 12px; }

@media (max-width: 640px) {
  .topbar__inner { padding: 10px 16px; flex-wrap: wrap; }
  .page { padding: 20px 16px 48px; }
  .brand__sub { display: none; }
  .server-state span { display: none; }
  .grid { grid-template-columns: 1fr; }
}

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