/* ============================================
   Unruled — Premium Dark Theme
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #16213e;
  --bg-card: #14141e;
  --bg-input: #0d0d14;
  --bg-hover: rgba(255, 255, 255, 0.04);
  --bg-sidebar: rgba(255, 255, 255, 0.02);
  --text-primary: #eaeaef;
  --text-secondary: #a0a0b8;
  --text-muted: #5a5a70;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-light: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.25);
  --gradient-start: #8b5cf6;
  --gradient-mid: #6366f1;
  --gradient-end: #3b82f6;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --transition: 0.2s ease;
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --sidebar-width: 280px;
}

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

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

a:hover {
  color: var(--accent-hover);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ============================================
   Layout
   ============================================ */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
  transform: translateX(-100%);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.sidebar-logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

/* Keep .logo class working for backward compat */
.sidebar-header .logo {
  display: none;
}
.sidebar-header h1 {
  display: none;
}

/* New Chat button */
.sidebar-new-chat-wrap {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  color: var(--accent-hover);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--accent-light);
  background: transparent;
}

.new-chat-button:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.1);
  transform: translateY(-1px);
  color: var(--accent-hover);
}

.new-chat-button .icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 300;
}

/* Sidebar search */
.sidebar-search {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-search-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.sidebar-search-input:focus {
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(255, 255, 255, 0.05);
}

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

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 20px;
}

.nav-section-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 10px;
  margin-bottom: 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent-hover);
  border-left-color: var(--accent);
}

.nav-item .icon {
  width: 18px;
  text-align: center;
  font-size: 1rem;
}

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

.my-stats-area {
  padding: 0 0 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.my-stats-area:empty {
  display: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-lg);
  transition: background var(--transition);
}

.user-info:hover {
  background: var(--bg-hover);
}

.user-avatar-ring {
  padding: 2px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
  flex-shrink: 0;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.settings-gear-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: auto;
  transition: color var(--transition);
}

.user-info:hover .settings-gear-icon {
  color: var(--text-secondary);
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* ---- Sidebar overlay (mobile) ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 99;
  animation: fadeIn 0.2s ease;
}

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

/* ---- Main content ---- */
.main-content {
  flex: 1;
  margin-left: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg-primary);
}

/* ---- Top bar ---- */
.top-bar {
  height: 52px;
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hamburger-btn {
  display: flex;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

.hamburger-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.chat-title-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-action-btn {
  font-size: 0.78rem;
  padding: 5px 10px;
  border-radius: var(--radius);
}

/* Export dropdown */
.export-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 140px;
  overflow: hidden;
}

.export-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.export-option:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-success .status-dot {
  box-shadow: 0 0 6px var(--success);
}

.badge-warning .status-dot {
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ============================================
   Auth Pages (Login/Register)
   ============================================ */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 28px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-tab:hover:not(.active) {
  background: var(--bg-hover);
}

/* ============================================
   Login Page — Premium Redesign
   ============================================ */

@keyframes loginGradientShift {
  0%   { background-position: 0% 50%; }
  25%  { background-position: 100% 50%; }
  50%  { background-position: 100% 100%; }
  75%  { background-position: 0% 100%; }
  100% { background-position: 0% 50%; }
}

body.login-page {
  background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 25%, #0f0f0f 50%, #0a0a1a 75%, #1a0a2e 100%);
  background-size: 400% 400%;
  animation: loginGradientShift 20s ease infinite;
  overflow: hidden;
}

.login-bg-glow {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, rgba(79, 70, 229, 0.04) 40%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: glowPulse 6s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  0%   { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 1;   transform: translate(-50%, -50%) scale(1.15); }
}

body.login-page::before,
body.login-page::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

body.login-page::before {
  width: 300px;
  height: 300px;
  top: 10%;
  right: 15%;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.06), transparent 70%);
  animation: floatParticle1 12s ease-in-out infinite alternate;
}

body.login-page::after {
  width: 200px;
  height: 200px;
  bottom: 15%;
  left: 10%;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.05), transparent 70%);
  animation: floatParticle2 10s ease-in-out infinite alternate;
}

@keyframes floatParticle1 {
  0%   { transform: translate(0, 0); }
  100% { transform: translate(-40px, 30px); }
}

@keyframes floatParticle2 {
  0%   { transform: translate(0, 0); }
  100% { transform: translate(30px, -40px); }
}

@keyframes cardFadeIn {
  0%   { opacity: 0; transform: translateY(24px); }
  100% { opacity: 1; transform: translateY(0); }
}

body.login-page .auth-card {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 48px 40px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 80px rgba(99, 102, 241, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: cardFadeIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.login-branding {
  text-align: center;
  margin-bottom: 36px;
}

.login-wordmark {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 30%, #3b82f6 60%, #14b8a6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 8px;
}

.login-tagline {
  font-size: 0.9rem;
  color: rgba(160, 160, 184, 0.7);
  font-weight: 400;
  letter-spacing: 0.02em;
}

body.login-page .form-group {
  margin-bottom: 22px;
}

body.login-page .form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(160, 160, 184, 0.6);
  margin-bottom: 8px;
}

body.login-page .form-control {
  width: 100%;
  padding: 13px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
  outline: none;
}

body.login-page .form-control:focus {
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12), 0 0 20px rgba(99, 102, 241, 0.08);
  background: rgba(255, 255, 255, 0.06);
}

body.login-page .form-control::placeholder {
  color: rgba(160, 160, 184, 0.35);
}

.login-btn {
  position: relative;
  width: 100%;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 40%, #3b82f6 70%, #14b8a6 100%);
  background-size: 200% 200%;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
  outline: none;
  overflow: hidden;
  margin-top: 8px;
}

.login-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1, #3b82f6, #14b8a6);
  background-size: 200% 200%;
  animation: loginGradientShift 6s ease infinite;
  z-index: 0;
}

.login-btn .btn-text,
.login-btn .btn-spinner {
  position: relative;
  z-index: 1;
}

.login-btn:hover:not(:disabled) {
  transform: scale(1.02);
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.3), 0 0 40px rgba(99, 102, 241, 0.15);
}

.login-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.login-btn .btn-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
}

.login-btn.loading .btn-spinner {
  display: inline-block;
}

@media (max-width: 480px) {
  body.login-page .auth-card {
    padding: 36px 24px;
    border-radius: 16px;
    margin: 0 4px;
  }
  .login-wordmark {
    font-size: 2rem;
  }
  .login-tagline {
    font-size: 0.82rem;
  }
  .login-bg-glow {
    width: 350px;
    height: 350px;
  }
}

/* ============================================
   Forms
   ============================================ */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-control::placeholder {
  color: var(--text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6b80' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-error {
  font-size: 0.8rem;
  color: var(--error);
  margin-top: 4px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-light);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background: #16a34a;
  border-color: #16a34a;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
  border-color: var(--warning);
}

.btn-warning:hover:not(:disabled) {
  background: #d97706;
  border-color: #d97706;
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card .stat-change {
  font-size: 0.8rem;
  margin-top: 4px;
}

.stat-change.positive {
  color: var(--success);
}

.stat-change.negative {
  color: var(--error);
}

/* ============================================
   Welcome State
   ============================================ */
.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.welcome-inner {
  text-align: center;
  animation: welcomeFadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.welcome-wordmark {
  font-size: 3.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 12px;
}

.welcome-tagline {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.04em;
  margin-bottom: 32px;
}

.welcome-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid));
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
}

.welcome-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 24px var(--accent-glow);
}

.welcome-start-btn:active {
  transform: translateY(0) scale(0.98);
}

/* ============================================
   Chat Interface
   ============================================ */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
}

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

/* Messages */
.message {
  display: flex;
  gap: 12px;
  max-width: 75%;
  padding: 4px 0;
  position: relative;
}

.message-copy-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .message-copy-btn {
  opacity: 1;
}

.message-copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

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

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

.message.message-animate {
  animation: messageEntrance 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message.user.message-animate {
  animation: messageEntranceRight 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid));
  color: #fff;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.message.assistant .message-avatar {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-xl);
  font-size: var(--chat-font-size, 15px);
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user {
  cursor: default;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.15));
  color: var(--text-primary);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-bottom-right-radius: 4px;
}

.message.user .message-bubble:active {
  transform: scale(0.98);
  transition: transform 0.1s;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Code blocks */
.message-bubble pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--font-mono);
  font-size: calc(var(--chat-font-size, 15px) * 0.88);
  color: var(--text-primary);
  line-height: 1.6;
  position: relative;
}

.message-bubble pre::after {
  content: 'copy';
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.65rem;
  font-family: inherit;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.message-bubble pre:hover::after {
  opacity: 0.6;
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-bubble pre code {
  background: none;
  padding: 0;
}

/* Code blocks inside user bubbles */
.message.user .message-bubble pre {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.08);
}

.message.user .message-bubble code {
  background: rgba(0, 0, 0, 0.15);
}

/* Markdown: Headings inside message bubbles */
.message-bubble h3 {
  font-size: 1.15em;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--text-primary);
  line-height: 1.3;
}

.message-bubble h4 {
  font-size: 1.05em;
  font-weight: 600;
  margin: 12px 0 4px;
  color: var(--text-primary);
  line-height: 1.3;
}

.message-bubble h5 {
  font-size: 0.95em;
  font-weight: 600;
  margin: 10px 0 4px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.message-bubble h3:first-child,
.message-bubble h4:first-child,
.message-bubble h5:first-child {
  margin-top: 0;
}

/* Markdown: Blockquotes */
.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.03);
  margin: 8px 0;
  padding: 8px 14px;
  font-style: italic;
  color: var(--text-secondary);
  border-radius: 0 var(--radius) var(--radius) 0;
}

body.light-mode .message-bubble blockquote {
  background: rgba(0, 0, 0, 0.03);
}

/* Markdown: Strikethrough */
.message-bubble del {
  opacity: 0.65;
  text-decoration: line-through;
}

/* Markdown: Lists */
.message-bubble ul,
.message-bubble ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-bubble ul {
  list-style-type: disc;
}

.message-bubble ol {
  list-style-type: decimal;
}

.message-bubble li {
  margin: 3px 0;
  line-height: 1.6;
}

/* Markdown: Horizontal rule */
.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 12px 0;
  opacity: 0.5;
}

/* Markdown: Links */
.message-bubble a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition), text-decoration var(--transition);
}

.message-bubble a:hover {
  text-decoration: underline;
  color: var(--accent-hover, var(--accent));
}

/* Markdown: Bold — slightly brighter */
.message-bubble strong {
  font-weight: 600;
  color: var(--text-primary);
}

body.light-mode .message-bubble strong {
  font-weight: 700;
}

.message-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}


/* ---- Templates Popup ---- */
.templates-container {
  position: relative;
  display: flex;
  align-items: center;
}

.templates-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 260px;
  max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 100;
  margin-bottom: 8px;
  overflow: hidden;
}

.templates-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-primary);
}

.templates-popup-list {
  max-height: 240px;
  overflow-y: auto;
}

.templates-popup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: background var(--transition);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.templates-popup-item:hover {
  background: rgba(99, 102, 241, 0.08);
  color: var(--text-primary);
}

.templates-popup-item .template-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.templates-popup-item .template-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.templates-popup-item:hover .template-delete-btn {
  opacity: 1;
}

.templates-popup-item .template-delete-btn:hover {
  color: var(--danger);
}

.templates-popup-empty {
  padding: 16px 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Save-template modal overlay */
.template-save-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-save-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 320px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.template-save-modal h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--text-primary);
}

.template-save-modal input,
.template-save-modal textarea {
  width: 100%;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  box-sizing: border-box;
}

.template-save-modal textarea {
  min-height: 80px;
  resize: vertical;
}

.template-save-modal .template-save-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
/* ---- Chat Input ---- */
.chat-input-area {
  padding: 12px 20px 16px;
  background: transparent;
}

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 860px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 6px 6px 6px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08), 0 4px 20px rgba(0, 0, 0, 0.2);
}

.chat-input-wrapper textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 200px;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--chat-font-size, 15px);
  line-height: 1.5;
  outline: none;
}

.chat-input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.chat-input-wrapper .btn-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.chat-input-wrapper .btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Stop/Cancel generation button */
.chat-input-wrapper .btn-stop {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  display: none;
  animation: fadeIn 0.15s ease;
}

.chat-input-wrapper .btn-stop.visible {
  display: inline-flex;
}

.generation-stopped-note {
  display: inline;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.85em;
}

/* Input hints */
.chat-input-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px 0;
  max-width: 860px;
  margin: 0 auto;
}

.font-size-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  cursor: pointer;
  line-height: 1.4;
  transition: color var(--transition), border-color var(--transition);
}

.font-size-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.kbd-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.kbd-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.68rem;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

.char-count-text {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Shortcuts help button */
.shortcuts-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 8px;
  padding: 0;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  vertical-align: middle;
  transition: color 0.15s, border-color 0.15s;
}

.shortcuts-help-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* Shortcuts table */
.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcuts-table tr + tr {
  border-top: 1px solid var(--border);
}

.shortcuts-table td {
  padding: 8px 10px;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.shortcuts-table .shortcut-keys {
  white-space: nowrap;
  text-align: right;
  width: 45%;
}

.shortcuts-table kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 0.78rem;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary, var(--text-primary));
}

/* ============================================
   Typing Indicator
   ============================================ */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* Thinking bubble glow */
.thinking-bubble .message-bubble {
  animation: thinkingGlow 2s ease-in-out infinite;
}

@keyframes thinkingGlow {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 12px 2px rgba(99, 102, 241, 0.15); }
}

/* Thinking status text */
.thinking-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  transition: opacity 0.4s ease;
  opacity: 1;
}

.thinking-status.fade-out {
  opacity: 0;
}

/* ============================================
   Conversation List
   ============================================ */
.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  font-size: 0.84rem;
  border-left: 2px solid transparent;
  position: relative;
}

.conversation-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.conversation-item.active {
  background: var(--accent-light);
  color: var(--accent-hover);
  border-left-color: var(--accent);
}

.conversation-item .title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-pin-btn,
.conv-rename-btn,
.conv-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}

.conv-pin-btn { font-size: 0.75rem; }
.conv-rename-btn { font-size: 0.8rem; }
.conv-delete-btn { font-size: 1.1rem; }

.conv-delete-btn:hover { color: #ef4444; }
.conv-rename-btn:hover { color: var(--accent); }
.conv-pin-btn:hover { color: var(--accent); }

/* Pinned conversations get accent pin button always visible */
.conversation-item.pinned .conv-pin-btn {
  opacity: 1;
  color: var(--accent);
}

/* Pinned conversations subtle visual distinction */
.conversation-item.pinned {
  border-left-color: var(--accent);
}

.pin-icon {
  font-size: 0.7rem;
  vertical-align: middle;
}

.conversation-item:hover .conv-pin-btn,
.conversation-item:hover .conv-rename-btn,
.conversation-item:hover .conv-delete-btn,
.conversation-item.active .conv-pin-btn,
.conversation-item.active .conv-rename-btn,
.conversation-item.active .conv-delete-btn {
  opacity: 1;
}

@media (max-width: 768px) {
  .conv-pin-btn,
  .conv-rename-btn,
  .conv-delete-btn {
    opacity: 1;
  }
}

/* Load more conversations button */
.load-more-conversations {
  padding: 10px;
  text-align: center;
}

.load-more-conversations .btn {
  width: 100%;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-color: var(--border);
  transition: all var(--transition);
}

.load-more-conversations .btn:hover {
  color: var(--accent-hover);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 400px;
  border-left: 3px solid;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.toast.success {
  background: rgba(20, 20, 30, 0.9);
  color: var(--success);
  border-left-color: var(--success);
}

.toast.error {
  background: rgba(20, 20, 30, 0.9);
  color: var(--error);
  border-left-color: var(--error);
}

.toast.info {
  background: rgba(20, 20, 30, 0.9);
  color: var(--info);
  border-left-color: var(--info);
}

.toast.warning {
  background: rgba(20, 20, 30, 0.9);
  color: var(--warning);
  border-left-color: var(--warning);
}

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

.toast.toast-exit {
  animation: toastOut 0.3s ease forwards;
}

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

/* ============================================
   Tables
   ============================================ */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--bg-tertiary);
}

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-hover);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-danger {
  background: var(--error-bg);
  color: var(--error);
}

/* ============================================
   Modals / Dialogs
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-2xl);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

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

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

/* ============================================
   Loading / Spinner
   ============================================ */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

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

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-muted);
  gap: 12px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {

  .message {
    max-width: 92%;
  }

  .message-copy-btn {
    opacity: 1;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 28px 20px;
  }

  .modal {
    width: 95%;
  }

  .top-bar {
    padding: 0 12px;
    gap: 8px;
  }

  .top-bar h2 {
    font-size: 0.95rem;
  }

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

  .chat-input-area {
    padding: 8px 12px 12px;
  }

  .chat-input-wrapper {
    border-radius: var(--radius-lg);
  }

  .welcome-wordmark {
    font-size: 2.2rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

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

  .table-container {
    font-size: 0.8rem;
  }

  td, th {
    padding: 8px 10px;
  }
}

/* ============================================
   Utilities
   ============================================ */
.btn:focus-visible,
.nav-item:focus-visible,
.auth-tab:focus-visible,
.form-control:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }

/* ============================================
   Admin Panel
   ============================================ */
.admin-body {
  background: var(--bg-primary);
}

.admin-layout {
  min-height: 100vh;
}

.admin-sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.admin-logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.admin-nav-icon {
  font-size: 1rem;
}

.admin-sidebar-footer {
  border-top: 1px solid var(--border);
}

.admin-back-link {
  margin-bottom: 12px;
}

.admin-user-block {
  padding: 8px 0 0;
}

.admin-signout-btn {
  margin-top: 8px;
}

.admin-topbar {
  gap: 12px;
}

.admin-topbar-brand h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.admin-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-topbar-back {
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.admin-topbar-back:hover {
  color: var(--accent-hover);
}

.admin-page-content {
  padding: 24px;
}

.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.admin-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-stat-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.admin-stat-icon--green { color: var(--success); }
.admin-stat-icon--blue  { color: var(--info); }
.admin-stat-icon--purple { color: #8b5cf6; }
.admin-stat-icon--amber { color: var(--warning); }

.admin-stat-body {
  min-width: 0;
}

.admin-stat-number {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.admin-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-card {
  margin-bottom: 20px;
}

.admin-card-header {
  flex-wrap: wrap;
  gap: 12px;
}

.admin-search-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.admin-search-box {
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-search-icon {
  font-size: 0.9rem;
}

.admin-search-input {
  min-width: 180px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
}

.admin-pagination button {
  padding: 6px 14px;
  font-size: 0.82rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.admin-pagination button:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.admin-pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.admin-pagination .page-info {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.admin-section {
  animation: fadeIn 0.25s ease;
}

.admin-section-visible {
  display: block;
}

.admin-modal-overlay {
  z-index: 9000;
}

.admin-modal {
  max-width: 480px;
}

.admin-modal input[type="text"],
.admin-modal input[type="email"],
.admin-modal input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  margin-top: 6px;
}

.admin-modal input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.admin-modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.admin-modal .btn-cancel {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition);
}

.admin-modal .btn-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.admin-modal .btn-confirm-danger {
  padding: 8px 16px;
  background: var(--error);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all var(--transition);
}

.admin-modal .btn-confirm-danger:hover {
  background: #dc2626;
}

.admin-modal .temp-password {
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--accent-hover);
  margin: 12px 0;
  text-align: center;
  letter-spacing: 0.05em;
  word-break: break-all;
  user-select: all;
}

.role-select {
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

.role-select:focus {
  border-color: var(--accent);
}

.badge-admin {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}

.badge-user {
  background: var(--info-bg);
  color: var(--info);
}

.badge-active {
  background: var(--success-bg);
  color: var(--success);
}

.badge-inactive {
  background: var(--error-bg);
  color: var(--error);
}

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

@media (max-width: 768px) {
  .admin-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .admin-search-row {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-topbar-back {
    display: none;
  }
}

@media (max-width: 480px) {
  .admin-stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   Glassmorphism fallback for browsers without
   backdrop-filter support
   ============================================ */
@supports not (backdrop-filter: blur(1px)) {
  .sidebar {
    background: var(--bg-secondary);
  }
  .top-bar {
    background: var(--bg-primary);
  }
  body.login-page .auth-card {
    background: var(--bg-card);
  }
  .sidebar-overlay {
    background: rgba(0, 0, 0, 0.8);
  }
  .modal-overlay {
    background: rgba(0, 0, 0, 0.8);
  }
  .toast {
    background: var(--bg-secondary);
  }
  .toast.success { background: var(--bg-secondary); }
  .toast.error   { background: var(--bg-secondary); }
  .toast.info    { background: var(--bg-secondary); }
  .toast.warning { background: var(--bg-secondary); }
  .chat-input-wrapper {
    background: var(--bg-secondary);
  }
}

/* ============================================
   Sidebar Close Button (mobile)
   ============================================ */
.sidebar-close-btn {
  display: block;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: auto;
  line-height: 1;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

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

/* ============================================
   Theme Toggle Button
   ============================================ */
.theme-toggle-btn {
  font-size: 1.1rem;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  cursor: pointer;
}

/* ============================================
   Light Mode Theme
   ============================================ */
body.light-mode {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e8eaf0;
  --bg-card: #ffffff;
  --bg-input: #f0f0f4;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-sidebar: rgba(255, 255, 255, 0.85);
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #888898;
  --accent: #5b5eed;
  --accent-hover: #4f46e5;
  --accent-light: rgba(91, 94, 237, 0.1);
  --accent-glow: rgba(91, 94, 237, 0.2);
  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

body.light-mode ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

body.light-mode ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

body.light-mode .sidebar {
  background: rgba(255, 255, 255, 0.9);
  border-right-color: rgba(0, 0, 0, 0.08);
}

body.light-mode .sidebar-overlay.visible {
  background: rgba(0, 0, 0, 0.3);
}

body.light-mode .top-bar {
  background: rgba(255, 255, 255, 0.85);
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

body.light-mode .chat-input-wrapper {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .message-bubble {
  background: var(--bg-card);
  border-color: rgba(0, 0, 0, 0.06);
}

body.light-mode .message.user .message-bubble {
  background: var(--accent-light);
  color: var(--text-primary);
}

body.light-mode .modal-overlay {
  background: rgba(0, 0, 0, 0.3);
}

body.light-mode .modal {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
}

body.light-mode .toast {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

body.light-mode .card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.06);
}

body.light-mode .admin-stat-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.06);
}

body.light-mode .form-control {
  background: var(--bg-input);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

body.light-mode .sidebar-search-input {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

body.light-mode .conversation-item.active {
  background: var(--accent-light);
}

body.light-mode .new-chat-button {
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode pre,
body.light-mode .message-bubble pre {
  background: #f0f0f4;
  border-color: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

body.light-mode code,
body.light-mode .message-bubble code {
  background: rgba(0, 0, 0, 0.05);
}

body.light-mode .role-select {
  background: var(--bg-input);
  color: var(--text-primary);
}

body.light-mode .welcome-state {
  color: var(--text-primary);
}

body.light-mode .shortcuts-help-btn {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .shortcuts-table kbd {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .message-copy-btn {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .draft-badge {
  background: var(--warning) !important;
}

body.light-mode .templates-popup {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

body.light-mode .templates-popup-header {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.light-mode .templates-popup-item {
  border-bottom-color: rgba(0, 0, 0, 0.04);
}

body.light-mode .templates-popup-item:hover {
  background: rgba(91, 94, 237, 0.06);
}

body.light-mode .template-save-modal {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

body.light-mode .template-save-modal input,
body.light-mode .template-save-modal textarea {
  background: var(--bg-input);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

body.light-mode .chat-search-bar {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

body.light-mode .chat-search-input {
  background: var(--bg-input);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

body.light-mode .conv-tag-input {
  background: var(--bg-input);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
}

body.light-mode .conv-tag-add-btn {
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .font-size-btn {
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .kbd-hint kbd {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .password-strength-bar {
  background: rgba(0, 0, 0, 0.08);
}

/* ============================================
   Model Switcher Cards
   ============================================ */
.models-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
}

.model-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--transition);
}

.model-card:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.model-card-active {
  border-color: var(--success);
  background: var(--success-bg);
}

.model-card-active:hover {
  background: var(--success-bg);
}

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

.model-card-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}

.model-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.model-card-actions {
  margin-left: 16px;
  flex-shrink: 0;
}

/* ---- Streaming token fade-in animation ---- */

.token-appear {
  display: inline;
  animation: tokenFadeIn 0.15s ease-out forwards;
}

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

/* Streaming cursor effect — blinking block cursor at end of bubble */
.message-bubble.streaming::after {
  content: '\25CB';
  animation: cursorBlink 0.8s infinite;
  color: var(--accent);
  margin-left: 1px;
  font-size: 0.85em;
}

@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ============================================
   Accessibility: Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .message.message-animate,
  .message.user.message-animate {
    animation: none;
    opacity: 1;
  }

  .token-appear {
    animation: none;
    opacity: 1;
  }

  .thinking-bubble .message-bubble {
    animation: none;
  }

  .typing-indicator span {
    animation: none;
    opacity: 0.6;
  }

  .message-bubble.streaming::after {
    animation: none;
    opacity: 1;
  }

  .thinking-status {
    transition: none;
  }
}

/* ============================================
   Chat Log Viewer (Admin)
   ============================================ */
.chatlog-viewer-modal {
  max-width: 720px;
  width: 95%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chatlog-viewer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chatlog-viewer-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.chatlog-viewer-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.chatlog-viewer-meta strong {
  color: var(--text-secondary);
}

.chatlog-close-btn {
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition);
}

.chatlog-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chatlog-viewer-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-log-message {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  max-width: 85%;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-log-message.user {
  align-self: flex-end;
  background: var(--accent-light);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.chat-log-message.assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

.chat-log-message.system {
  align-self: center;
  background: var(--warning-bg);
  border: 1px solid rgba(245, 158, 11, 0.2);
  max-width: 90%;
  font-style: italic;
}

.chat-log-message-role {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chat-log-message.user .chat-log-message-role {
  color: var(--accent-hover);
}

.chat-log-message-content {
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-primary);
}

.chat-log-message-meta {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 6px;
  opacity: 0.7;
}

/* ============================================
   Password Strength Meter
   ============================================ */

.password-strength-container {
  margin-top: 6px;
}

.password-strength-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 4px;
}

.password-strength-bar .password-strength-fill {
  height: 100%;
  border-radius: 2px;
  width: 0;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.password-strength-fill.strength-weak {
  width: 33%;
  background-color: var(--error);
}

.password-strength-fill.strength-medium {
  width: 66%;
  background-color: var(--warning);
}

.password-strength-fill.strength-strong {
  width: 100%;
  background-color: var(--success);
}

.password-strength-label {
  font-size: 0.75rem;
  line-height: 1;
}

.password-strength-label.strength-weak {
  color: var(--error);
}

.password-strength-label.strength-medium {
  color: var(--warning);
}

.password-strength-label.strength-strong {
  color: var(--success);
}

/* ============================================
   Compact Mode
   ============================================ */

body.compact-mode .message {
  gap: 8px;
  padding: 2px 0;
}

body.compact-mode .message-avatar {
  width: 28px;
  height: 28px;
  font-size: 0.65rem;
}

body.compact-mode .message-bubble {
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  border-radius: var(--radius-lg);
}

body.compact-mode .chat-messages {
  gap: 4px;
}

body.compact-mode .message-meta {
  font-size: 0.65rem;
}

body.compact-mode .message-copy-btn {
  font-size: 0.6rem;
  padding: 1px 4px;
}

#compact-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============================================
   In-Conversation Search Bar
   ============================================ */

.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-search-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.chat-search-input:focus {
  border-color: var(--accent);
}

.chat-search-counter {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 50px;
  text-align: center;
}

.chat-search-nav-btn {
  padding: 4px 8px !important;
  font-size: 0.7rem !important;
  line-height: 1 !important;
}

.chat-search-close-btn {
  padding: 4px 8px !important;
  font-size: 1rem !important;
  line-height: 1 !important;
}

.chat-messages mark {
  background: rgba(245, 158, 11, 0.4);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.chat-messages mark.current-match {
  background: rgba(245, 158, 11, 0.8);
  outline: 2px solid var(--warning);
}

/* ---- Scroll Navigation Buttons ---- */

.scroll-nav-btn {
  display: none;
  position: absolute;
  right: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(30, 30, 40, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  z-index: 20;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s, background 0.2s, transform 0.15s;
}

.scroll-nav-btn:hover {
  background: rgba(50, 50, 65, 0.75);
  transform: scale(1.08);
}

.scroll-to-bottom-btn {
  bottom: 80px;
}

.scroll-to-top-btn {
  top: 60px;
}

body.light-mode .scroll-nav-btn {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.1);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

body.light-mode .scroll-nav-btn:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* ---- Connection Status Indicator ---- */

.connection-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
  position: relative;
  transition: background-color 0.3s ease;
}

.connection-online {
  background-color: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.connection-offline {
  background-color: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.connection-offline::after {
  content: 'Offline';
  font-size: 0.7rem;
  color: #ef4444;
  margin-left: 14px;
  white-space: nowrap;
  position: absolute;
  line-height: 10px;
}

.connection-banner {
  background: rgba(239, 68, 68, 0.15);
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 49;
  position: relative;
}

body.light-mode .connection-banner {
  background: rgba(239, 68, 68, 0.08);
}

/* ---- Reconnected Toast ---- */

.reconnected-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(34, 197, 94, 0.9);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.reconnected-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Message Timestamps ---- */
.message-timestamp {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
  opacity: 0.7;
  cursor: default;
}

.message-timestamp:hover {
  opacity: 1;
}

/* ---- Conversation Tag Pills ---- */
.conv-tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}

.conv-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.58rem;
  padding: 1px 5px;
  border-radius: 8px;
  white-space: nowrap;
  line-height: 1.4;
  font-weight: 500;
  cursor: default;
}

.conv-tag-pill-delete {
  cursor: pointer;
  font-size: 0.7rem;
  margin-left: 1px;
  opacity: 0;
  transition: opacity 0.15s;
}

.conv-tag-pill:hover .conv-tag-pill-delete {
  opacity: 1;
}

.conv-tag-add-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 5px;
  font-size: 0.85rem;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  line-height: 1.4;
}

.conv-tag-add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.conversation-item:hover .conv-tag-add-btn,
.conversation-item.active .conv-tag-add-btn {
  opacity: 1;
}

.conv-tag-input-wrap {
  margin-top: 3px;
}

.conv-tag-input {
  background: var(--bg-input, rgba(255,255,255,0.06));
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.68rem;
  width: 90px;
  outline: none;
}

.conv-tag-input:focus {
  border-color: var(--accent);
}
