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

/* ── Design tokens — mirrors main SoulPilates app ────────────────────────── */
:root {
  --sp-brand:            #C97B4B;
  --sp-brand-dark:       #B06835;
  --sp-brand-soft:       rgba(201, 123, 75, 0.08);
  --sp-brand-glow:       rgba(201, 123, 75, 0.18);

  --sp-dark:             #2C2C2C;
  --sp-white:            #FFFFFF;
  --sp-bg:               #F6F5F2;
  --sp-surface:          #FFFFFF;
  --sp-border:           #E8E5E0;
  --sp-border-strong:    #D4D0CA;

  --sp-text-primary:     #1A1A1A;
  --sp-text-secondary:   #5C5C5C;
  --sp-text-muted:       #9B9B9B;

  --sp-success:          #3D8C5C;
  --sp-warning:          #D4930D;
  --sp-danger:           #C44B4B;

  --sp-radius-sm:        6px;
  --sp-radius-md:        10px;
  --sp-radius-lg:        14px;
  --sp-radius-full:      999px;

  --sp-shadow-sm:        0 1px 3px rgba(0,0,0,0.04);
  --sp-shadow-md:        0 4px 12px rgba(0,0,0,0.06);

  --sp-transition-base:  0.18s ease;

  /* Inbox-specific */
  --inbox-sidebar-w:     280px;
  --inbox-compose-h:     140px;
  --inbox-topbar-h:      56px;

  /* Channel brand colours */
  --wa-green:     #25D366;
  --fb-blue:      #0866FF;
  --ig-pink:      #E1306C;
  --tt-black:     #010101;
  --tt-red:       #FE2C55;
}

[data-theme="dark"] {
  --sp-bg:               #161614;
  --sp-surface:          #1E1D1B;
  --sp-border:           #2E2C28;
  --sp-border-strong:    #3E3B36;
  --sp-text-primary:     #F0EDE8;
  --sp-text-secondary:   #A8A49E;
  --sp-text-muted:       #6B6862;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--sp-bg);
  color: var(--sp-text-primary);
  height: 100%;
  overflow: hidden;
}

/* ── Layout shell ────────────────────────────────────────────────────────── */
.inbox-shell {
  display: grid;
  grid-template-columns: var(--inbox-sidebar-w) 1fr;
  grid-template-rows: var(--inbox-topbar-h) 1fr;
  height: 100vh;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--sp-surface);
  border-bottom: 1px solid var(--sp-border);
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  color: var(--sp-text-primary);
}
.topbar-logo-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--sp-brand);
}
.topbar-title { color: var(--sp-text-secondary); font-weight: 400; }
.topbar-spacer { flex: 1; }
.topbar-badge {
  background: var(--sp-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--sp-radius-full);
  min-width: 20px;
  text-align: center;
}
.topbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sp-text-secondary);
  padding: 6px;
  border-radius: var(--sp-radius-sm);
  transition: background var(--sp-transition-base), color var(--sp-transition-base);
}
.topbar-btn:hover { background: var(--sp-brand-soft); color: var(--sp-brand); }

/* ── Conversation sidebar ─────────────────────────────────────────────────── */
.conv-sidebar {
  border-right: 1px solid var(--sp-border);
  background: var(--sp-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.conv-search {
  padding: 12px;
  border-bottom: 1px solid var(--sp-border);
}
.conv-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-md);
  background: var(--sp-bg);
  color: var(--sp-text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--sp-transition-base);
}
.conv-search input:focus { border-color: var(--sp-brand); }

.channel-filters {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--sp-border);
  overflow-x: auto;
}
.channel-filter-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-full);
  background: none;
  font-size: 12px;
  cursor: pointer;
  color: var(--sp-text-secondary);
  transition: all var(--sp-transition-base);
  display: flex;
  align-items: center;
  gap: 5px;
}
.channel-filter-btn.active,
.channel-filter-btn:hover { border-color: var(--sp-brand); color: var(--sp-brand); background: var(--sp-brand-soft); }
.channel-filter-btn.ch-wa.active  { --sp-brand: var(--wa-green); }
.channel-filter-btn.ch-fb.active  { --sp-brand: var(--fb-blue); }
.channel-filter-btn.ch-ig.active  { --sp-brand: var(--ig-pink); }
.channel-filter-btn.ch-tt.active  { --sp-brand: var(--tt-red); }

.conv-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--sp-border);
  transition: background var(--sp-transition-base);
  position: relative;
}
.conv-item:hover { background: var(--sp-bg); }
.conv-item.active { background: var(--sp-brand-soft); }
.conv-item.unread .conv-name { font-weight: 600; }

.conv-avatar {
  position: relative;
  flex-shrink: 0;
}
.conv-avatar-img {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--sp-brand-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--sp-brand);
  overflow: hidden;
}
.conv-avatar-img.placeholder { background: var(--sp-brand-soft); color: var(--sp-brand); }
.channel-badge {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--sp-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px;
}
.channel-badge.wa { background: var(--wa-green); }
.channel-badge.fb { background: var(--fb-blue); }
.channel-badge.ig { background: var(--ig-pink); }
.channel-badge.tt { background: var(--tt-black); }

.conv-body { flex: 1; min-width: 0; }
.conv-header { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; margin-bottom: 3px; }
.conv-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--sp-text-muted); flex-shrink: 0; }
.conv-snippet { font-size: 12px; color: var(--sp-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-unread-badge {
  background: var(--sp-brand);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: var(--sp-radius-full);
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}

/* ── Message thread panel ─────────────────────────────────────────────────── */
.thread-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sp-bg);
}

.thread-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--inbox-topbar-h);
  background: var(--sp-surface);
  border-bottom: 1px solid var(--sp-border);
  flex-shrink: 0;
}
.thread-header-info { flex: 1; min-width: 0; }
.thread-header-name { font-weight: 600; font-size: 15px; }
.thread-header-meta { font-size: 12px; color: var(--sp-text-muted); }
.thread-header-actions { display: flex; gap: 6px; }
.thread-action-btn {
  padding: 7px 14px;
  border-radius: var(--sp-radius-md);
  border: 1px solid var(--sp-border);
  background: none;
  font-size: 13px;
  cursor: pointer;
  color: var(--sp-text-secondary);
  transition: all var(--sp-transition-base);
}
.thread-action-btn:hover { border-color: var(--sp-brand); color: var(--sp-brand); background: var(--sp-brand-soft); }
.thread-action-btn.close-btn { color: var(--sp-danger); }
.thread-action-btn.close-btn:hover { border-color: var(--sp-danger); background: rgba(196,75,75,0.06); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--sp-border-strong); border-radius: 2px; }

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.msg-row.outbound { flex-direction: row-reverse; }

.msg-bubble {
  max-width: 68%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}
.msg-row.inbound .msg-bubble {
  background: var(--sp-surface);
  border: 1px solid var(--sp-border);
  border-bottom-left-radius: 4px;
}
.msg-row.outbound .msg-bubble {
  background: var(--sp-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 10px;
  color: var(--sp-text-muted);
  flex-shrink: 0;
  margin-bottom: 4px;
}
.msg-row.outbound .msg-time { text-align: right; }
.msg-status {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  text-align: right;
  margin-top: 2px;
}
.msg-staff-label {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  margin-bottom: 3px;
  font-weight: 500;
}

/* attachment previews */
.msg-image { max-width: 240px; border-radius: 10px; display: block; cursor: pointer; }
.msg-image:hover { opacity: 0.92; }
.msg-file {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.06);
  border-radius: var(--sp-radius-md);
  text-decoration: none;
  color: inherit;
  font-size: 13px;
}
.msg-file:hover { background: rgba(0,0,0,0.1); }
.msg-caption { font-size: 12px; margin-top: 4px; opacity: 0.85; }

/* date separator */
.date-separator {
  text-align: center;
  margin: 10px 0;
  position: relative;
}
.date-separator::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 1px solid var(--sp-border);
}
.date-separator span {
  background: var(--sp-bg);
  padding: 0 12px;
  position: relative;
  font-size: 11px;
  color: var(--sp-text-muted);
}

/* ── Compose box ─────────────────────────────────────────────────────────── */
.compose-area {
  flex-shrink: 0;
  background: var(--sp-surface);
  border-top: 1px solid var(--sp-border);
  padding: 12px 16px;
}
.compose-attachments-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.compose-attachment-thumb {
  position: relative;
  width: 60px; height: 60px;
  border-radius: var(--sp-radius-sm);
  overflow: hidden;
  border: 1px solid var(--sp-border);
}
.compose-attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.compose-attachment-thumb-remove {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none; cursor: pointer;
  border-radius: 50%;
  width: 16px; height: 16px;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
}
.compose-file-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--sp-bg);
  border-radius: var(--sp-radius-sm);
  border: 1px solid var(--sp-border);
  font-size: 12px;
}
.compose-file-item button { background: none; border: none; cursor: pointer; color: var(--sp-text-muted); font-size: 14px; }

.compose-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.compose-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-lg);
  background: var(--sp-bg);
  color: var(--sp-text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  line-height: 1.5;
  overflow-y: auto;
  transition: border-color var(--sp-transition-base);
}
.compose-input:focus { border-color: var(--sp-brand); }
.compose-input::placeholder { color: var(--sp-text-muted); }

.compose-icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-md);
  background: none;
  cursor: pointer;
  color: var(--sp-text-secondary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--sp-transition-base);
}
.compose-icon-btn:hover { border-color: var(--sp-brand); color: var(--sp-brand); background: var(--sp-brand-soft); }

.compose-send-btn {
  width: 38px; height: 38px;
  border: none;
  border-radius: var(--sp-radius-md);
  background: var(--sp-brand);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--sp-transition-base);
}
.compose-send-btn:hover { background: var(--sp-brand-dark); }
.compose-send-btn:disabled { background: var(--sp-border-strong); cursor: not-allowed; }

/* Templates dropdown */
.templates-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--sp-surface);
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-md);
  box-shadow: var(--sp-shadow-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
}
.template-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--sp-border);
  transition: background var(--sp-transition-base);
}
.template-item:last-child { border-bottom: none; }
.template-item:hover { background: var(--sp-brand-soft); }
.template-item-name { font-weight: 500; font-size: 13px; margin-bottom: 2px; }
.template-item-preview { font-size: 12px; color: var(--sp-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Empty states ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  color: var(--sp-text-muted);
}
.empty-state-icon { font-size: 48px; }
.empty-state-title { font-size: 16px; font-weight: 500; color: var(--sp-text-secondary); }
.empty-state-sub { font-size: 13px; text-align: center; max-width: 260px; }

/* ── Channels settings modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--sp-surface);
  border-radius: var(--sp-radius-lg);
  box-shadow: var(--sp-shadow-md);
  padding: 28px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--sp-text-muted); }

/* ── Channel card in settings ────────────────────────────────────────────── */
.channel-card {
  border: 1px solid var(--sp-border);
  border-radius: var(--sp-radius-md);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.channel-card-icon { font-size: 24px; width: 36px; text-align: center; }
.channel-card-body { flex: 1; }
.channel-card-name { font-weight: 500; font-size: 14px; }
.channel-card-status { font-size: 12px; color: var(--sp-text-muted); }
.channel-card-status.connected { color: var(--sp-success); }
.channel-connect-btn {
  padding: 7px 14px;
  border-radius: var(--sp-radius-md);
  border: 1px solid var(--sp-border);
  background: none;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--sp-transition-base);
}
.channel-connect-btn:hover { border-color: var(--sp-brand); color: var(--sp-brand); }
.channel-connect-btn.danger:hover { border-color: var(--sp-danger); color: var(--sp-danger); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--sp-border-strong); border-radius: 2px; }

/* ── Loading spinner ─────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--sp-border);
  border-top-color: var(--sp-brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: auto;
}

/* ── Connection indicator ────────────────────────────────────────────────── */
.connection-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--sp-success);
  flex-shrink: 0;
}
.connection-dot.disconnected { background: var(--sp-danger); }
