/* ============================================================
   Banteng Caraka WA Gateway — Design System
   ============================================================ */

:root {
  --bg: #f1f5f9;
  --bg-2: #e2e8f0;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --brand: #e62129;
  --brand-2: #c41e3a;
  --brand-soft: #fef2f2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1e40af;
  --info-soft: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .15);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-2: #0f172a;
  --card: #1e293b;
  --ink: #f1f5f9;
  --ink-2: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --line-2: #475569;
  --brand: #ef4444;
  --brand-2: #dc2626;
  --brand-soft: #450a0a;
  --ok: #4ade80;
  --ok-soft: #052e16;
  --warn: #fbbf24;
  --warn-soft: #422006;
  --bad: #f87171;
  --bad-soft: #450a0a;
  --info: #93c5fd;
  --info-soft: #172554;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--brand); text-decoration: none; transition: color .15s; }
a:hover { color: var(--brand-2); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

h1, h2, h3, h4 { color: var(--ink); margin: 0 0 8px; line-height: 1.25; font-weight: 700; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: 0 0 8px; }
code { background: var(--bg-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; font-family: ui-monospace, monospace; }
pre { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: var(--radius); overflow: auto; font-size: 13px; }
pre code { background: transparent; padding: 0; color: inherit; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.py { padding-top: 32px; padding-bottom: 32px; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }

/* ============================================================
   LANDING / FORM PAGES
   ============================================================ */

.hero {
  background: linear-gradient(135deg, #e62129 0%, #9f1239 55%, #7f1d1d 100%);
  color: white;
  padding: 28px 0;
  box-shadow: var(--shadow-md);
}
.hero .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-text { min-width: 0; }
.logo,
.logo-img {
  width: 48px; height: 48px; border-radius: 10px;
  flex-shrink: 0; object-fit: contain;
  display: block;
}
.logo {
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 24px;
  backdrop-filter: blur(8px);
}
.logo-img {
  background: white;
  padding: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.logo-img.lg { width: 64px; height: 64px; border-radius: 14px; }
.logo-img.sm { width: 36px; height: 36px; border-radius: 8px; padding: 3px; }
.hero h1 { color: white; margin: 0; font-size: 22px; }
.hero p { margin: 4px 0 0; opacity: .92; font-size: 14px; }
.hero a { color: white; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.docs pre { font-size: 13px; }
.footer { border-top: 1px solid var(--line); padding: 20px 0; margin-top: 40px; color: var(--muted); font-size: 13px; }
.footer .container { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* Auth forms (login / register) */
.auth-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  box-sizing: border-box;
}
.auth-page .form {
  max-width: 420px; width: 100%;
  margin: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px 24px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  text-align: center; margin-bottom: 20px;
}
.auth-brand .logo-img { margin: 0 auto 12px; }
.auth-brand h2 { margin: 0 0 4px; font-size: 20px; }
.auth-brand p { margin: 0; font-size: 13px; color: var(--muted); }
.form h2 { margin: 0 0 18px; font-size: 22px; }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  text-decoration: none; line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.danger { background: var(--bad); color: white; border-color: var(--bad); }
.btn.danger:hover { filter: brightness(.92); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn.icon { padding: 8px; }

/* For inverted contexts (e.g. hero) */
.hero .btn { background: rgba(255,255,255,.12); color: white; border-color: rgba(255,255,255,.4); }
.hero .btn:hover { background: rgba(255,255,255,.22); }
.hero .btn.primary { background: white; color: var(--brand); border-color: white; }
.hero .btn.primary:hover { background: #fef2f2; }

.btn-block {
  width: 100%; padding: 11px;
  background: var(--brand); color: white; border-radius: var(--radius-sm);
  border: 1px solid var(--brand); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.btn-block:hover { background: var(--brand-2); }
.btn-block:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ============================================================
   FORMS
   ============================================================ */

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12.5px;
  color: var(--ink-2); margin-bottom: 5px; font-weight: 500;
}
.field input, .field textarea, .field select,
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]),
textarea, select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px;
  background: var(--card); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus,
input:focus, textarea:focus, select:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(185, 28, 28, .15);
}
.field textarea { min-height: 80px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.field input[disabled], .field input[readonly] { background: var(--bg-2); color: var(--muted); }

.alert {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13.5px; margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert.error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert.info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

/* ============================================================
   SHELL (sidebar layout)
   ============================================================ */

.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; min-height: 100dvh; }

.side {
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #cbd5e1;
  padding: 14px 12px;
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.side .col { display: flex; flex-direction: column; min-height: calc(100vh - 28px); min-height: calc(100dvh - 28px); }
.side .brand {
  display: flex; align-items: center; gap: 10px;
  color: white; padding: 4px 8px 14px;
  border-bottom: 1px solid #334155; margin-bottom: 12px;
}
.side .brand .logo-img { width: 40px; height: 40px; border-radius: 8px; padding: 3px; background: white; flex-shrink: 0; }
.side .brand-text { min-width: 0; }
.side .brand h1 { color: white; font-size: 14px; line-height: 1.2; margin: 0; }
.side .brand .brand-sub { font-size: 10.5px; color: #94a3b8; margin-top: 2px; line-height: 1.3; }

.side .nav-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }

.side .nav-group { font-size: 10.5px; color: #64748b; text-transform: uppercase; letter-spacing: .08em; padding: 12px 10px 4px; font-weight: 600; }
.side a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: #cbd5e1; font-size: 13px; transition: background .12s, color .12s;
}
.side a:hover { background: #1e293b; color: white; text-decoration: none; }
.side a.active {
  background: var(--brand); color: white; font-weight: 500;
  box-shadow: 0 2px 6px rgba(185, 28, 28, .35);
}
.side a .ico { width: 16px; text-align: center; flex-shrink: 0; font-size: 14px; }

.side .me {
  margin-top: auto; padding-top: 12px; border-top: 1px solid #334155;
  font-size: 12px; color: #94a3b8;
}
.side .me .name { color: white; font-weight: 600; font-size: 13px; }

.main { padding: 24px; max-width: calc(100vw - 260px); min-width: 0; }
.main h2 { margin: 0 0 12px; font-size: 22px; }

/* Mobile top bar (injected by sidebar.js) */
.mobile-topbar {
  display: none;
  position: sticky; top: 0; z-index: 90;
  align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.mobile-topbar .menu-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink);
  font-size: 20px; cursor: pointer;
}
.mobile-topbar .menu-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.mobile-topbar .topbar-title {
  font-weight: 700; font-size: 15px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.mobile-topbar .topbar-logo { width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  z-index: 180;
}

/* Page header pattern */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header-text h2 { margin: 0; font-size: 22px; }
.page-header-text p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; max-width: 720px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; }

.stat-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.stat-card .stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ============================================================
   TABLES
   ============================================================ */

.table {
  width: 100%; border-collapse: collapse;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  font-size: 13.5px;
  box-shadow: var(--shadow-sm);
}
.table th, .table td {
  padding: 9px 12px; text-align: left;
  border-bottom: 1px solid var(--line); vertical-align: middle;
}
.table th {
  background: var(--bg-2); color: var(--muted);
  font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--bg-2); }
.table tr:last-child td { border-bottom: none; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 4px; }

/* responsive: scroll horizontally on mobile */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.table-wrap .table { margin-bottom: 0; min-width: 560px; }

/* ============================================================
   BADGES / STATUS PILLS
   ============================================================ */

.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em;
  font-weight: 600; border: 1px solid transparent;
}
.badge.connected { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.badge.disconnected, .badge.banned, .badge.failed, .badge.cancelled {
  background: var(--bad-soft); color: var(--bad); border-color: var(--bad);
}
.badge.qr, .badge.connecting, .badge.pairing, .badge.queued, .badge.pending, .badge.running {
  background: var(--warn-soft); color: var(--warn); border-color: var(--warn);
}
.badge.info, .badge.completed, .badge.sent, .badge.delivered, .badge.read, .badge.received {
  background: var(--info-soft); color: var(--info); border-color: var(--info);
}

/* ============================================================
   MODAL
   ============================================================ */

.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: none; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .18s ease-out;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--card); color: var(--ink);
  border-radius: var(--radius-lg); padding: 22px;
  max-width: 460px; width: 100%;
  max-height: calc(100vh - 40px); overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn .18s ease-out;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; padding-right: 24px; }
.modal img.qr { width: 100%; max-width: 320px; display: block; margin: 10px auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.modal .pair {
  font-family: ui-monospace, monospace; font-size: 28px;
  letter-spacing: .15em; text-align: center; padding: 12px;
  background: var(--bg-2); border-radius: var(--radius-sm); color: var(--ink);
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  cursor: pointer; color: var(--muted);
  background: transparent; border: 0; padding: 4px 8px;
  font-size: 22px; line-height: 1; border-radius: var(--radius-sm);
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--bg-2); color: var(--ink); }
.modal-close:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* For modals that contain modal-close, add relative position */
.modal { position: relative; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center; padding: 40px 20px;
  background: var(--card); border: 2px dashed var(--line-2);
  border-radius: var(--radius);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 8px; opacity: .6; }
.empty-state h3 { margin: 0 0 4px; }
.empty-state p { margin: 0 0 12px; color: var(--muted); }

.table-state { text-align: center; padding: 24px 12px !important; }
.table-state-error { color: var(--bad); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-stack {
  position: fixed; top: 16px; right: 16px;
  z-index: 1000; display: flex; flex-direction: column; gap: 8px;
  max-width: 380px; pointer-events: none;
}
.toast {
  background: var(--card); color: var(--ink);
  border-left: 4px solid var(--info);
  padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 13.5px; pointer-events: auto;
  animation: slideInRight .25s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
.toast .toast-title { font-weight: 600; margin-bottom: 2px; }
.toast .toast-body { color: var(--ink-2); }

@keyframes slideInRight {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   SPINNER
   ============================================================ */

.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--line-2); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   COPYABLE
   ============================================================ */

.copyable { cursor: pointer; }
.copyable:hover { text-decoration: underline; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* ============================================================
   THEME TOGGLE
   ============================================================ */

.theme-toggle {
  position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: calc(16px + env(safe-area-inset-left)); z-index: 100;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: transform .15s, box-shadow .15s;
}
.auth-page .theme-toggle,
body.auth-page .theme-toggle { display: none !important; }

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 800px) {
  .container { padding: 0 16px; }
  .py { padding-top: 24px; padding-bottom: 24px; }
  .hero { padding: 20px 0; }
  .hero h1 { font-size: 18px; }
  .hero p { font-size: 13px; }
  .hero .container { flex-direction: column; align-items: flex-start; }
  .hero nav { width: 100%; }
  .hero nav .btn { width: 100%; justify-content: center; }
  .footer .container { flex-direction: column; align-items: flex-start; gap: 6px; }

  .auth-page { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .auth-page .form { margin: 0 auto; width: 100%; max-width: 420px; padding: 22px 18px; border-radius: var(--radius); }
  .form { margin: 24px 16px; padding: 22px 18px; }

  .shell,
  .inbox-shell { display: block; }
  .mobile-topbar { display: flex; }
  .sidebar-backdrop { display: none; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .theme-toggle { display: none; }

  .side {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(288px, 88vw);
    height: 100vh; height: 100dvh;
    z-index: 200;
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
    padding-top: calc(14px + env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.sidebar-open .side { transform: translateX(0); }
  .side .col { min-height: 100%; }
  .side a { padding: 10px 12px; font-size: 14px; min-height: 44px; }
  .side .me { width: 100%; margin-top: 8px; padding-bottom: 8px; }

  .main {
    max-width: 100vw;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { flex: 1; justify-content: center; min-height: 44px; }
  .page-header-text h2 { font-size: 20px; }

  .btn { min-height: 40px; }
  .btn.sm { min-height: 34px; }
  .toolbar { gap: 6px; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }

  .table { font-size: 12.5px; }
  .table th, .table td { padding: 8px 10px; }
  .table .actions { white-space: normal; }
  .table .actions .btn { margin: 2px 0; }

  .cards { grid-template-columns: 1fr; }
  .stat-card .stat-value { font-size: 24px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }

  .toast-stack {
    left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top));
    max-width: none;
  }
  .theme-toggle { bottom: calc(12px + env(safe-area-inset-bottom)); left: calc(12px + env(safe-area-inset-left)); }

  /* Inbox responsive: stack panels, show only one at a time */
  .inbox-main { min-height: calc(100dvh - 56px); }
  .inbox-main.thread-open .conv-list { display: none; }
  .inbox-main:not(.thread-open) .chat-pane { display: none; }
  .chat-thread { max-height: calc(100dvh - 220px); }
  .bubble { max-width: 88%; }

  pre { font-size: 11.5px; padding: 12px; }
  .card pre { overflow-x: auto; }

  .modal-bg { padding: 12px; align-items: flex-end; }
  .modal {
    padding: 18px;
    max-height: calc(100dvh - 24px);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  .modal h3 { font-size: 16px; }
  .field input, .field textarea, .field select,
  input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]),
  textarea, select {
    font-size: 16px; /* prevent iOS zoom on focus */
  }
}

@media (max-width: 480px) {
  h2 { font-size: 20px; }
  .page-header-text h2 { font-size: 18px; }
  .hero .brand { gap: 10px; }
  .logo-img.lg { width: 52px; height: 52px; }
}

/* ============================================================
   DARK MODE TWEAKS
   ============================================================ */

html[data-theme="dark"] .table tbody tr:hover { background: #0f172a; }
html[data-theme="dark"] .conv-list { background: var(--card); }
html[data-theme="dark"] .chat-pane { background: var(--bg); }
html[data-theme="dark"] .chat-header { background: var(--card); }
html[data-theme="dark"] .chat-input { background: var(--card); }
html[data-theme="dark"] .bubble.in { background: var(--card); border-color: var(--line); color: var(--ink); }
html[data-theme="dark"] .bubble.out { background: #166534; color: #ecfdf5; }
html[data-theme="dark"] .conv-list .item:hover { background: var(--bg-2); }
html[data-theme="dark"] .conv-list .item.active { background: #1f2937; border-left-color: var(--brand); }
html[data-theme="dark"] pre { background: #020617; color: #e2e8f0; border: 1px solid var(--line); }
html[data-theme="dark"] code { background: #1e293b; color: #e2e8f0; }
