/* ═══════════════════════════════════════════════════════════════════════
   SMS Chat Log Viewer — Dark Glassmorphism Theme
   ═══════════════════════════════════════════════════════════════════════ */

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

:root {
  /* Palette */
  --bg-deep: #06080f;
  --bg-base: #0b0f1a;
  --bg-surface: #111827;
  --bg-elevated: #1a2237;
  --bg-hover: #1e293b;
  --border: rgba(148, 163, 184, 0.08);
  --border-accent: rgba(6, 182, 212, 0.2);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Accents */
  --accent-1: #06b6d4;
  --accent-2: #8b5cf6;
  --accent-3: #3b82f6;
  --gradient-accent: linear-gradient(135deg, #06b6d4, #3b82f6, #8b5cf6);
  --gradient-accent-soft: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(139, 92, 246, 0.15));
  --gradient-surface: linear-gradient(145deg, rgba(17, 24, 39, 0.8), rgba(26, 34, 55, 0.6));

  /* Glass */
  --glass-bg: rgba(17, 24, 39, 0.6);
  --glass-border: rgba(148, 163, 184, 0.06);
  --glass-blur: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 40px rgba(6, 182, 212, 0.08);

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Sizing */
  --sidebar-width: 320px;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}

/* Ambient glow background */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 20% 20%, rgba(6, 182, 212, 0.04) 0%, transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.03) 0%, transparent 50%),
              radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ── App Layout ───────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--glass-border);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  z-index: 10;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  border-radius: var(--radius-md);
  color: white;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3);
}

.logo-icon svg {
  width: 20px;
  height: 20px;
}

.logo h1 {
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* Search */
.search-box {
  padding: 12px 20px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  transition: all 0.2s;
  outline: none;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1);
}

/* Agent List */
.agent-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.agent-list::-webkit-scrollbar {
  width: 4px;
}

.agent-list::-webkit-scrollbar-track {
  background: transparent;
}

.agent-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

.agent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  margin-bottom: 2px;
}

.agent-item:hover {
  background: var(--bg-hover);
  border-color: var(--border);
  transform: translateX(2px);
}

.agent-item.active {
  background: var(--gradient-accent-soft);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.agent-info {
  flex: 1;
  min-width: 0;
}

.agent-item-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-item-ext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.agent-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Main Content ─────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  animation: fadeIn 0.6s ease-out;
}

.empty-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent-soft);
  border-radius: var(--radius-xl);
  color: var(--accent-1);
  margin-bottom: 8px;
}

.empty-icon svg {
  width: 40px;
  height: 40px;
}

.empty-state h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Content Panel */
.content-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.content-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.back-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-1);
}

.back-btn svg {
  width: 20px;
  height: 20px;
}

.agent-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-avatar-lg {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: white;
  text-transform: uppercase;
}

.agent-badge h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.agent-ext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.content-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-group label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.filter-group input[type="date"] {
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  outline: none;
  transition: all 0.2s;
}

.filter-group input[type="date"]:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.1);
}

/* Date input calendar icon color */
.filter-group input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

.btn-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--gradient-accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 12px rgba(6, 182, 212, 0.25);
  align-self: flex-end;
}

.btn-filter:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.35);
}

.btn-filter:active {
  transform: translateY(0);
}

.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 12px rgba(16, 185, 129, 0.25);
  align-self: flex-end;
}

.btn-export:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.35);
}

.btn-export:active {
  transform: translateY(0);
}

/* ── Conversations List ───────────────────────────────────────────────── */
.conversations-view {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

.conversations-view::-webkit-scrollbar {
  width: 6px;
}

.conversations-view::-webkit-scrollbar-track {
  background: transparent;
}

.conversations-view::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

/* Phone Search */
.phone-search-box {
  position: relative;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
}

.phone-search-icon {
  position: absolute;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.phone-search-box input {
  width: 100%;
  padding: 12px 40px 12px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.25s;
  outline: none;
  letter-spacing: 0.02em;
}

.phone-search-box input::placeholder {
  color: var(--text-muted);
}

.phone-search-box input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1), 0 0 20px rgba(6, 182, 212, 0.05);
  background: var(--bg-elevated);
}

.phone-search-clear {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.phone-search-clear svg {
  width: 14px;
  height: 14px;
}

.phone-search-clear:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.conversations-list {
  display: grid;
  gap: 8px;
}

.conversation-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--gradient-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideUp 0.3s ease-out backwards;
}

.conversation-card:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent-1);
}

.conv-avatar svg {
  width: 20px;
  height: 20px;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-name {
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.conv-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.conv-count {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-1);
  background: rgba(6, 182, 212, 0.1);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* ── Chat View ────────────────────────────────────────────────────────── */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-partner-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(17, 24, 39, 0.5);
  border-bottom: 1px solid var(--border);
}

.partner-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.partner-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-2);
  font-weight: 600;
  font-size: 0.8rem;
}

.partner-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.partner-phone {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 8px;
}

.message-count-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

.chat-date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.chat-date-divider::before,
.chat-date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.chat-date-divider span {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  white-space: nowrap;
}

.chat-bubble {
  max-width: 75%;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.5;
  animation: bubbleIn 0.3s ease-out backwards;
  position: relative;
  word-wrap: break-word;
}

.chat-bubble.inbound {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.chat-bubble.outbound {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(59, 130, 246, 0.2));
  border: 1px solid rgba(6, 182, 212, 0.15);
  border-bottom-right-radius: 4px;
  color: var(--text-primary);
}

.bubble-text {
  margin-bottom: 4px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.bubble-direction {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

/* ── Loading Overlay ──────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 15, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
}

.loading-overlay p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--accent-1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Skeleton Loaders ─────────────────────────────────────────────────── */
.skeleton-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: var(--bg-elevated);
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-line.w30 { width: 30%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.w45 { width: 45%; }
.skeleton-line.w50 { width: 50%; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w70 { width: 70%; }
.skeleton-line.w80 { width: 80%; }

/* No conversations */
.no-conversations {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 12px;
}

.no-conversations svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  opacity: 0.5;
}

.no-conversations p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Error state */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 12px;
}

.error-state svg {
  width: 48px;
  height: 48px;
  color: #ef4444;
  opacity: 0.7;
}

.error-state p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.error-state .error-msg {
  color: #ef4444;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ── Animations ───────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bubbleIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes shimmer {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

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

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 280px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-toggle {
    display: flex;
  }

  .content-header {
    padding: 12px 16px;
  }

  .content-header-right {
    width: 100%;
    flex-wrap: wrap;
  }

  .conversations-view {
    padding: 12px 16px;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-bubble {
    max-width: 85%;
  }
}

@media (max-width: 600px) {
  .content-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-group input[type="date"] {
    font-size: 0.75rem;
    padding: 5px 8px;
  }

  .btn-filter {
    width: 100%;
    justify-content: center;
  }
}

/* Mobile menu button (shown in main area on mobile) */
.mobile-menu-btn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--gradient-accent);
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4);
  z-index: 9;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.mobile-menu-btn svg {
  width: 22px;
  height: 22px;
}

.mobile-menu-btn:hover {
  transform: scale(1.05);
}

@media (max-width: 900px) {
  .mobile-menu-btn {
    display: flex;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9;
}

.sidebar-overlay.visible {
  display: block;
}
