/* Design tokens follow the OpenWA dashboard (MIT): WhatsApp green on a slate palette, light + dark. */
:root {
  --primary: #25d366;
  --primary-text: #167c3b;
  --primary-hover: #1da851;
  --primary-soft: rgba(37, 211, 102, 0.12);
  --focus-ring: var(--primary-text);
  --bg-light: #f8fafc;
  --bg-white: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --control-border: #7b8aa0;
  --error: #ef4444;
  --error-text: #b93232;
  --error-soft: rgba(239, 68, 68, 0.1);
  --success: #22c55e;
  --success-text: #157b3b;
  --success-soft: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-text: #935f06;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.1);
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 10px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg-light: #0f172a;
  --bg-white: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border: #334155;
  --control-border: #68788f;
  --primary-soft: color-mix(in srgb, var(--primary) 18%, transparent);
  --primary-text: var(--primary);
  --error-text: #f77b7b;
  --success-text: var(--success);
  --warning-text: var(--warning);
  --info: #60a5fa;
  --code-bg: #020617;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg-light: #0f172a;
    --bg-white: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: #334155;
    --control-border: #68788f;
    --primary-soft: color-mix(in srgb, var(--primary) 18%, transparent);
    --primary-text: var(--primary);
    --error-text: #f77b7b;
    --success-text: var(--success);
    --warning-text: var(--warning);
    --info: #60a5fa;
    --code-bg: #020617;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

/* ==================== Base ==================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg-light);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-light);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.025em;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

a {
  color: var(--primary-text);
  font-weight: 500;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 5px;
  background: var(--bg-light);
  border: 1px solid var(--border);
}

svg {
  flex-shrink: 0;
  display: block;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #06301a;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-white);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-light);
  border-color: var(--control-border);
}

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}

/* ==================== Forms ==================== */
.form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.input-group label,
.input-group legend {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  padding: 0;
  margin-bottom: 0.25rem;
}

input[type='text'],
input[type='password'],
input[type='tel'],
input[type='url'],
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text-primary);
  background: var(--bg-white);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 1px var(--focus-ring), 0 0 0 3px rgba(37, 211, 102, 0.12);
}

input.error {
  border-color: var(--error);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

.hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.875rem !important;
  font-weight: 400 !important;
  color: var(--text-secondary) !important;
  cursor: pointer;
  margin: 0.15rem 0 !important;
}

.check input {
  margin-top: 0.3rem;
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.check b {
  color: var(--text-primary);
  font-weight: 600;
}

.row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.row input {
  flex: 1;
  min-width: 180px;
}

.error-message {
  font-size: 0.8125rem;
  color: var(--error-text);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid transparent;
  overflow-wrap: anywhere;
}

.alert.success {
  background: var(--success-soft);
  color: var(--success-text);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
}

.alert.error {
  background: var(--error-soft);
  color: var(--error-text);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
}

.alert.info {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 30%, transparent);
}

/* ==================== Login ==================== */
.login-container {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg-light);
}

.login-card {
  background: var(--bg-white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 3rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 2rem;
}

.logo-badge {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px -8px rgba(37, 211, 102, 0.6);
  margin-bottom: 0.75rem;
}

.brand-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.version-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.login-form {
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-wrapper {
  position: relative;
}

.input-wrapper input {
  padding-inline-end: 3rem;
}

.toggle-visibility {
  position: absolute;
  inset-inline-end: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.toggle-visibility:hover {
  color: var(--text-primary);
}

/* ==================== Layout ==================== */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  height: 100dvh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.5rem 24px;
  min-height: 72px;
}

.sidebar-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-version {
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.menu-close {
  display: none;
  margin-inline-start: auto;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-light);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}

.sidebar-footer {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.sidebar-btn:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}

.logout-btn:hover {
  background: var(--error-soft);
  color: var(--error-text);
}

.main-content {
  flex: 1;
  margin-left: 260px;
  width: calc(100% - 260px);
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg-light);
}

.mobile-bar {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.5);
  z-index: 90;
}

/* ==================== Page ==================== */
.page {
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.stat-card > div:last-child {
  min-width: 0;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary-text);
  flex-shrink: 0;
}

.stat-icon.icon-success {
  background: var(--success-soft);
  color: var(--success-text);
}

.stat-icon.icon-error {
  background: var(--error-soft);
  color: var(--error-text);
}

.stat-icon.icon-warning {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.stat-icon.icon-info {
  background: var(--info-soft);
  color: var(--info);
}

.stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-value.stat-small {
  font-size: 1rem;
  padding-top: 0.2rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.grid-2 .card {
  margin-bottom: 0;
}

.card.narrow {
  max-width: 640px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-body {
  padding: 1.25rem;
}

.card-body.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-light);
  color: var(--text-secondary);
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.success {
  background: var(--success-soft);
  color: var(--success-text);
}

.badge.warning {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.badge.error {
  background: var(--error-soft);
  color: var(--error-text);
}

.badge.info {
  background: var(--info-soft);
  color: var(--info);
}

.qr-box {
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.qr-box img {
  width: 240px;
  height: 240px;
  display: block;
  image-rendering: pixelated;
}

.qr-steps {
  margin: 0;
  padding-inline-start: 1.25rem;
  text-align: start;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.connected-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.account-name {
  font-size: 1.125rem;
  font-weight: 700;
}

.account-number {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.link {
  font-size: 0.8125rem;
}

/* ==================== Table ==================== */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  text-align: start;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background: color-mix(in srgb, var(--bg-light) 60%, transparent);
}

.cell-msg {
  max-width: 420px;
  overflow-wrap: anywhere;
  color: var(--text-secondary);
}

.cell-nowrap {
  white-space: nowrap;
}

.cell-muted {
  color: var(--text-muted);
}

.method {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.method.get {
  background: var(--info-soft);
  color: var(--info);
}

.method.post {
  background: var(--success-soft);
  color: var(--success-text);
}

.method.put {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.code {
  margin: 0 0 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

/* ==================== Modal + toast ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
}

.modal {
  background: var(--bg-white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
}

.modal p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin: 0.5rem 0 1.5rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 300;
  max-width: calc(100vw - 2.5rem);
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-white);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  animation: toast-in 0.2s ease-out;
}

.toast.success {
  color: var(--success-text);
}

.toast.error {
  color: var(--error-text);
}

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

/* ==================== Mobile ==================== */
@media (max-width: 767px) {
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 80;
    height: 56px;
    padding: 0 0.75rem;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
  }

  .mobile-brand .sidebar-logo {
    width: 26px;
    height: 26px;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-close {
    display: inline-flex;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 1.25rem 1rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 2rem 1.5rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 1rem;
  }
}

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

/* Profile photo (Business page) */
.photo-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.photo-preview,
.photo-empty {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 1px solid var(--border);
}

.photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-light);
  color: var(--text-muted);
}

.photo-empty[hidden],
.photo-preview[hidden] {
  display: none;
}
