/* ── Theme variables ──────────────────────────────────────── */
:root {
  --bg:               #f1f5f9;
  --surface:          #ffffff;
  --surface-2:        #f8fafc;
  --surface-3:        #f1f5f9;
  --text:             #0f172a;
  --text-muted:       #64748b;
  --text-faint:       #94a3b8;
  --label:            #374151;
  --border:           #e2e8f0;
  --border-input:     #cbd5e1;
  --surface-blue:     #eff6ff;
  --border-blue:      #bfdbfe;
  --text-blue:        #1d4ed8;
  --surface-green:    #dcfce7;
  --text-green:       #15803d;
  --surface-yellow:   #fef9c3;
  --text-yellow:      #a16207;
  --badge-neutral-bg: #f1f5f9;
  --badge-neutral-txt:#475569;
  --primary:          #3b82f6;
  --primary-dark:     #2563eb;
  --success:          #22c55e;
  --error:            #ef4444;
}

html[data-theme="dark"] {
  --bg:               #0f172a;
  --surface:          #1e293b;
  --surface-2:        #263248;
  --surface-3:        #1e293b;
  --text:             #f1f5f9;
  --text-muted:       #94a3b8;
  --text-faint:       #64748b;
  --label:            #cbd5e1;
  --border:           #334155;
  --border-input:     #475569;
  --surface-blue:     rgba(59,130,246,0.12);
  --border-blue:      #1d4ed8;
  --text-blue:        #93c5fd;
  --surface-green:    rgba(34,197,94,0.1);
  --text-green:       #4ade80;
  --surface-yellow:   rgba(161,98,7,0.2);
  --text-yellow:      #fbbf24;
  --badge-neutral-bg: #334155;
  --badge-neutral-txt:#94a3b8;
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  background: #1e293b;
  color: #f8fafc;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid #0f172a;
}

.navbar-brand {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-link {
  color: #94a3b8;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  transition: color 150ms, background 150ms;
}

.nav-link:hover  { color: #f8fafc; background: rgba(255,255,255,0.07); }
.nav-link.active { color: #f8fafc; background: rgba(255,255,255,0.1); }

.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.refresh-indicator {
  font-size: 12px;
  color: #64748b;
}

/* ── Page wrapper ─────────────────────────────────────────── */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.page-header {
  margin-bottom: 22px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 3px;
}

/* ── Stat cards row ───────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-note {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* ── Main grid ────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  align-items: start;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 18px;
}

/* ── Form ─────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--label);
}

textarea, input[type="text"], input[type="password"], select {
  width: 100%;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
  resize: vertical;
}

textarea:focus, input[type="text"]:focus, input[type="password"]:focus, select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

textarea { min-height: 110px; }

.form-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 150ms, opacity 150ms;
  white-space: nowrap;
}

.btn-primary {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
}
.btn-primary:hover    { background: #2563eb; border-color: #2563eb; }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }

.btn-secondary {
  background: var(--surface);
  color: var(--label);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-sm { padding: 5px 11px; font-size: 12px; }

.btn-danger {
  background: var(--surface);
  color: #dc2626;
  border-color: #fca5a5;
}
.btn-danger:hover { background: #fee2e2; border-color: #f87171; }

/* ── Status text ──────────────────────────────────────────── */
.status-text {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ── Message feed ─────────────────────────────────────────── */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 560px;
  overflow-y: auto;
  padding: 16px;
}

.message-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  background: var(--surface-2);
  display: grid;
  gap: 5px;
}

.message-item.outbound {
  background: var(--surface-blue);
  border-color: var(--border-blue);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-inbound  { background: var(--surface-green); color: var(--text-green); }
.badge-outbound { background: var(--surface-blue);  color: var(--text-blue);  }
.badge-status   { background: var(--badge-neutral-bg); color: var(--badge-neutral-txt); }

.message-route {
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: ui-monospace, monospace;
}

.message-body {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
}

.message-time  { font-size: 11px; color: var(--text-faint); }
.message-error { font-size: 12px; color: #dc2626; }

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-faint);
  font-size: 13.5px;
  border: 1px dashed var(--border-input);
  border-radius: 8px;
  margin: 16px;
}

/* ── Users table ──────────────────────────────────────────── */
.users-table {
  width: 100%;
  border-collapse: collapse;
}

.users-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}

.users-table td:last-child {
  white-space: nowrap;
}

.users-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover td      { background: var(--surface-2); }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name   { font-weight: 600; color: var(--text); font-size: 13.5px; }
.user-handle { font-size: 12px;  color: var(--text-faint); }

.setup-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.setup-badge.complete { background: var(--surface-green);  color: var(--text-green);  }
.setup-badge.pending  { background: var(--surface-yellow); color: var(--text-yellow); }

/* Inline send row */
.send-row { display: none; }
.send-row.open { display: table-row; }

.send-row td {
  padding: 12px 16px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.send-row textarea {
  min-height: 72px;
  margin-bottom: 8px;
}

.send-row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.send-status { font-size: 12.5px; color: var(--text-muted); }

/* Inline profile row */
.profile-row { display: none; }
.profile-row.open { display: table-row; }

.profile-row td {
  padding: 12px 16px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.profile-row-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 140px;
}

.profile-field-key {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

.profile-field-question {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.profile-field-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

.profile-field-empty {
  color: var(--border-input);
  font-weight: 400;
  font-style: italic;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .message-list   { max-height: none; }
}

@media (max-width: 600px) {
  .page       { padding: 16px 12px 32px; }
  .stats-row  { grid-template-columns: 1fr 1fr; }
  .navbar     { padding: 0 14px; gap: 16px; }
}
