@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Refined palette inspired by Linear / Stripe */
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-sidebar: #0b1220;
  --bg-sidebar-hover: #131c2e;
  --bg-sidebar-active: #1e293b;
  --border: #e6e8ec;
  --border-strong: #d4d8de;
  --border-subtle: #eef0f3;

  --text: #0a0e1a;
  --text-secondary: #4a5263;
  --text-muted: #6b7280;
  --text-subtle: #94a0af;
  --text-on-dark: #e5e9f2;
  --text-on-dark-muted: #8c95a8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --accent-gold: #f59e0b;
  --accent-gold-light: #fef3c7;

  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-strong-bg: #fee2e2;
  --danger-text: #991b1b;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.10), 0 4px 8px rgba(15, 23, 42, 0.06);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  --transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  font-feature-settings: 'cv02','cv03','cv04','cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--primary-light); color: var(--text); }

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); }

/* ====================== Layout ====================== */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: var(--bg-sidebar);
  color: var(--text-on-dark);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .brand-mark {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1e3a8a 0%, #0b1220 100%);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06), inset 0 1px 0 rgba(255,255,255,0.08);
}
.sidebar .brand-mark svg { width: 22px; height: 22px; }
.sidebar .brand-text { line-height: 1.1; }
.sidebar .brand-name { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.sidebar .brand-sub { color: var(--text-on-dark-muted); font-size: 11px; font-weight: 500; }

.sidebar nav { display: flex; flex-direction: column; gap: 1px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--text-on-dark-muted);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: var(--transition);
}
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.sidebar nav a:hover { background: var(--bg-sidebar-hover); color: #fff; }
.sidebar nav a.active { background: var(--bg-sidebar-active); color: #fff; }
.sidebar nav a.active svg { opacity: 1; color: var(--accent-gold); }

.sidebar .section-label {
  padding: 14px 10px 6px 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-on-dark-muted);
  font-weight: 700;
  opacity: 0.65;
}

.sidebar .footer {
  margin-top: auto;
  padding: 14px 10px 4px 10px;
  font-size: 11.5px;
  color: var(--text-on-dark-muted);
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar .footer .send-window { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.sidebar .footer .dot { width: 7px; height: 7px; border-radius: 50%; }
.sidebar .footer .dot.green { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.sidebar .footer .dot.red { background: var(--danger); }
.sidebar .footer .dot.amber { background: var(--accent-gold); }

.main {
  flex: 1;
  padding: 28px 36px 80px 36px;
  overflow-x: hidden;
  min-width: 0;
}

/* ====================== Page header ====================== */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.page-header .subtitle { color: var(--text-muted); font-size: 14px; margin-top: 2px; }
.page-header .actions { display: flex; gap: 8px; align-items: center; }

/* ====================== Buttons ====================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: var(--transition);
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
}
.btn:hover { background: #f8fafc; border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #047857; border-color: #047857; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: #f1f5f9; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 14px; font-weight: 600; }
.btn-block { width: 100%; justify-content: center; }

/* ====================== Forms ====================== */

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  width: 100%;
  transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }

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

label.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; letter-spacing: -0.005em; }

/* ====================== Cards ====================== */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-xs);
}
.card h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

/* ====================== Stats grid ====================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.stat:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); font-weight: 700; }
.stat .value { font-size: 30px; font-weight: 700; margin-top: 6px; letter-spacing: -0.025em; line-height: 1.05; color: var(--text); }
.stat .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat.danger .value { color: var(--danger); }
.stat.success .value { color: var(--success); }
.stat.warning .value { color: var(--warning); }
.stat.primary .value { color: var(--primary); }

/* ====================== Toolbar ====================== */

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select { width: auto; max-width: 240px; }
.toolbar .spacer { flex: 1; }

/* ====================== Tables ====================== */

.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr { transition: background 0.1s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

tr.row-sent { background: var(--danger-bg); }
tr.row-sent:hover { background: var(--danger-strong-bg); }
tr.row-sent td { color: var(--danger-text); }
tr.row-sent .phone { text-decoration: line-through; }
tr.row-optout { background: #f3f4f6; }
tr.row-optout td { text-decoration: line-through; opacity: 0.7; }

/* ====================== Badges ====================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.5;
}
.badge-success { background: var(--success-bg); color: #065f46; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-strong-bg); color: var(--danger-text); }
.badge-info { background: var(--primary-light); color: #1e40af; }
.badge-muted { background: #f1f5f9; color: #475569; }

.region-LONG_ISLAND { background: #dbeafe; color: #1e3a8a; }
.region-NEW_JERSEY { background: #ede9fe; color: #5b21b6; }
.region-PENNSYLVANIA { background: #d1fae5; color: #064e3b; }
.region-NYC { background: #cffafe; color: #155e75; }

/* ====================== Bulk action bar ====================== */

.checkbox-cell { width: 40px; text-align: center; }
input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }

.bulk-bar {
  position: sticky;
  top: 12px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 10;
  box-shadow: var(--shadow-md);
}
.bulk-bar.active { display: flex; }
.bulk-bar .count { font-weight: 700; background: rgba(255,255,255,0.15); padding: 2px 10px; border-radius: 999px; }
.bulk-bar .btn { background: rgba(255,255,255,0.95); color: var(--text); border: none; }
.bulk-bar .btn:hover { background: #fff; }

/* ====================== Modal ====================== */

.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-bg.active { display: flex; animation: fadeIn 0.15s ease-out; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 26px;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.18s ease-out;
}
.modal h3 { margin-bottom: 18px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.modal .field { margin-bottom: 14px; }
.modal label, .modal .field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; letter-spacing: -0.005em; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ====================== Emergency stop ====================== */

.emergency-stop {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--danger);
  color: #fff;
  padding: 13px 22px;
  border-radius: 999px;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(220,38,38,0.35), 0 0 0 1px rgba(255,255,255,0.1) inset;
  z-index: 99;
  transition: var(--transition);
}
.emergency-stop:hover { background: #b91c1c; transform: translateY(-2px); box-shadow: 0 12px 28px rgba(220,38,38,0.45); }
.emergency-stop.active { background: var(--accent-gold); color: #78350f; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.7} }

/* ====================== Empty state ====================== */

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty .big { font-size: 36px; margin-bottom: 10px; }
.empty .title { font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* ====================== Number cards ====================== */

.number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}
.number-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  transition: var(--transition);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.number-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.number-card .phone { font-size: 19px; font-weight: 700; letter-spacing: -0.015em; }
.number-card .label { color: var(--text-muted); margin-top: 2px; font-size: 12.5px; }
.number-card .meta { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.number-card .meta .pill { background: #f1f5f9; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; color: var(--text-secondary); font-weight: 500; }
.number-card.status-active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--success); }
.number-card.status-paused::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--warning); }
.number-card.status-paused_high_optout::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--danger); }
.number-card.status-retired { opacity: 0.5; }
.number-card.status-retired::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--text-subtle); }

.progress {
  height: 6px;
  background: #f1f5f9;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill { height: 100%; background: var(--primary); transition: width 0.4s ease-out; border-radius: 3px; }
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* ====================== Flash ====================== */

.flash {
  position: fixed;
  top: 22px;
  right: 22px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  z-index: 200;
  display: none;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}
.flash.success { background: var(--success); }
.flash.danger { background: var(--danger); }
.flash.show { display: block; animation: slideIn 0.25s ease-out; }

/* ====================== Login ====================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #0b1220 0%, #1e293b 100%);
}
.login-box {
  background: #fff;
  padding: 36px 32px;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 380px;
  max-width: 92vw;
}
.login-box .brand-stack { text-align: center; margin-bottom: 24px; }
.login-box .brand-stack svg { width: 64px; height: 64px; margin-bottom: 12px; }
.login-box .brand-stack h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.025em; }
.login-box .brand-stack .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ====================== Misc helpers ====================== */

.dry-run-banner {
  background: linear-gradient(135deg, var(--accent-gold-light) 0%, #fed7aa 100%);
  color: #92400e;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  border: 1px solid rgba(251,191,36,0.35);
}

.template-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: var(--transition);
}
.template-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.template-card .header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; gap: 8px; flex-wrap: wrap; }
.template-card .name { font-weight: 600; font-size: 14px; }
.template-card .body { color: var(--text-secondary); font-size: 13px; line-height: 1.55; white-space: pre-wrap; }
.template-card .actions { margin-top: 10px; display: flex; gap: 6px; }

.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
.checkbox-group label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; padding: 6px; border-radius: var(--radius-xs); }
.checkbox-group label:hover { background: #f8fafc; }

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 18px 0 8px 0;
}

.divider { height: 1px; background: var(--border); margin: 18px 0; }
.text-mono { font-family: var(--font-mono); font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-sm { font-size: 12.5px; }

.pagination { display: flex; gap: 6px; justify-content: center; padding: 16px; align-items: center; }
.pagination .info { color: var(--text-muted); font-size: 13px; margin: 0 12px; }

.preview-box {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ====================== Responsive ====================== */

@media (max-width: 920px) {
  .sidebar { width: 64px; padding: 16px 6px; }
  .sidebar .brand { padding: 4px 6px 14px 6px; justify-content: center; }
  .sidebar .brand-text, .sidebar nav a span, .sidebar .footer, .sidebar .section-label { display: none; }
  .sidebar nav a { justify-content: center; padding: 9px 6px; }
  .sidebar nav a svg { margin: 0; }
  .main { padding: 18px 18px 80px 18px; }
  .page-header h1 { font-size: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat .value { font-size: 22px; }
  .toolbar { gap: 6px; }
  .toolbar input, .toolbar select { font-size: 13px; }
  th, td { padding: 9px 10px; font-size: 12.5px; }
  .emergency-stop { padding: 11px 16px; font-size: 12px; }
}

/* PWA standalone tweaks */
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  body { padding-top: env(safe-area-inset-top); }
  .main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ====================== Avatar ====================== */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}

/* ====================== iMessage-style chat ====================== */
.imsg-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
  height: calc(100vh - 130px);
}
.imsg-list {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  box-shadow: var(--shadow-xs);
}
.imsg-list .search-box {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 1;
}
.imsg-list .search-box input { background: var(--bg); border: none; }
.imsg-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  gap: 12px;
  align-items: center;
}
.imsg-row:hover { background: #fafbfc; }
.imsg-row.active { background: var(--primary-light); }
.imsg-row .info { flex: 1; min-width: 0; }
.imsg-row .name-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.imsg-row .name { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.imsg-row .name.unread::before { content: '•'; color: var(--primary); margin-right: 4px; font-size: 18px; line-height: 0; }
.imsg-row .when { color: var(--text-subtle); font-size: 11.5px; flex-shrink: 0; }
.imsg-row .preview { color: var(--text-muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imsg-row .row-meta { display: flex; gap: 6px; margin-top: 4px; align-items: center; }
.imsg-row .badge { font-size: 9.5px; padding: 1px 6px; }

.imsg-thread {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.imsg-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg-elev);
}
.imsg-header .header-info { flex: 1; min-width: 0; }
.imsg-header .name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.imsg-header .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.imsg-header .actions { display: flex; gap: 6px; }

.imsg-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 20px 16px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.imsg-time-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 12px 0 4px 0;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.imsg-bubble {
  max-width: 76%;
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.42;
  word-wrap: break-word;
  position: relative;
  margin-top: 2px;
}
.imsg-bubble.in {
  background: #e9eaee;
  color: #0a0e1a;
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}
.imsg-bubble.out {
  background: #007aff;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.imsg-bubble.dry {
  background: var(--warning-bg);
  color: #78350f;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.imsg-bubble.failed {
  background: var(--danger-bg);
  color: var(--danger-text);
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.imsg-bubble + .imsg-bubble.same { border-radius: 18px; margin-top: 2px; }
.imsg-bubble.in.same:not(:last-child) { border-bottom-left-radius: 18px; }
.imsg-bubble.in.same:last-child { border-bottom-left-radius: 6px; }
.imsg-bubble.out.same:not(:last-child) { border-bottom-right-radius: 18px; }
.imsg-bubble.out.same:last-child { border-bottom-right-radius: 6px; }
.imsg-bubble .bubble-meta {
  font-size: 10.5px;
  opacity: 0.7;
  margin-top: 3px;
  font-weight: 500;
}

.imsg-input-bar {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.imsg-input-bar .input-wrap {
  flex: 1;
  background: #f1f3f5;
  border-radius: 22px;
  padding: 8px 14px;
  display: flex;
  align-items: flex-end;
  border: 1px solid transparent;
  transition: var(--transition);
}
.imsg-input-bar .input-wrap:focus-within { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.imsg-input-bar textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 15px;
  line-height: 1.4;
  padding: 4px 0;
  min-height: 22px;
  max-height: 120px;
  font-family: inherit;
  width: 100%;
}
.imsg-input-bar .send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.imsg-input-bar .send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
.imsg-input-bar .send-btn:disabled { background: var(--text-subtle); cursor: not-allowed; }
.imsg-input-bar .send-btn svg { width: 18px; height: 18px; }

.imsg-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted);
  flex-direction: column; gap: 8px;
  padding: 40px;
  text-align: center;
}
.imsg-empty svg { width: 48px; height: 48px; opacity: 0.3; }

@media (max-width: 920px) {
  .imsg-grid { grid-template-columns: 1fr; height: calc(100vh - 100px); position: relative; }
  .imsg-grid.has-active .imsg-list { display: none; }
  .imsg-grid:not(.has-active) .imsg-thread { display: none; }
  .imsg-header .back-btn { display: inline-flex !important; }
}
.imsg-header .back-btn { display: none; }

/* ====================== Region tag big — for number cards ====================== */
.region-banner {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ====================== Variable insertion buttons ====================== */
.var-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.var-btn {
  background: var(--primary-light);
  color: #1e40af;
  border: 1px solid #bfdbfe;
  padding: 4px 9px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 500;
  transition: var(--transition);
}
.var-btn:hover { background: #bfdbfe; transform: translateY(-1px); }
.var-btn.spintax { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.var-btn.spintax:hover { background: #fde68a; }

/* ====================== Better contacts table ====================== */
.contact-row .name-cell { display: flex; align-items: center; gap: 10px; }
.contact-row .name-cell .name-text { font-weight: 600; color: var(--text); }
.contact-row .city-state { color: var(--text-muted); font-size: 12.5px; }

