:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #b91c1c;
  --brand-2: #dc2626;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
}
html[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --brand: #ef4444;
  --brand-2: #dc2626;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
}
html[data-theme="dark"] .table { background: var(--card); }
html[data-theme="dark"] .table th { background: #0f172a; color: var(--muted); }
html[data-theme="dark"] .field input, html[data-theme="dark"] .field textarea, html[data-theme="dark"] .field select,
html[data-theme="dark"] input[type=time], html[data-theme="dark"] input[type=date], html[data-theme="dark"] input[type=datetime-local] {
  background: var(--card); color: var(--ink); border-color: var(--line);
}
html[data-theme="dark"] .conv-list { background: var(--card); }
html[data-theme="dark"] .chat-pane { background: #0b1220; }
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: #0b1220; }
html[data-theme="dark"] .conv-list .item.active { background: #1f2937; border-left-color: var(--brand); }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.5; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.py { padding-top: 32px; padding-bottom: 32px; }

.hero { background: linear-gradient(135deg, var(--brand) 0%, #7f1d1d 100%); color: white; padding: 28px 0; }
.hero .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 48px; height: 48px; border-radius: 10px; background: rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 24px; }
.hero h1 { margin: 0; font-size: 22px; }
.hero p { margin: 4px 0 0; opacity: .9; font-size: 14px; }
.hero a { color: white; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.4); color: white; font-weight: 500;
  background: transparent; cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.btn.primary { background: white; color: var(--brand); border-color: white; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: white; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

.docs { margin-top: 28px; }
.docs pre { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 10px; overflow: auto; font-size: 13px; }
.muted { color: var(--muted); font-size: 14px; }

.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; }

/* forms */
.form { max-width: 420px; margin: 60px auto; background: white; border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.form h2 { margin: 0 0 18px; font-size: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; background: white; color: var(--ink);
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.btn-block { width: 100%; padding: 10px; background: var(--brand); color: white; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; }
.btn-block:hover { background: var(--brand-2); }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.alert.error { background: #fef2f2; color: var(--bad); border: 1px solid #fecaca; }
.alert.ok { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.center { text-align: center; }

/* dashboard */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: #0f172a; color: #cbd5e1; padding: 16px; }
.side .brand { color: white; padding: 6px 0 14px; border-bottom: 1px solid #1e293b; margin-bottom: 12px; }
.side .brand h1 { color: white; font-size: 16px; }
.side a { display: block; padding: 8px 10px; border-radius: 6px; color: #cbd5e1; font-size: 14px; }
.side a:hover { background: #1e293b; text-decoration: none; }
.side a.active { background: var(--brand); color: white; }
.side .me { margin-top: auto; padding-top: 12px; border-top: 1px solid #1e293b; font-size: 13px; color: #94a3b8; }
.side .me .name { color: white; font-weight: 600; }
.side .col { display: flex; flex-direction: column; min-height: calc(100vh - 32px); }
.main { padding: 24px; }
.main h2 { margin: 0 0 16px; font-size: 22px; }

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

.table { width: 100%; border-collapse: collapse; background: white; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: #f1f5f9; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: none; }
.table .mono { font-family: ui-monospace, monospace; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.badge.connected { background: #dcfce7; color: var(--ok); }
.badge.disconnected, .badge.banned { background: #fee2e2; color: var(--bad); }
.badge.qr, .badge.connecting, .badge.pairing { background: #fef3c7; color: var(--warn); }

.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.7); z-index: 50;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-bg.show { display: flex; }
.modal { background: white; border-radius: 14px; padding: 22px; max-width: 460px; width: 100%; }
.modal h3 { margin: 0 0 12px; }
.modal img { width: 100%; max-width: 320px; display: block; margin: 10px auto; border: 1px solid var(--line); border-radius: 8px; }
.modal .pair { font-family: ui-monospace, monospace; font-size: 28px; letter-spacing: .15em; text-align: center; padding: 10px; background: #f1f5f9; border-radius: 8px; }
.modal-close { float: right; cursor: pointer; color: var(--muted); }

.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; }

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

.hidden { display: none !important; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; }
  .side .brand { width: 100%; }
  .side a { padding: 6px 10px; font-size: 13px; }
  .side .me { width: 100%; margin-top: 8px; }

  /* Inbox responsive: stack panels, show only one at a time */
  .inbox-shell { grid-template-columns: 1fr !important; }
  .inbox-main { grid-template-columns: 1fr !important; height: auto !important; }
  .inbox-main.thread-open .conv-list { display: none; }
  .inbox-main:not(.thread-open) .chat-pane { display: none; }
  .chat-thread { max-height: calc(100vh - 220px); }
}

.theme-toggle {
  position: fixed; bottom: 16px; left: 16px; z-index: 100;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
