/* Fluent - WhatsApp-Class Web Application CSS */
:root {
  --font-base: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  --transition-speed: 0.2s;

  /* Accent Gradients (Default: Emerald) */
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --gradient-accent: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --chat-outgoing: #056162;
  --chat-outgoing-text: #e9edef;
  --chat-incoming: #202c33;
  --chat-incoming-text: #e9edef;

  /* Theme: Dark (Default) */
  --bg-app: #0c1317;
  --bg-sidebar: #111b21;
  --bg-chat: #0b141a;
  --bg-header: #202c33;
  --bg-panel: #111b21;
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --bg-input: #2a3942;
  --border-color: #222d34;
  --text-main: #e9edef;
  --text-muted: #8696a0;
  --text-dim: #667781;
  --badge-bg: #00a884;
  --badge-text: #111b21;
  --modal-overlay: rgba(11, 20, 26, 0.85);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Light Theme */
[data-theme="light"] {
  --bg-app: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-chat: #efeae2;
  --bg-header: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-hover: #f5f6f6;
  --bg-active: #e9edef;
  --bg-input: #ffffff;
  --border-color: #e9edef;
  --text-main: #111b21;
  --text-muted: #667781;
  --text-dim: #8696a0;
  --chat-outgoing: #d9fdd3;
  --chat-outgoing-text: #111b21;
  --chat-incoming: #ffffff;
  --chat-incoming-text: #111b21;
  --modal-overlay: rgba(240, 242, 245, 0.85);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* Dim Theme (Midnight) */
[data-theme="dim"] {
  --bg-app: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-chat: #090d16;
  --bg-header: #1e293b;
  --bg-panel: #1e293b;
  --bg-hover: #334155;
  --bg-active: #475569;
  --bg-input: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --chat-outgoing: #1e3a5f;
  --chat-outgoing-text: #f8fafc;
  --chat-incoming: #1e293b;
  --chat-incoming-text: #f8fafc;
  --modal-overlay: rgba(15, 23, 42, 0.88);
}

/* Accent Gradients */
[data-accent="ocean"] {
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --primary-glow: rgba(56, 189, 248, 0.3);
  --gradient-accent: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  --chat-outgoing: #0c4a6e;
}

[data-accent="violet"] {
  --primary: #a855f7;
  --primary-hover: #7e22ce;
  --primary-glow: rgba(168, 85, 247, 0.3);
  --gradient-accent: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
  --chat-outgoing: #581c87;
}

[data-accent="rose"] {
  --primary: #f43f5e;
  --primary-hover: #be123c;
  --primary-glow: rgba(244, 63, 94, 0.3);
  --gradient-accent: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  --chat-outgoing: #881337;
}

[data-accent="cyberpunk"] {
  --primary: #06b6d4;
  --primary-hover: #0891b2;
  --primary-glow: rgba(6, 182, 212, 0.35);
  --gradient-accent: linear-gradient(135deg, #06b6d4 0%, #d946ef 100%);
  --chat-outgoing: #155e75;
}

/* Reduced Motion */
.reduced-motion *,
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}

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

body {
  font-family: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
#app {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Auth Overlay */
#auth-view {
  position: fixed;
  inset: 0;
  background: var(--bg-app);
  background-image: radial-gradient(circle at 50% 20%, var(--primary-glow) 0%, transparent 60%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.auth-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 28px;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.auth-tagline {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition-speed);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-primary {
  background: var(--gradient-accent);
  color: #ffffff;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-active);
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
}

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-full);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.auth-switch {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.auth-switch span {
  color: var(--primary);
  font-weight: 600;
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #ef4444;
  color: #fca5a5;
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 420px;
  min-width: 280px;
  max-width: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-header {
  height: 60px;
  padding: 10px 16px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-main);
  flex-shrink: 0;
}

.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-lg { width: 72px; height: 72px; font-size: 24px; }
.avatar-xl { width: 96px; height: 96px; font-size: 32px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Navigation Tabs (Chats, Status, Channels, Calls, AI) */
.nav-tabs {
  display: flex;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.tab-item {
  flex: 1;
  min-width: 60px;
  text-align: center;
  padding: 12px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  transition: all var(--transition-speed);
}

.tab-item:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-accent);
}

/* Search Bar & Filters */
.search-container {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
}

.search-box {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  padding: 6px 12px;
  gap: 10px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 13px;
  width: 100%;
}

.filter-pills {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-sidebar);
  overflow-x: auto;
  border-bottom: 1px solid var(--border-color);
}

.pill {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-speed);
}

.pill:hover {
  color: var(--text-main);
}

.pill.active {
  background: var(--primary-glow);
  color: var(--primary);
  font-weight: 600;
}

/* Chat & Items List */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-sidebar);
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background var(--transition-speed);
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-active);
}

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

.chat-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chat-snippet-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-snippet {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.badge-unread {
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-full);
  padding: 2px 7px;
  min-width: 18px;
  text-align: center;
}

/* Main Chat Area */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-chat);
  position: relative;
  background-size: cover;
  background-position: center;
}

.chat-header {
  height: 60px;
  padding: 8px 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.chat-header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.chat-header-status {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-header-status.online {
  color: var(--primary);
  font-weight: 500;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Pinned Message Banner */
.pinned-banner {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  cursor: pointer;
}

.pinned-banner i {
  color: var(--primary);
  margin-right: 8px;
}

/* Message Feed */
.message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.e2ee-tag {
  align-self: center;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 11px;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  max-width: 90%;
  text-align: center;
}

/* Speech Bubbles */
.message-bubble {
  max-width: 65%;
  min-width: 100px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
  display: flex;
  flex-direction: column;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background: var(--chat-outgoing);
  color: var(--chat-outgoing-text);
  border-bottom-right-radius: 2px;
}

.message-bubble.incoming {
  align-self: flex-start;
  background: var(--chat-incoming);
  color: var(--chat-incoming-text);
  border-bottom-left-radius: 2px;
}

.msg-sender-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 3px;
}

.quoted-message {
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
}

.quoted-sender {
  font-weight: 600;
  color: var(--primary);
}

.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
  float: right;
  margin-left: 10px;
}

.receipt-icon {
  font-size: 14px;
}
.receipt-icon.read {
  color: #38bdf8;
}

/* Media in bubble */
.msg-image {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  object-fit: cover;
  margin-bottom: 4px;
}

.msg-audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  width: 260px;
}

.msg-doc {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Message Actions Menu on Hover */
.message-bubble:hover .msg-actions-trigger {
  opacity: 1;
}

.msg-actions-trigger {
  position: absolute;
  top: 4px;
  right: 6px;
  opacity: 0;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-full);
  padding: 2px 6px;
  font-size: 12px;
  transition: opacity var(--transition-speed);
}

/* Message Reactions Pill */
.msg-reactions-row {
  display: flex;
  gap: 4px;
  margin-top: -6px;
  margin-bottom: 4px;
  z-index: 2;
}

.reaction-badge {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 2px 6px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Chat Input Bar */
.chat-input-bar {
  min-height: 62px;
  padding: 8px 16px;
  background: var(--bg-header);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-input-box {
  flex: 1;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
}

.chat-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
}

/* Voice Note Recording Bar */
.voice-recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  color: #ef4444;
  font-weight: 600;
  font-size: 14px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: var(--radius-full);
  animation: pulse 1s infinite;
  display: inline-block;
  margin-right: 8px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.2); }
}

/* Modals & Overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

/* WebRTC Call Screen Overlay */
#call-overlay {
  position: fixed;
  inset: 0;
  background: #090d16;
  z-index: 1000;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 32px 20px;
}

.call-header {
  text-align: center;
}

.call-title {
  font-size: 24px;
  font-weight: 700;
  margin-top: 12px;
}

.call-status {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.video-grid {
  width: 100%;
  max-width: 800px;
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
}

.remote-video {
  width: 100%;
  height: 100%;
  max-height: 480px;
  border-radius: var(--radius-lg);
  background: #111b21;
  object-fit: cover;
}

.local-video {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  height: 120px;
  border-radius: var(--radius-md);
  border: 2px solid var(--primary);
  background: #000;
  object-fit: cover;
}

.call-controls {
  display: flex;
  gap: 20px;
}

.call-btn {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border: none;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.call-btn-danger {
  background: #ef4444;
  color: #fff;
}
.call-btn-danger:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* Incoming Call Modal */
#incoming-call-modal {
  position: fixed;
  top: 24px;
  right: 24px;
  background: var(--bg-panel);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  z-index: 1050;
  display: none;
  align-items: center;
  gap: 16px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { transform: translateY(-50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Status / Stories Viewer */
#status-viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 900;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
}

.story-progress-bar {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto 16px auto;
}

.story-segment {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.story-fill {
  height: 100%;
  background: #ffffff;
  width: 0%;
}

.story-content-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
  font-size: 26px;
  font-weight: 600;
  color: #ffffff;
  padding: 24px;
}

/* Channels Screen & AI screen */
.channel-post-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.empty-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
  gap: 12px;
}

.empty-placeholder i {
  font-size: 48px;
  color: var(--primary);
  opacity: 0.6;
}

/* Responsive Rules for 200px - 2000px */
@media (max-width: 768px) {
  .app-sidebar {
    width: 100%;
  }

  .chat-container {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
  }

  .chat-container.mobile-active {
    display: flex;
  }

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

@media (max-width: 480px) {
  .sidebar-header {
    padding: 8px 12px;
  }
  .nav-tabs .tab-item {
    font-size: 11px;
    padding: 10px 4px;
  }
  .message-bubble {
    max-width: 90%;
  }
}
