/* Connect Hub — Design System (extracted from AI Closer platform) */
:root {
  --text-muted: #888;
  --bg:       #F2F4F8;
  --bg2:      #FFFFFF;
  --bg3:      #E8ECF1;
  --bg4:      #D8DEE6;
  --border:   #D0D7E0;
  --text:     #1D2433;
  --text2:    #5A6578;
  --text3:    #8B95A5;
  --accent:   #3B82F6;
  --accent2:  #2563EB;
  --green:    #16A34A;
  --red:      #DC2626;
  --amber:    #CA8A04;
  --purple:   #7C3AED;
  --cyan:     #0891B2;
  --rail-w:   160px;
  --radius:   10px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  /* These get overridden by tenant config at runtime */
  --sidebar-gradient: linear-gradient(135deg, #3B82F6, #7C3AED);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; background: var(--bg); color: var(--text); font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius); border: none;
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent2); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg4); }
.btn-ghost  { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px;
  padding: 9px 12px; outline: none; transition: border-color .15s; font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 90px; }
.form-help { font-size: 0.78rem; color: var(--text3); margin-top: 4px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
}
.card-sm { padding: 16px; }
.card-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin-bottom: 10px; }
.card-sub   { font-size: 0.83rem; color: var(--text2); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 0 20px; }
.container-sm { max-width: 520px; margin: 0 auto; padding: 0 20px; }
.container-wide { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-shell { height: 100vh; display: flex; }

/* ── App Sidebar ─────────────────────────────────────────────────────────── */
.app-sidebar {
  width: var(--rail-w); min-height: 100vh;
  background: var(--bg2); border-right: 1px solid var(--border);
  padding: 16px 8px; display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 16px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.logo-text {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--sidebar-gradient);
  color: #fff; font-size: 0.85rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-name { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 8px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text2);
  font-size: 14px; cursor: pointer; transition: all .12s;
  text-decoration: none;
}
.nav-item:hover, .nav-item.active { background: var(--bg3); color: var(--text); text-decoration: none; }

/* ── Main content area ───────────────────────────────────────────────────── */
.app-main { flex: 1; overflow-y: auto; padding: 12px 16px; min-width: 0; }

/* ── Page area ───────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.page-sub   { color: var(--text2); font-size: 0.88rem; margin-bottom: 24px; }

/* ── Grid layouts ────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { font-size: 0.78rem; color: var(--text2); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-value.cyan { color: var(--cyan); }
.stat-value.purple { color: var(--purple); }
.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }

/* ── Status pill ─────────────────────────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 20px; padding: 3px 10px; font-size: 0.75rem; font-weight: 600; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.live { background: rgba(63,185,80,.12); color: var(--green); }
.pill.testing { background: rgba(210,153,34,.12); color: var(--amber); }
.pill.pending { background: rgba(248,81,73,.12); color: var(--red); }
.pill.approved { background: rgba(63,185,80,.12); color: var(--green); }

/* ── Chat ────────────────────────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 56px - 56px); }
.chat-log  { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 18px; font-size: 0.85rem; line-height: 1.4; }
.bubble.user      { background: var(--accent2); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.assistant { background: var(--bg3); align-self: flex-start; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble-sources { font-size: 0.72rem; color: var(--text3); margin-top: 6px; }
.bubble-time { font-size: 0.7rem; color: var(--text3); margin-top: 4px; }
.chat-input-row { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.chat-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 10px 14px; font-size: 14px; outline: none; }
.chat-input:focus { border-color: var(--accent); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-green  { background: rgba(63,185,80,.15); color: var(--green); }
.badge-red    { background: rgba(248,81,73,.15);  color: var(--red); }
.badge-amber  { background: rgba(210,153,34,.15); color: var(--amber); }
.badge-gray   { background: var(--bg3); color: var(--text3); border: 1px solid var(--border); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-area, #toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 18px; font-size: 14px;
  box-shadow: var(--shadow); animation: slideIn .2s ease; min-width: 220px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.section-label { font-size: 0.78rem; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.empty { text-align: center; padding: 60px 20px; color: var(--text3); font-size: 0.92rem; }
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .4; }
.empty h3 { color: var(--text2); font-size: 1rem; margin-bottom: 6px; }
.empty p { font-size: 0.85rem; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
.section-gap { margin-bottom: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap { display: flex; gap: 10px; align-items: center; }
.mt-16 { margin-top: 16px; }
.text-sm { font-size: 0.8rem; color: var(--text2); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
td { padding: 12px 14px; border-bottom: 1px solid rgba(0,0,0,.06); color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0,0,0,.03); }
.row-link { cursor: pointer; }

/* ── Info banner ─────────────────────────────────────────────────────────── */
.info-banner { background: rgba(59,130,246,.06); border: 1px solid rgba(59,130,246,.15); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; font-size: 0.875rem; color: var(--text2); line-height: 1.6; }
.info-banner strong { color: var(--text); }

/* ── Data tables ─────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.data-table th {
  text-align: left; color: var(--text3); font-weight: 500;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 7px 8px; border-bottom: 1px solid var(--bg3); color: var(--text2); }
.data-table tr:last-child td { border-bottom: none; }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.mode-toggle { display: flex; align-items: center; gap: 10px; }
.mode-toggle label { font-size: 0.85rem; color: var(--text2); }
.switch { position: relative; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--border); border-radius: 24px; cursor: pointer; transition: background .2s; }
.slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--text3); border-radius: 50%; transition: transform .2s, background .2s; }
input:checked + .slider { background: rgba(63,185,80,.2); border-color: var(--green); }
input:checked + .slider::before { transform: translateX(20px); background: var(--green); }
.switch.switch-sm { transform: scale(0.75); transform-origin: left; }

/* ── Tab buttons (shared) ───────────────────────────────────────────────── */
.tab-btn { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text3); padding: 8px 16px; cursor: pointer; font-size: 0.88rem; font-weight: 500; transition: color .15s, border-color .15s; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }

/* ── Back button ─────────────────────────────────────────────────────────── */
.back-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--text2); font-size: 0.85rem; cursor: pointer; margin-bottom: 20px; }
.back-btn:hover { color: var(--text); }

/* ── Draft / queued message bubble ──────────────────────────────────────── */
.bubble-draft { border: 2px dashed var(--border) !important; opacity: .75; }
.bubble-draft-label {
  font-size: .7rem; color: var(--text3);
  display: block; margin-top: 2px;
}

/* ── Progress bar (from momentum) ────────────────────────────────────────── */
.mo-progress-track { height: 5px; background: var(--bg4); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.mo-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 3px; transition: width .3s; }

/* ── Queue cards ─────────────────────────────────────────────────────────── */
.queue-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.queue-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.queue-contact { font-weight: 600; font-size: 0.95rem; }
.queue-tenant { font-size: 0.75rem; color: var(--cyan); margin-top: 2px; }
.queue-time { font-size: 0.75rem; color: var(--text3); }
.queue-inbound { background: var(--bg3); border-radius: 7px; padding: 10px 12px; font-size: 0.875rem; color: var(--text2); margin-bottom: 10px; }
.queue-inbound-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text3); margin-bottom: 4px; }
.queue-draft-wrap { position: relative; }
.queue-draft { width: 100%; background: rgba(59,130,246,.06); border: 1px solid rgba(59,130,246,.20); border-radius: 7px; padding: 10px 12px; color: var(--text); font-size: 0.9rem; resize: vertical; min-height: 64px; font-family: inherit; outline: none; }
.queue-draft:focus { border-color: var(--accent); }
.queue-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── Unified Conversation Layout ────────────────────────────────────────── */
.unified-layout {
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  height: calc(100vh - 60px);
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.unified-contacts-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  overflow: hidden;
}

.unified-contacts-header {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.unified-contacts-list {
  flex: 1;
  overflow-y: auto;
}

.unified-contact-item {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  align-items: center;
}
.unified-contact-item:hover { background: var(--bg3); }
.unified-contact-item.selected { background: var(--bg3); border-left: 3px solid var(--cyan); }

.unified-contact-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
}
.cm-item:hover { background: var(--bg3); }

.unified-contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text2);
  flex-shrink: 0;
}

.unified-contact-info { flex: 1; min-width: 0; }
.unified-contact-name { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unified-contact-preview { font-size: 0.78rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.unified-contact-meta { text-align: right; flex-shrink: 0; }
.unified-contact-time { font-size: 0.7rem; color: var(--text3); }
.unified-contact-channels { display: flex; gap: 3px; justify-content: flex-end; margin-top: 3px; }

.channel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Thread Panel */
.unified-thread-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
}

.unified-thread-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text3);
  text-align: center;
}
.unified-thread-empty h3 { color: var(--text2); margin: 0 0 8px; }
.unified-thread-empty p { font-size: 0.85rem; }

.unified-thread-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.unified-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.unified-compose-area {
  border-top: 1px solid var(--border);
  padding: 8px 14px;
}

.channel-tabs {
  display: flex;
  gap: 0;
}
.channel-tab {
  padding: 6px 12px;
  border-radius: 0;
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text3);
  transition: all 0.15s;
  font-weight: 500;
}
.channel-tab:hover { color: var(--text); }
.channel-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: transparent; }

.unified-compose-row {
  display: flex;
  gap: 8px;
}

.unified-compose-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.channel-badge-inline {
  font-size: 0.7rem;
  font-weight: 600;
}

/* iPhone-style message bubbles */
.bubble.imessage-out { background: #007AFF; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.imessage-out .bubble-time { color: rgba(255,255,255,.65); }
.bubble.sms-out { background: #34C759; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.sms-out .bubble-time { color: rgba(255,255,255,.65); }
.bubble.whatsapp-out { background: #25D366; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.whatsapp-out .bubble-time { color: rgba(255,255,255,.65); }
.bubble.email-out { background: #5A6978; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.email-out .bubble-time { color: rgba(255,255,255,.65); }
.bubble.inbound { background: #E9E9EB; color: #1c1c1e; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.inbound .bubble-time { color: #8e8e93; }

/* Activity Panel */
.unified-activity-panel {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  overflow: hidden;
}

.unified-activity-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.unified-activity-body {
  flex: 1;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.activity-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }
.activity-content { flex: 1; min-width: 0; }
.activity-title { font-size: 0.82rem; font-weight: 500; }
.activity-detail { font-size: 0.75rem; color: var(--text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.activity-time { font-size: 0.7rem; color: var(--text3); margin-top: 3px; }

/* Notification Bell */
.notif-bell-wrap {
  position: relative;
  margin-left: 12px;
}

.notif-bell-btn {
  position: relative;
  padding: 6px;
}

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.notif-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  width: 340px;
  max-height: 420px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 300;
  overflow: hidden;
}

.notif-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.notif-dropdown-body {
  overflow-y: auto;
  max-height: 360px;
}

.notif-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  align-items: flex-start;
}
.notif-item:hover { background: var(--bg3); }
.notif-icon { font-size: 1.2rem; flex-shrink: 0; }
.notif-content { flex: 1; min-width: 0; }
.notif-title { font-size: 0.82rem; font-weight: 500; }
.notif-preview { font-size: 0.75rem; color: var(--text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-time { font-size: 0.7rem; color: var(--text3); margin-top: 3px; }

/* Responsive: collapse activity panel on small screens */
@media (max-width: 900px) {
  .unified-layout { grid-template-columns: 220px 1fr; }
  .unified-activity-panel { display: none; }
}
@media (max-width: 768px) {
  .unified-layout { grid-template-columns: 1fr; }
  .unified-contacts-panel { max-height: 200px; }
  .app-sidebar { display: none; }
  .app-main { padding: 16px; }
}
