/* ── ODIV Inbox — BASE / LAYOUT LAYER ───────────────────────────────────────
   Uses design tokens from /css/variables.css.
   Safe-area insets for iOS notch + home indicator.

   ⚠️  This is the FOUNDATIONAL layout layer for the v2 PWA. It declares the
   structural properties (position, display, flex, overflow, …) that the
   v2 polish layer (/inbox/v2/css/inbox-v2.css) builds on top of. Both
   files load on /inbox/v2/index.html in this order: v1 first, v2 second.

   Editing rules (#193, post-mortem 2026-04-17):
     - DO NOT delete a structural rule here without first checking that
       v2 either redeclares it OR doesn't depend on it. The bug pattern
       that bit us was the OPPOSITE direction: v2 declared a partial
       override that silently inherited a stale v1 structural property.
       But removing v1 rules cold has the same risk.
     - For new component styling, ADD to inbox-v2.css instead. v1 should
       only change to fix bugs in load-bearing layout.

   The future Vite migration (#194) will collapse this file into the v2
   source tree — until then, treat both files as one logical stylesheet
   split across two physical paths.
─────────────────────────────────────────────────────────────────────────── */

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --inbox-header-h: calc(56px + var(--safe-top));
  --inbox-nav-h:    calc(60px + var(--safe-bottom));
  --inbox-composer-h: calc(60px + var(--safe-bottom));
}

/* ── Reset ──────────────────────────────────────────────────────────────── */

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

body.dark-theme {
  margin: 0;
  padding: 0;
  background: var(--bg-dark, #0f1117);
  color: var(--text-primary, #e8ecf1);
  font-family: var(--font-sans, Inter, system-ui, sans-serif);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* PWA: no scroll on body, only within screens */
  height: 100dvh;
}

/* ── Screen base ────────────────────────────────────────────────────────── */

.inbox-screen {
  /* Pinned to the VISUAL viewport (not the layout viewport) so the
     header stays anchored at the visible top and the composer at the
     visible bottom — even when the on-screen keyboard reduces the
     visible area on iOS Safari. The custom properties below are
     written by services/keyboard-aware.js using visualViewport. They
     fall back to 100dvh + offset:0 on browsers without
     window.visualViewport (none in our supported set as of 2026). */
  position: fixed;
  top: var(--kbd-app-offset-top, 0);
  left: 0;
  right: 0;
  width: 100%;
  height: var(--kbd-app-height, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--bg-dark, #0f1117);
  overflow: hidden;
}

/* ── Init screen ────────────────────────────────────────────────────────── */

.inbox-screen-init {
  align-items: center;
  justify-content: center;
}

.inbox-init-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.inbox-init-logo {
  border-radius: 20px;
  box-shadow: 0 0 32px rgba(37, 211, 102, 0.25);
}

/* ── Spinner ────────────────────────────────────────────────────────────── */

.inbox-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(37, 211, 102, 0.2);
  border-top-color: #25D366;
  border-radius: 50%;
  animation: inbox-spin 0.8s linear infinite;
}

@keyframes inbox-spin { to { transform: rotate(360deg); } }
@keyframes inbox-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Header ─────────────────────────────────────────────────────────────── */

.inbox-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(12px + var(--safe-top)) 12px 12px;
  background: var(--bg-surface, #141720);
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
  min-height: var(--inbox-header-h);
  z-index: 10;
}

.inbox-header-logo {
  border-radius: 8px;
  flex-shrink: 0;
}

.inbox-header-title {
  flex: 1;
  font-family: var(--font-display, Outfit, sans-serif);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary, #e8ecf1);
}

.inbox-header-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary, #8b95a5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.inbox-header-icon-btn:hover {
  background: var(--bg-card, #181b23);
  color: var(--text-primary, #e8ecf1);
}

.inbox-thread-contact {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inbox-thread-contact-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-thread-contact-sub {
  font-size: 0.75rem;
  color: var(--text-muted, #7d8799);
}

/* ── Login screen ───────────────────────────────────────────────────────── */

.inbox-login-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  gap: 1.5rem;
}

.inbox-login-brand {
  text-align: center;
}

.inbox-login-brand img {
  border-radius: 16px;
  box-shadow: 0 0 32px rgba(37, 211, 102, 0.25);
  margin-bottom: 1rem;
}

.inbox-login-title {
  font-family: var(--font-display, Outfit, sans-serif);
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  background: linear-gradient(135deg, #25D366, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.inbox-login-sub {
  color: var(--text-secondary, #8b95a5);
  margin: 0;
  font-size: 0.9rem;
}

.inbox-auth-card {
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--radius-lg, 12px);
  padding: 1.5rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.inbox-form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.inbox-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary, #8b95a5);
}

.inbox-input {
  background: var(--bg-surface, #141720);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--radius-md, 8px);
  color: var(--text-primary, #e8ecf1);
  font-size: 1rem;
  padding: 0.65rem 0.875rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.inbox-input:focus {
  border-color: #25D366;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.inbox-form-hint {
  font-size: 0.75rem;
  color: var(--text-muted, #7d8799);
}

/* OTP boxes */
.inbox-otp-sent-msg {
  text-align: center;
  color: var(--text-secondary, #8b95a5);
  font-size: 0.875rem;
  margin: 0;
}

.inbox-otp-boxes {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.25rem 0;
}

.inbox-otp-box {
  width: 44px;
  height: 52px;
  border-radius: var(--radius-md, 8px);
  border: 2px solid var(--glass-border, rgba(255,255,255,0.08));
  background: var(--bg-surface, #141720);
  color: var(--text-primary, #e8ecf1);
  font-size: 1.4rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.inbox-otp-box:focus {
  border-color: #25D366;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.2);
}

.inbox-otp-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.inbox-otp-timer {
  color: var(--text-muted, #7d8799);
}

.inbox-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md, 8px);
  color: #ef4444;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.inbox-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

.inbox-btn:active { transform: scale(0.97); }
.inbox-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.inbox-btn-primary {
  background: linear-gradient(135deg, #25D366, #10b981);
  color: #fff;
}

.inbox-btn-ghost {
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  color: var(--text-primary, #e8ecf1);
}

.inbox-btn-link {
  background: none;
  border: none;
  color: #25D366;
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0;
  text-align: center;
}

.inbox-btn-link:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Filter pills ───────────────────────────────────────────────────────── */

.inbox-filter-pills {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface, #141720);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.08));
}

.inbox-filter-pills::-webkit-scrollbar { display: none; }

.inbox-pill {
  background: none;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 20px;
  color: var(--text-secondary, #8b95a5);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.875rem;
  white-space: nowrap;
  transition: all 0.15s;
}

.inbox-pill-active {
  background: rgba(37, 211, 102, 0.15);
  border-color: rgba(37, 211, 102, 0.4);
  color: #25D366;
}

/* ── Banners ─────────────────────────────────────────────────────────────── */

.inbox-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.875rem;
  font-size: 0.8rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.inbox-banner-warning {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
  color: #f59e0b;
}

.inbox-banner-info {
  background: rgba(37, 211, 102, 0.08);
  border-bottom: 1px solid rgba(37, 211, 102, 0.2);
  color: #25D366;
}

/* ── Chat list ───────────────────────────────────────────────────────────── */

.inbox-chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--inbox-nav-h);
}

.inbox-loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem 1rem;
  color: var(--text-muted, #7d8799);
  font-size: 0.875rem;
}

.inbox-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem 1rem;
  color: var(--text-muted, #7d8799);
  font-size: 0.875rem;
}

/* Chat row */
.inbox-chat-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 0.875rem;
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}

.inbox-chat-row:hover, .inbox-chat-row:active {
  background: var(--bg-card, #181b23);
}

.inbox-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #128C7E, #25D366);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  font-family: var(--font-display, Outfit, sans-serif);
}

.inbox-chat-avatar img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
}

.inbox-chat-meta {
  flex: 1;
  min-width: 0;
}

.inbox-chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  margin-bottom: 0.2rem;
}

.inbox-chat-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary, #e8ecf1);
}

.inbox-chat-time {
  font-size: 0.7rem;
  color: var(--text-muted, #7d8799);
  flex-shrink: 0;
}

.inbox-chat-preview {
  font-size: 0.8rem;
  color: var(--text-secondary, #8b95a5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-chat-badges {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

.inbox-badge {
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
}

.inbox-badge-unread {
  background: #25D366;
  color: #fff;
}

.inbox-badge-unassigned {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #f59e0b;
}

.inbox-badge-bot {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
}

/* Pull-to-refresh spinner */
.ptr-spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(37, 211, 102, 0.3);
  border-top-color: #25D366;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s;
}

.ptr-spinning {
  animation: ptr-spin 0.7s linear infinite;
}

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
   PHASE 2 — Templates, Attachments, Reactions, Assign, Contact
   ═══════════════════════════════════════════════════════════════ */

/* ── Sheet common header ──────────────────────────────────────── */
.inbox-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem 0.75rem;
}
.inbox-sheet-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.inbox-sheet-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.inbox-sheet-close:hover { background: var(--bg-surface); }
.inbox-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--accent-green);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 1rem 0.5rem;
}

/* ── Template sheet ───────────────────────────────────────────── */
.inbox-template-sheet {
  max-height: 78vh;
  display: flex;
  flex-direction: column;
}
.inbox-template-search {
  margin: 0 1rem 0.75rem;
  flex-shrink: 0;
}
.inbox-template-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 0 0.5rem;
}
.inbox-template-row {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.15s;
}
.inbox-template-row:hover,
.inbox-template-row:active { background: var(--bg-surface); }
.inbox-template-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.inbox-template-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: monospace;
  word-break: break-all;
}
.inbox-template-cat {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.inbox-template-lang {
  font-size: 0.6rem;
  font-weight: 500;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted, #7d8799);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.tpl-cat-marketing {
  background: rgba(245,158,11,0.15);
  color: #f59e0b;
}
.tpl-cat-auth {
  background: rgba(99,102,241,0.15);
  color: #a5b4fc;
}
.tpl-cat-utility {
  background: rgba(37,211,102,0.12);
  color: var(--accent-green);
}
.inbox-template-preview-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
/* Template variable form */
#template-variables {
  padding: 0 1rem 1rem;
  overflow-y: auto;
}
.tpl-preview-header {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}
.tpl-preview-body {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  margin-bottom: 0.4rem;
  line-height: 1.5;
}
.tpl-preview-footer {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.tpl-preview-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.tpl-btn-chip {
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  color: var(--accent-green);
}
.inbox-template-preview {
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.tpl-var-section { margin-bottom: 0.75rem; }
.tpl-var-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 0.5rem;
}
#tpl-send-btn { width: 100%; margin-top: 0.5rem; }

/* ── Attach sheet ─────────────────────────────────────────────── */
.inbox-attach-sheet { max-height: 40vh; }
.inbox-attach-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 0.5rem 1rem 1.5rem;
}
.inbox-attach-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.inbox-attach-opt:hover,
.inbox-attach-opt:active {
  background: var(--bg-surface);
  border-color: var(--accent-green);
  color: var(--text-primary);
}
.inbox-attach-icon { font-size: 1.6rem; }

/* ── Emoji shelf (in composer) ────────────────────────────────── */
.inbox-emoji-shelf {
  display: none;
  flex-wrap: wrap;
  gap: 0.1rem;
  padding: 0.6rem 0.5rem;
  background: var(--bg-card);
  border-top: 1px solid var(--glass-border);
  max-height: 120px;
  overflow-y: auto;
}
.inbox-emoji-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: transform 0.1s;
}
.inbox-emoji-btn:active { transform: scale(1.3); }

/* ── Reaction shelf popup ─────────────────────────────────────── */
.inbox-reaction-shelf-popup {
  position: fixed;
  display: none;
  align-items: center;
  gap: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  padding: 0.4rem 0.6rem;
  z-index: 300;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  left: 50%;
  transform: translateX(-50%);
}
.inbox-react-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.15rem;
  border-radius: 50%;
  line-height: 1;
  transition: transform 0.1s;
}
.inbox-react-btn:active { transform: scale(1.4); }
.inbox-react-reply {
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border-radius: 99px;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
}
.inbox-reaction-shelf-sep {
  width: 1px;
  height: 24px;
  background: var(--glass-border);
  margin: 0 0.1rem;
}

/* ── Assign sheet ─────────────────────────────────────────────── */
.inbox-agent-list {
  overflow-y: auto;
  max-height: 50vh;
  padding-bottom: 1rem;
}
.inbox-agent-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.15s;
}
.inbox-agent-row:hover,
.inbox-agent-row:active { background: var(--bg-surface); }
.inbox-agent-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-green), #10b981);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.inbox-agent-info { display: flex; flex-direction: column; }
.inbox-agent-name { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.inbox-agent-email { font-size: 0.75rem; color: var(--text-muted); }

/* ── Contact info panel (slides in from right) ────────────────── */
.inbox-contact-panel {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  z-index: 250;
  display: none;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.inbox-contact-panel.inbox-panel-open {
  transform: translateX(0);
}
.inbox-contact-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0 2rem;
}
.inbox-contact-card {
  margin: 0.75rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}
.inbox-contact-card:first-child {
  text-align: center;
  padding: 1.5rem 1rem;
}
.inbox-contact-avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-green), #10b981);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  margin: 0 auto 0.75rem;
}
.inbox-contact-name-lg {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.25rem;
}
.inbox-contact-phone-lg {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0;
}
.inbox-contact-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
}
.inbox-tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.inbox-tag-chip {
  background: rgba(37,211,102,0.1);
  border: 1px solid rgba(37,211,102,0.25);
  color: var(--accent-green);
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
}
.inbox-cf-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--glass-border);
  gap: 0.5rem;
}
.inbox-cf-row:last-child { border-bottom: none; }
.inbox-cf-label { font-size: 0.8rem; color: var(--text-secondary); }
.inbox-cf-value { font-size: 0.8rem; color: var(--text-primary); text-align: right; word-break: break-word; max-width: 60%; }
.inbox-contact-actions .inbox-sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.9rem;
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  color: var(--text-primary);
  text-align: left;
}
.inbox-contact-actions .inbox-sheet-item:last-child { border-bottom: none; }
.inbox-contact-actions .inbox-sheet-item:hover { color: var(--accent-green); }

/* ── New chat sheet ───────────────────────────────────────────── */
.inbox-new-chat-sheet { max-height: 55vh; }

.inbox-load-more-btn {
  width: auto;
  padding: 0.5rem 1.5rem;
  font-size: 0.85rem;
  margin: 0.75rem auto;
  display: block;
}

/* ── Search bar ─────────────────────────────────────────────────────────── */

.inbox-search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface, #141720);
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}

.inbox-search-input {
  flex: 1;
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--radius-md, 8px);
  color: var(--text-primary, #e8ecf1);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  outline: none;
}

.inbox-search-input:focus {
  border-color: #25D366;
}

/* ── FAB ────────────────────────────────────────────────────────────────── */

.inbox-fab {
  position: absolute;
  bottom: calc(var(--inbox-nav-h) + 16px);
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366, #10b981);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 10;
}

.inbox-fab:active { transform: scale(0.92); }

/* ── Bottom navigation ───────────────────────────────────────────────────── */

.inbox-bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  background: var(--bg-surface, #141720);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}

.inbox-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0.6rem 0;
  background: none;
  border: none;
  color: var(--text-muted, #7d8799);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.15s;
}

.inbox-nav-active {
  color: #25D366;
}

/* ── Messages container ──────────────────────────────────────────────────── */

.inbox-messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0.5rem calc(var(--inbox-composer-h) + 0.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */

.inbox-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  margin-bottom: 0.15rem;
}

.inbox-bubble-wrap-out {
  align-self: flex-end;
  align-items: flex-end;
  margin-left: 15%;
}

.inbox-bubble-wrap-in {
  align-self: flex-start;
  align-items: flex-start;
  margin-right: 15%;
}

.inbox-bubble {
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
}

/* Outbound (sent by us) */
.inbox-bubble-out {
  background: linear-gradient(135deg, #128C7E, #25D366);
  border-radius: 12px 12px 4px 12px;
  color: #fff;
}

/* Inbound (from customer) */
.inbox-bubble-in {
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 12px 12px 12px 4px;
  color: var(--text-primary, #e8ecf1);
}

/* Internal note */
.inbox-bubble-note {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-md, 8px);
  color: var(--text-primary, #e8ecf1);
  width: 100%;
  max-width: 100%;
}

/* Quote / reply-to context box */
.inbox-bubble-quote {
  background: rgba(255,255,255,0.08);
  border-left: 3px solid #25D366;
  border-radius: var(--radius-sm, 6px);
  color: var(--text-secondary, #8b95a5);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  padding: 0.3rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bubble meta (timestamp + status) */
.inbox-bubble-meta {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.55);
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-top: 0.15rem;
}

.inbox-bubble-in .inbox-bubble-meta { color: var(--text-muted, #7d8799); }

.inbox-tick { font-size: 0.7rem; }
.inbox-tick-sent     { color: rgba(255,255,255,0.55); }
.inbox-tick-delivered{ color: rgba(255,255,255,0.55); }
.inbox-tick-read     { color: #25D366; }
.inbox-tick-failed   { color: #ef4444; }

/* Reaction badge */
.inbox-reaction-badge {
  position: absolute;
  bottom: -8px;
  right: -4px;
  background: var(--bg-surface, #141720);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.1));
  border-radius: 10px;
  font-size: 0.75rem;
  padding: 0.1rem 0.25rem;
}

/* System dividers */
.inbox-system-divider {
  text-align: center;
  color: var(--text-muted, #7d8799);
  font-size: 0.75rem;
  padding: 0.5rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inbox-system-divider::before, .inbox-system-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--glass-border, rgba(255,255,255,0.08));
}
.inbox-divider-assign { color: #60a5fa; }
.inbox-divider-assign::before, .inbox-divider-assign::after { background: rgba(96,165,250,0.2); }
.inbox-divider-done { color: #34d399; }
.inbox-divider-done::before, .inbox-divider-done::after { background: rgba(52,211,153,0.2); }
.inbox-divider-close { color: #9ca3af; }
.inbox-divider-close::before, .inbox-divider-close::after { background: rgba(156,163,175,0.15); }

/* ── Composer bar ────────────────────────────────────────────────────────── */

/* ── Channel selector ─────────────────────────────────────────────────── */

.inbox-channel-strip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-surface, #141720);
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  font-size: 0.72rem;
  position: absolute;
  bottom: var(--inbox-composer-h);
  left: 0;
  right: 0;
  z-index: 11;
}

.inbox-channel-label {
  color: var(--text-muted, #7d8799);
  flex-shrink: 0;
}

.inbox-channel-btn {
  background: rgba(37,211,102,0.1);
  border: 1px solid rgba(37,211,102,0.2);
  border-radius: 4px;
  color: #25D366;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.inbox-channel-picker {
  position: absolute;
  bottom: calc(var(--inbox-composer-h) + 30px);
  left: 0.5rem;
  right: 0.5rem;
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  z-index: 12;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
}

.inbox-channel-opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.75rem;
  background: none;
  border: none;
  color: var(--text-primary, #e8ecf1);
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,0.05));
}
.inbox-channel-opt:last-child { border-bottom: none; }
.inbox-channel-opt:hover { background: rgba(255,255,255,0.04); }
.inbox-channel-opt.active { color: #25D366; font-weight: 600; }

.inbox-composer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--bg-surface, #141720);
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  z-index: 10;
}

.inbox-composer-icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-secondary, #8b95a5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  margin-bottom: 1px;
}

.inbox-composer-icon-btn:hover { background: var(--bg-card, #181b23); color: var(--text-primary); }

.inbox-composer-input {
  flex: 1;
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 20px;
  color: var(--text-primary, #e8ecf1);
  font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  overflow-y: auto;
  padding: 0.5rem 0.875rem;
  resize: none;
  transition: border-color 0.15s;
  width: 100%;
}

.inbox-composer-input:focus { border-color: rgba(37,211,102,0.4); }
.inbox-composer-input:disabled { opacity: 0.4; }
.inbox-composer-input::placeholder { color: var(--text-muted, #7d8799); }

.inbox-composer-send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #25D366, #10b981);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, opacity 0.15s;
  margin-bottom: 1px;
}

.inbox-composer-send-btn:active { transform: scale(0.9); }
.inbox-composer-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Template-only bar (session expired) */
.inbox-template-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem calc(0.75rem + var(--safe-bottom));
  background: var(--bg-surface, #141720);
  border-top: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 0.8rem;
  color: #f59e0b;
  z-index: 11;
}

.inbox-template-bar .inbox-btn {
  width: auto;
  padding: 0.4rem 0.875rem;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-left: auto;
}

/* Reply bar */
.inbox-reply-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.875rem;
  background: var(--bg-card, #181b23);
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}

.inbox-reply-preview {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-secondary, #8b95a5);
  border-left: 2px solid #25D366;
  padding-left: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-reply-cancel {
  background: none;
  border: none;
  color: var(--text-muted, #7d8799);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.25rem;
}

/* ── Bottom sheet ────────────────────────────────────────────────────────── */

.inbox-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
}

.inbox-bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card, #181b23);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.1));
  padding: 0.5rem 0 calc(0.75rem + var(--safe-bottom));
  z-index: 51;
  max-height: 70dvh;
  overflow-y: auto;
}

.inbox-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}

.inbox-sheet-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  transition: background 0.12s;
  font-size: 0.9375rem;
  color: var(--text-primary, #e8ecf1);
}

.inbox-sheet-item:hover { background: var(--bg-surface, #141720); }
.inbox-sheet-item-danger { color: #ef4444; }

/* ── Profile screen ──────────────────────────────────────────────────────── */

.inbox-screen-profile {
  z-index: 40;
}

.inbox-profile-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.inbox-profile-card {
  background: var(--bg-card, #181b23);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--radius-lg, 12px);
  padding: 1.25rem;
  margin-bottom: 0.875rem;
}

.inbox-profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #128C7E, #25D366);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: #fff;
  margin: 0 auto 0.75rem;
  font-family: var(--font-display, Outfit, sans-serif);
}

.inbox-profile-name {
  font-weight: 600;
  font-size: 1.1rem;
  text-align: center;
  margin: 0 0 0.25rem;
}

.inbox-profile-email {
  text-align: center;
  color: var(--text-secondary, #8b95a5);
  font-size: 0.85rem;
  margin: 0;
}

.inbox-profile-role {
  text-align: center;
  margin: 0.5rem 0 0;
}

.inbox-role-chip {
  display: inline-block;
  background: rgba(37, 211, 102, 0.15);
  border: 1px solid rgba(37, 211, 102, 0.3);
  border-radius: 20px;
  color: #25D366;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.625rem;
}

.inbox-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md, 8px);
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.75rem 1rem;
  width: 100%;
  transition: background 0.15s;
  margin-top: 1rem;
}

.inbox-logout-btn:hover { background: rgba(239, 68, 68, 0.15); }
