/* ═══════════════════════════════════════════
   ChatLens — Design System & Core Styles
   Apple Liquid Glass / Glassmorphism Theme
   ═══════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Backgrounds */
  --bg-deep: #050a10;
  --bg-primary: #0b1018;
  --bg-secondary: #111a25;
  --bg-chat: #0c1219;

  /* Glass */
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-bg-hover: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.07);
  --glass-border-light: rgba(255, 255, 255, 0.12);
  --glass-highlight: rgba(255, 255, 255, 0.08);
  --glass-blur: 28px;

  /* Accent */
  --accent: #00d4a1;
  --accent-dim: #00a87e;
  --accent-glow: rgba(0, 212, 161, 0.12);
  --accent-glow-strong: rgba(0, 212, 161, 0.25);

  /* Chat Bubbles */
  --bubble-out-bg: linear-gradient(135deg, rgba(0, 140, 110, 0.35), rgba(0, 92, 75, 0.45));
  --bubble-out-border: rgba(0, 212, 161, 0.12);
  --bubble-in-bg: linear-gradient(135deg, rgba(25, 38, 48, 0.7), rgba(20, 32, 42, 0.8));
  --bubble-in-border: rgba(255, 255, 255, 0.05);

  /* Text */
  --text-primary: #e2e8f0;
  --text-secondary: #7a8a9a;
  --text-muted: #4a5568;
  --text-timestamp: #5d7080;
  --text-accent: #00d4a1;

  /* System */
  --system-bg: rgba(0, 212, 161, 0.06);
  --system-border: rgba(0, 212, 161, 0.1);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Radii */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 100px;

  /* Spacing */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 36px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration: 0.3s;
  --duration-slow: 0.5s;
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg-deep: #eef2f7;
  --bg-primary: #f5f7fa;
  --bg-secondary: #e8ecf1;
  --bg-chat: #e4dcd4;

  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-hover: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-border-light: rgba(0, 0, 0, 0.12);
  --glass-highlight: rgba(255, 255, 255, 0.9);

  --accent: #00a884;
  --accent-dim: #008f6f;
  --accent-glow: rgba(0, 168, 132, 0.12);
  --accent-glow-strong: rgba(0, 168, 132, 0.22);

  --bubble-out-bg: linear-gradient(135deg, #d9fdd3, #c8f7c5);
  --bubble-out-border: rgba(0, 168, 132, 0.15);
  --bubble-in-bg: linear-gradient(135deg, #ffffff, #f7f8fa);
  --bubble-in-border: rgba(0, 0, 0, 0.06);

  --text-primary: #111b21;
  --text-secondary: #54656f;
  --text-muted: #8696a0;
  --text-timestamp: #667781;
  --text-accent: #008f6f;

  --system-bg: rgba(0, 168, 132, 0.08);
  --system-border: rgba(0, 168, 132, 0.12);
}

[data-theme="light"] body {
  background: var(--bg-deep);
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.75);
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .sidebar {
  background: rgba(255, 255, 255, 0.5);
  border-right-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .status-bar {
  background: rgba(255, 255, 255, 0.65);
  border-top-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .glass-panel {
  background: rgba(255, 255, 255, 0.55);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .glass-panel::before {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.8), transparent);
}

[data-theme="light"] .glass-panel-solid {
  background: rgba(255, 255, 255, 0.85);
}

[data-theme="light"] .chat-area::before {
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23667781' fill-opacity='1'%3E%3Ccircle cx='10' cy='10' r='2'/%3E%3Ccircle cx='40' cy='15' r='1.5'/%3E%3Crect x='25' y='35' width='4' height='3' rx='1'/%3E%3Ccircle cx='50' cy='45' r='2'/%3E%3Cpath d='M5 40 L8 37 L11 40 Z'/%3E%3Crect x='45' y='8' width='3' height='4' rx='1'/%3E%3Ccircle cx='15' cy='50' r='1'/%3E%3Ccircle cx='35' cy='5' r='1'/%3E%3C/g%3E%3C/svg%3E");
}

[data-theme="light"] .search-box input {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .search-box input:focus {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 168, 132, 0.4);
}

[data-theme="light"] .user-selector select {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .user-selector select option {
  background: white;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .lightbox {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="light"] .scroll-fab {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-secondary);
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

[data-theme="light"] .date-pill {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-secondary);
}

[data-theme="light"] .bubble.out {
  border-color: rgba(0, 168, 132, 0.1);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

[data-theme="light"] .bubble.out::after {
  border-bottom-color: #c8f7c5;
}

[data-theme="light"] .bubble.in {
  border-color: rgba(0, 0, 0, 0.05);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

[data-theme="light"] .bubble.in::after {
  border-bottom-color: #f7f8fa;
}

[data-theme="light"] .system-msg {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .bubble-text a {
  color: #0277bd;
}

/* ── Theme Toggle Button ── */
.theme-toggle {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all var(--duration) var(--ease);
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
}

.theme-toggle:hover {
  background: var(--glass-bg-hover);
  color: var(--accent);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  width: 18px;
  height: 18px;
}

/* Show/hide based on theme */
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

input, button, textarea {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

button {
  cursor: pointer;
}

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

img, video {
  max-width: 100%;
  display: block;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ── Glass Component ── */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  position: relative;
}

.glass-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--glass-highlight), transparent);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  pointer-events: none;
}

.glass-panel-solid {
  background: rgba(15, 22, 32, 0.85);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
}

/* ── Screen Management ── */
.screen {
  position: fixed;
  inset: 0;
  transition: opacity var(--duration-slow) var(--ease), transform var(--duration-slow) var(--ease);
  display: flex;
  flex-direction: column;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.97);
  visibility: hidden;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
  visibility: visible;
}

/* ── Chat Screen Layout ── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-primary);
}

.header {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-md) var(--sp-lg);
  background: rgba(10, 16, 24, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
  flex-shrink: 0;
}

.header .back-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background var(--duration) var(--ease);
  color: var(--text-secondary);
  font-size: 1.2rem;
}

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

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #00b4d8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--accent-glow);
}

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

.header-info h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-info p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: var(--sp-xs);
}

.header-actions button {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all var(--duration) var(--ease);
  color: var(--text-secondary);
  font-size: 1.1rem;
  position: relative;
}

.header-actions button:hover {
  background: var(--glass-bg-hover);
  color: var(--accent);
}

.header-actions button.active {
  background: var(--accent-glow);
  color: var(--accent);
}

/* ── Main Content ── */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
.sidebar {
  width: 340px;
  min-width: 340px;
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  background: rgba(8, 13, 20, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  overflow-y: auto;
  transition: transform var(--duration-slow) var(--ease), opacity var(--duration-slow) var(--ease);
  z-index: 5;
}

.sidebar.hidden {
  transform: translateX(-100%);
  opacity: 0;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
}

.sidebar-section {
  padding: var(--sp-lg);
  border-bottom: 1px solid var(--glass-border);
}

.sidebar-section h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--sp-md);
}

/* ── Search Input ── */
.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-pill);
  color: var(--text-primary);
  font-size: 0.87rem;
  transition: all var(--duration) var(--ease);
}

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

.search-box input:focus {
  border-color: rgba(0, 212, 161, 0.3);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 20px var(--accent-glow);
}

.search-box .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--sp-sm);
  padding: 0 var(--sp-xs);
}

.search-nav span {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.search-nav button {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all var(--duration) var(--ease);
}

.search-nav button:hover {
  background: var(--glass-bg-hover);
  color: var(--accent);
}

/* ── User Selector ── */
.user-selector {
  padding: var(--sp-lg);
  border-bottom: 1px solid var(--glass-border);
}

.user-selector label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--sp-sm);
}

.user-selector select {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.user-selector select option {
  background: var(--bg-secondary);
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg-chat);
}

/* Chat wallpaper pattern */
.chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Ccircle cx='10' cy='10' r='2'/%3E%3Ccircle cx='40' cy='15' r='1.5'/%3E%3Crect x='25' y='35' width='4' height='3' rx='1'/%3E%3Ccircle cx='50' cy='45' r='2'/%3E%3Cpath d='M5 40 L8 37 L11 40 Z'/%3E%3Crect x='45' y='8' width='3' height='4' rx='1'/%3E%3Ccircle cx='15' cy='50' r='1'/%3E%3Ccircle cx='35' cy='5' r='1'/%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-md) var(--sp-lg);
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
}

/* ── Status Bar ── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--sp-lg);
  background: rgba(10, 16, 24, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--duration) var(--ease);
}

.lightbox.hidden {
  opacity: 0;
  pointer-events: none;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration) var(--ease);
  z-index: 10;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.lightbox-content {
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--r-md);
}

.lightbox-content video {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--r-md);
}

.lightbox-content audio {
  width: 400px;
}

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 16, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
  transition: opacity var(--duration-slow) var(--ease);
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.06);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--sp-md);
}

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

/* ── Animations ── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ── Utility ── */
/* Note: .screen.hidden uses visibility instead of display:none for smooth transitions */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.pointer-events-none { pointer-events: none; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    min-width: unset;
    z-index: 20;
  }
  .messages-container {
    padding: var(--sp-sm) var(--sp-md);
  }
}
