:root {
  /* === Base Theme Variables (Ocean - Default) === */
  --bg-primary: #0d1225;
  --bg-secondary: #111827;
  --bg-surface: #1a1f35;
  --bg-surface-hover: #222840;
  --bg-elevated: #1e2440;
  --bg-glass: rgba(13, 18, 37, 0.85);
  
  --border-light: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.10);
  --border-accent: rgba(59, 130, 246, 0.25);
  
  --text-primary: #f0f4ff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #60a5fa;
  
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  
  /* Utility colors (fixed across themes) */
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.08);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  
  --font-sans: 'TH Sarabun', 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Noto Sans Thai UI', monospace;
  
  --sidebar-width: 300px;
  --header-height: 60px;
  
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================================
   BACKWARD COMPAT: map old var names to new
   ============================================================ */
:root {
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Ocean Blue (default)
   ============================================================ */
[data-theme="ocean"] {
  --bg-primary: #0d1225;
  --bg-secondary: #111827;
  --bg-surface: #1a1f35;
  --bg-surface-hover: #222840;
  --bg-elevated: #1e2440;
  --bg-glass: rgba(13, 18, 37, 0.85);
  --border-accent: rgba(59, 130, 246, 0.25);
  --text-accent: #60a5fa;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Midnight Purple
   ============================================================ */
[data-theme="midnight"] {
  --bg-primary: #0f0a1a;
  --bg-secondary: #140f20;
  --bg-surface: #1e1830;
  --bg-surface-hover: #262040;
  --bg-elevated: #221c38;
  --bg-glass: rgba(15, 10, 26, 0.85);
  --border-accent: rgba(139, 92, 246, 0.25);
  --text-accent: #a78bfa;
  --accent-color: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.15);
  --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Forest Emerald
   ============================================================ */
[data-theme="forest"] {
  --bg-primary: #0a1a12;
  --bg-secondary: #0f2016;
  --bg-surface: #183022;
  --bg-surface-hover: #20402a;
  --bg-elevated: #1c3826;
  --bg-glass: rgba(10, 26, 18, 0.85);
  --border-accent: rgba(16, 185, 129, 0.25);
  --text-accent: #34d399;
  --accent-color: #10b981;
  --accent-hover: #059669;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Sunset Amber
   ============================================================ */
[data-theme="sunset"] {
  --bg-primary: #1a1208;
  --bg-secondary: #20180c;
  --bg-surface: #302410;
  --bg-surface-hover: #403018;
  --bg-elevated: #382814;
  --bg-glass: rgba(26, 18, 8, 0.85);
  --border-accent: rgba(245, 158, 11, 0.25);
  --text-accent: #fbbf24;
  --accent-color: #f59e0b;
  --accent-hover: #d97706;
  --accent-glow: rgba(245, 158, 11, 0.15);
  --shadow-glow: 0 0 20px rgba(245, 158, 11, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Rose Pink
   ============================================================ */
[data-theme="rose"] {
  --bg-primary: #1a0a10;
  --bg-secondary: #200f14;
  --bg-surface: #301820;
  --bg-surface-hover: #40202a;
  --bg-elevated: #381c24;
  --bg-glass: rgba(26, 10, 16, 0.85);
  --border-accent: rgba(244, 63, 94, 0.25);
  --text-accent: #fb7185;
  --accent-color: #f43f5e;
  --accent-hover: #e11d48;
  --accent-glow: rgba(244, 63, 94, 0.15);
  --shadow-glow: 0 0 20px rgba(244, 63, 94, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   THEME: Cyber Cyan
   ============================================================ */
[data-theme="cyber"] {
  --bg-primary: #0a1218;
  --bg-secondary: #0e1820;
  --bg-surface: #162430;
  --bg-surface-hover: #1e3040;
  --bg-elevated: #1a2838;
  --bg-glass: rgba(10, 18, 24, 0.85);
  --border-accent: rgba(6, 182, 212, 0.25);
  --text-accent: #22d3ee;
  --accent-color: #06b6d4;
  --accent-hover: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.15);
  --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.08);
  --accent-blue: var(--accent-color);
  --accent-blue-hover: var(--accent-hover);
  --accent-blue-glow: var(--accent-glow);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { color: var(--text-accent); }

::selection {
  background: var(--accent-blue-glow);
  color: var(--text-primary);
}

::-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;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar user info — ซ่อนไว้ ใช้ header version แทน */
.user-info {
  display: none !important;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-base);
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  image-rendering: auto;
  flex-shrink: 0;
  background: var(--bg-surface);
  padding: 3px;
  box-shadow: 0 0 0 1px var(--border-accent), 0 2px 8px rgba(59, 130, 246, 0.15);
}

.logo-text h1 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  background: linear-gradient(135deg, #f0f4ff, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-text .sub {
  font-size: 10px;
  color: var(--text-muted);
  -webkit-text-fill-color: var(--text-muted);
  letter-spacing: 0.3px;
}

.new-chat-btn {
  margin-top: 14px;
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-medium);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.new-chat-btn:hover {
  background: var(--bg-surface);
  border-color: var(--border-accent);
  color: var(--text-primary);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

.conv-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: 2px;
  border: 1px solid transparent;
  position: relative;
}

.conv-item:hover {
  background: var(--bg-surface);
}

.conv-item.active {
  background: var(--bg-surface);
  border-color: var(--border-accent);
}

.conv-item .conv-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.conv-item .conv-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.conv-item .conv-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.conv-item:hover .conv-delete {
  opacity: 1;
}

.conv-item .conv-delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
/* ============================================================
   LOGIN OVERLAY — Premium Design
   ============================================================ */

/* --- Animated Background --- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0a0e1a 0%, #0d1225 30%, #0f1a35 60%, #0a1628 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  overflow: hidden;
}

/* Grid pattern overlay */
.login-bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(59, 130, 246, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 130, 246, 0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 60% 50% at 50% 50%, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 60% 50% at 50% 50%, black 30%, transparent 70%);
  animation: gridShift 20s linear infinite;
}

@keyframes gridShift {
  0% { transform: translate(0, 0); }
  50% { transform: translate(30px, 15px); }
  100% { transform: translate(0, 0); }
}

/* Floating orbs */
.login-bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  pointer-events: none;
}

.login-bg-orb-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, #3b82f6, transparent);
  top: -200px;
  right: -150px;
  animation: orbFloat1 12s ease-in-out infinite;
}

.login-bg-orb-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #06b6d4, transparent);
  bottom: -200px;
  left: -150px;
  animation: orbFloat2 15s ease-in-out infinite;
}

.login-bg-orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #10b981, transparent);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: orbFloat3 18s ease-in-out infinite;
}

@keyframes orbFloat1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-50px, 60px) scale(1.1); }
  66% { transform: translate(30px, -40px) scale(0.9); }
}

@keyframes orbFloat2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, -50px) scale(1.15); }
  66% { transform: translate(-40px, 30px) scale(0.85); }
}

@keyframes orbFloat3 {
  0%, 100% { opacity: 0.1; transform: translate(-50%, -50%) scale(0.9); }
  50% { opacity: 0.2; transform: translate(-50%, -50%) scale(1.3); }
}

/* Floating particles */
.login-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

@keyframes particleFloat1 {
  0%, 100% { transform: translate(0, 0) rotate(0deg); opacity: 0.3; }
  25% { transform: translate(20px, -30px) rotate(90deg); opacity: 0.5; }
  50% { transform: translate(-15px, 10px) rotate(180deg); opacity: 0.2; }
  75% { transform: translate(10px, -20px) rotate(270deg); opacity: 0.4; }
}

@keyframes particleFloat2 {
  0%, 100% { transform: translate(0, 0); opacity: 0.2; }
  33% { transform: translate(-25px, 15px); opacity: 0.4; }
  66% { transform: translate(15px, -25px); opacity: 0.1; }
}

@keyframes particleFloat3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, 20px) scale(1.2); opacity: 0.3; }
}

/* --- Card Glassmorphism --- */
.login-card {
  position: relative;
  background: linear-gradient(
    160deg,
    rgba(26, 31, 53, 0.95) 0%,
    rgba(22, 28, 50, 0.9) 40%,
    rgba(30, 36, 64, 0.92) 100%
  );
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 24px;
  width: 420px;
  max-width: 92vw;
  overflow: hidden;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(59, 130, 246, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: cardEntrance 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: 1;
}

@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Accent bar at top of card */
.login-card-accent {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #3b82f6, #06b6d4, #10b981, #3b82f6);
  background-size: 300% 100%;
  animation: accentSweep 4s ease-in-out infinite;
}

@keyframes accentSweep {
  0%, 100% { background-position: 0% 0%; }
  50% { background-position: 100% 0%; }
}

/* --- Header --- */
.login-header {
  text-align: center;
  padding: 44px 36px 20px;
  position: relative;
}

.login-logo {
  margin-bottom: 16px;
}

.login-logo-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(6, 182, 212, 0.1));
  position: relative;
  animation: logoPulse 3s ease-in-out infinite;
}

.login-logo-ring::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(59, 130, 246, 0.3), rgba(6, 182, 212, 0.3), transparent);
  mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #fff calc(100% - 1.5px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #fff calc(100% - 1.5px));
  animation: ringRotate 6s linear infinite;
}

@keyframes ringRotate {
  to { transform: rotate(360deg); }
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.logo-img-large {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow:
    0 0 0 2px rgba(59, 130, 246, 0.2),
    0 8px 32px rgba(59, 130, 246, 0.2);
  animation: logoGlow 3s ease-in-out infinite;
}

@keyframes logoGlow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2), 0 8px 32px rgba(59, 130, 246, 0.2); }
  50% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35), 0 8px 40px rgba(59, 130, 246, 0.35); }
}

.login-header h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 2px;
  color: #fff;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #f0f4ff 0%, #93c5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fadeSlideUp 0.6s 0.2s both;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 18px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 400;
  opacity: 0.7;
  animation: fadeSlideUp 0.6s 0.3s both;
}

/* Divider with icon */
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  animation: fadeSlideUp 0.6s 0.4s both;
}

.login-divider-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

.login-divider-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-accent);
  font-size: 13px;
}

/* --- Body --- */
.login-body {
  padding: 0 36px 28px;
  animation: fadeSlideUp 0.6s 0.5s both;
}

.login-error {
  color: var(--error);
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 8px;
  display: none;
}

.login-error.visible {
  display: block;
}

/* --- Button Premium --- */
.login-btn {
  width: 100%;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  font-family: 'TH Sarabun', 'Sarabun', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.login-btn i {
  font-size: 16px;
  position: relative;
  z-index: 1;
}

.login-btn .btn-text {
  position: relative;
  z-index: 1;
}

/* OAuth Button */
.login-btn-oauth {
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #fff;
  font-size: 17px;
  padding: 16px 24px;
  box-shadow:
    0 4px 20px rgba(20,184,166,0.3),
    inset 0 1px 0 rgba(255,255,255,0.15);
  animation: loginBtnShift 12s ease-in-out infinite, fadeSlideUp 0.6s 0.6s both;
}

@keyframes loginBtnShift {
  0%, 100% { background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 4px 20px rgba(20,184,166,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  10%      { background: linear-gradient(135deg, #06b6d4, #0891b2); box-shadow: 0 4px 20px rgba(6,182,212,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  20%      { background: linear-gradient(135deg, #0ea5e9, #0284c7); box-shadow: 0 4px 20px rgba(14,165,233,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  30%      { background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 4px 20px rgba(99,102,241,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  40%      { background: linear-gradient(135deg, #8b5cf6, #7c3aed); box-shadow: 0 4px 20px rgba(139,92,246,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  50%      { background: linear-gradient(135deg, #ec4899, #db2777); box-shadow: 0 4px 20px rgba(236,72,153,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  60%      { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 4px 20px rgba(244,63,94,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  70%      { background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 4px 20px rgba(249,115,22,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  80%      { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 4px 20px rgba(245,158,11,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
  90%      { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 4px 20px rgba(16,185,129,0.3), inset 0 1px 0 rgba(255,255,255,0.15); }
}

@keyframes loginBtnShiftHover {
  0%, 100% { background: linear-gradient(135deg, #2dd4bf, #14b8a6); box-shadow: 0 8px 32px rgba(20,184,166,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  10%      { background: linear-gradient(135deg, #22d3ee, #06b6d4); box-shadow: 0 8px 32px rgba(6,182,212,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  20%      { background: linear-gradient(135deg, #38bdf8, #0ea5e9); box-shadow: 0 8px 32px rgba(14,165,233,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  30%      { background: linear-gradient(135deg, #818cf8, #6366f1); box-shadow: 0 8px 32px rgba(99,102,241,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  40%      { background: linear-gradient(135deg, #a78bfa, #8b5cf6); box-shadow: 0 8px 32px rgba(139,92,246,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  50%      { background: linear-gradient(135deg, #f472b6, #ec4899); box-shadow: 0 8px 32px rgba(236,72,153,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  60%      { background: linear-gradient(135deg, #fb7185, #f43f5e); box-shadow: 0 8px 32px rgba(244,63,94,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  70%      { background: linear-gradient(135deg, #fb923c, #f97316); box-shadow: 0 8px 32px rgba(249,115,22,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  80%      { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 8px 32px rgba(245,158,11,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
  90%      { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 8px 32px rgba(16,185,129,0.5), inset 0 1px 0 rgba(255,255,255,0.25); }
}

.login-btn-oauth:hover {
  transform: translateY(-3px) scale(1.01);
  animation: loginBtnShiftHover 12s ease-in-out infinite, fadeSlideUp 0.6s 0.6s both;
}

.login-btn-oauth:active {
  transform: translateY(-1px) scale(0.99);
}

.login-btn-oauth i {
  font-size: 18px;
}

/* Button shimmer */
.btn-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.08) 30%,
    rgba(255,255,255,0.15) 50%,
    rgba(255,255,255,0.08) 70%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Hint text below button */
.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.5;
  margin: 14px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  animation: fadeSlideUp 0.6s 0.7s both;
}

.login-hint i {
  font-size: 11px;
  opacity: 0.6;
}

/* --- Footer --- */
.login-footer {
  padding: 0;
  position: relative;
}

.login-footer::before {
  content: '';
  display: block;
  height: 1px;
  margin: 0 36px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}

.login-footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 36px 20px;
  animation: fadeSlideUp 0.6s 0.8s both;
}

.login-footer-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(244, 63, 94, 0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f43f5e;
  font-size: 14px;
  flex-shrink: 0;
}

.login-footer-text p {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.85;
  margin: 0;
  line-height: 1.5;
}

.login-footer-text p:first-child {
  font-weight: 600;
  opacity: 1;
  color: var(--text-primary);
}

/* --- Shared Animation --- */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .login-card {
    border-radius: 20px;
    width: 100%;
    max-width: 92vw;
  }

  .login-header {
    padding: 32px 24px 16px;
  }
  .login-body {
    padding: 0 24px 24px;
  }
  .login-footer::before {
    margin: 0 24px;
  }
  .login-footer-inner {
    padding: 14px 24px 18px;
  }

  .login-logo-ring {
    width: 76px;
    height: 76px;
  }
  .logo-img-large {
    width: 48px;
    height: 48px;
    border-radius: 13px;
  }
  .login-header h1 {
    font-size: 22px;
  }
  .login-subtitle {
    font-size: 12px;
    letter-spacing: 1px;
  }
  .login-btn-oauth {
    font-size: 15px;
    padding: 14px 20px;
  }
}

/* ============================================================
   USER INFO (sidebar footer)
   ============================================================ */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar i {
  font-size: 16px;
  color: #fff;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-code {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.logout-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* @keyframes */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.sidebar-footer {
  padding: 12px 14px 8px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.online { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,0.4); }
.status-dot.offline { background: var(--error); box-shadow: 0 0 8px rgba(239,68,68,0.4); }
.status-dot.warning { background: var(--warning); box-shadow: 0 0 8px rgba(245,158,11,0.4); }

/* ============================================================
   THEME PICKER
   ============================================================ */
.theme-picker {
  margin: 2px 0;
  position: relative;
}

.theme-toggle-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.theme-toggle-btn i:first-child {
  font-size: 13px;
  color: var(--accent-color);
}

.theme-chevron {
  margin-left: auto;
  font-size: 10px;
  transition: transform var(--transition-base);
  color: var(--text-muted);
}

.theme-picker.open .theme-chevron {
  transform: rotate(180deg);
}

.theme-options {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 8px;
  margin-top: 4px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.theme-picker.open .theme-options {
  display: grid;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.theme-option:hover {
  background: var(--bg-surface-hover);
}

.theme-option.active {
  border-color: var(--border-accent);
  background: var(--accent-glow);
}

.theme-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.theme-option.active .theme-swatch {
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--accent-color);
}

.theme-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1;
}

.theme-option.active .theme-label {
  color: var(--text-accent);
}

/* Developer Credit — ใต้ theme picker */
.sidebar-dev-credit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  letter-spacing: 0.3px;
}
.sidebar-dev-credit i {
  font-size: 12px;
  color: var(--accent-blue, #3b82f6);
}

/* Smooth theme transitions on body */
body {
  transition: background-color 0.3s ease,
              color 0.3s ease;
}

.sidebar,
.header,
.input-wrapper,
.login-card,
.message-bubble,
.conv-item {
  transition: background-color 0.25s ease,
              border-color 0.25s ease,
              box-shadow 0.25s ease;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
.header {
  height: var(--header-height);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.4);
  flex-shrink: 0;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left .conv-name {
  font-size: 15px;
  font-weight: 600;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--transition-fast);
}

.sidebar-toggle:hover {
  background: var(--bg-surface);
}

.header-center {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.header-logo-img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: cover;
  opacity: 0.9;
  box-shadow: 0 0 0 1px var(--border-accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  cursor: default;
}
.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
}
.header-user-details {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.header-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  white-space: nowrap;
}
.header-user-code {
  font-size: 10px;
  color: var(--text-muted);
}
.header-logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}
.header-logout-btn:hover {
  background: rgba(239,68,68,0.1);
  color: var(--error);
}

.header-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  cursor: default;
}
.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
}
.header-user-details {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.header-user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  white-space: nowrap;
}
.header-user-code {
  font-size: 10px;
  color: var(--text-muted);
}
.header-logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}
.header-logout-btn:hover {
  background: rgba(239,68,68,0.1);
  color: var(--error);
}

/* Header Clock — centered date & time display */
.header-clock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.clock-date {
  font-size: 14px;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

.clock-sep {
  font-size: 14px;
  color: var(--text-muted);
  opacity: 0.4;
}

.clock-time {
  font-size: 14px;
  color: var(--accent-blue);
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* Header title — smaller below clock */
.header-center .header-title {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  font-weight: 500;
  line-height: 1.3;
}

.header-center .header-subtitle {
  font-size: 9px;
  color: var(--text-muted);
  opacity: 0.5;
  line-height: 1.3;
}

/* Attached files in messages */
.msg-attached-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.msg-attached-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  font-size: 11px;
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 12px;
  color: var(--accent-blue);
  font-weight: 500;
}
.msg-attached-chip i {
  font-size: 12px;
}

/* Message Timestamp *//* Message Timestamp */
.message-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  padding-left: 46px;
  font-weight: 400;
  opacity: 0.5;
}

.message.assistant .message-time {
  color: var(--text-muted);
  opacity: 0.5;
}

.provider-badge {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.provider-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ============================================================
   CHAT AREA
   ============================================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  background: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.03) 0%, transparent 60%);
}

.messages-container {
  flex: 1;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 40px 5% 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.messages-container:not(.has-messages) {
  padding: 60px 5% 20px;
}

.messages-container.has-messages {
  justify-content: flex-start;
}

@media (min-width: 1200px) {
  .messages-container {
    padding: 50px 12% 24px;
  }
  .messages-container:not(.has-messages) {
    padding: 80px 12% 24px;
  }

  .input-area {
    padding: 12px 12% 14px;
  }
}

@media (min-width: 1600px) {
  .messages-container {
    padding: 60px 18% 28px;
  }
  .messages-container:not(.has-messages) {
    padding: 100px 18% 28px;
  }

  .input-area {
    padding: 14px 18% 16px;
  }
}

/* ============================================================
   WELCOME SCREEN
   ============================================================ */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 48px 24px 24px;
  animation: msgIn 0.4s ease backwards;
  width: 100%;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(59,130,246,0.18), rgba(6,182,212,0.12));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  margin-bottom: 24px;
  border: 1px solid var(--border-accent);
  box-shadow: 0 0 40px rgba(59,130,246,0.08);
  animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 40px rgba(59,130,246,0.08); }
  50% { box-shadow: 0 0 60px rgba(59,130,246,0.18); }
}

.welcome-message h2 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 10px;
  background: linear-gradient(135deg, #f0f4ff, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-message > p {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 0 6px;
  max-width: 500px;
  line-height: 1.6;
}

.welcome-hint {
  font-size: 13px !important;
  color: var(--text-muted) !important;
  margin-bottom: 24px !important;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 540px;
  width: 100%;
  margin: 16px 0 8px;
}

.suggestion-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.suggestion-btn i {
  font-size: 16px;
  color: var(--accent-color);
  width: 20px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.suggestion-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.suggestion-btn:hover i {
  transform: scale(1.15);
}

.suggestion-btn:active {
  transform: translateY(0);
}

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
  animation: msgIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.message.user {
  align-items: flex-end;
}

.message-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
}

.message.user .message-row {
  flex-direction: row-reverse;
}

.message-content {
  line-height: 1.65;
  font-size: 14px;
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  color: #fff;
}

.message.user .message-avatar {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.message-bubble {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 14px;
  position: relative;
}

.bubble-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
}

.bubble-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-accent);
  opacity: 0.85;
}

.message.user .bubble-role {
  color: rgba(255,255,255,0.8);
}

.bubble-time {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
  white-space: nowrap;
}

.message.user .bubble-time {
  color: rgba(255,255,255,0.6);
}

.message.assistant .message-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-top-left-radius: 4px;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
  border: none;
  border-top-right-radius: 4px;
  color: #fff;
  box-shadow: 0 2px 10px rgba(59,130,246,0.2);
}

.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble pre {
  margin: 10px 0;
  padding: 14px 16px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  border: 1px solid var(--border-light);
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-bubble pre code {
  background: none;
  padding: 0;
}

.message-bubble ul, .message-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message-bubble li {
  margin-bottom: 4px;
}

/* ============================================================
   TOOL CALL DISPLAY
   ============================================================ */
.tool-call {
  margin: 8px 0;
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.tool-call-header {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-accent);
  cursor: pointer;
  user-select: none;
  background: rgba(59, 130, 246, 0.04);
}

.tool-call-header .tool-icon {
  font-size: 14px;
}

.tool-call-body {
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-light);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-call-body.success {
  border-left: 2px solid var(--success);
}

.tool-call-body.error {
  border-left: 2px solid var(--error);
}

/* ============================================================
   PATIENT CARD (Tool Result)
   ============================================================ */
.patient-card-result {
  margin: 10px 0;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.patient-card-result .patient-photo {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  background: var(--bg-surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--text-muted);
}

.patient-card-result .patient-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.patient-card-result .patient-info {
  flex: 1;
  min-width: 0;
}

.patient-card-result .patient-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 2px;
}

.patient-card-result .patient-detail {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 6px;
}

.patient-card-result .patient-detail span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================
   TABLE DISPLAY
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
}

.data-table th {
  background: var(--bg-surface);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-light);
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

.data-table .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
}

.badge-waiting { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-exam { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-er { background: rgba(239,68,68,0.15); color: var(--error); }
.badge-complete { background: rgba(16,185,129,0.15); color: var(--success); }

/* ============================================================
   TYPING INDICATOR
   ============================================================ */
.typing-indicator {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: msgIn 0.3s ease backwards;
}

.typing-indicator .typing-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  border-top-left-radius: 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   INPUT AREA
   ============================================================ */
@keyframes accentLine {
  0%, 100% { background: linear-gradient(90deg, transparent, rgba(20,184,166,0.6), transparent); }
  10%      { background: linear-gradient(90deg, transparent, rgba(6,182,212,0.6), transparent); }
  20%      { background: linear-gradient(90deg, transparent, rgba(14,165,233,0.6), transparent); }
  30%      { background: linear-gradient(90deg, transparent, rgba(99,102,241,0.6), transparent); }
  40%      { background: linear-gradient(90deg, transparent, rgba(139,92,246,0.6), transparent); }
  50%      { background: linear-gradient(90deg, transparent, rgba(236,72,153,0.6), transparent); }
  60%      { background: linear-gradient(90deg, transparent, rgba(244,63,94,0.6), transparent); }
  70%      { background: linear-gradient(90deg, transparent, rgba(249,115,22,0.6), transparent); }
  80%      { background: linear-gradient(90deg, transparent, rgba(245,158,11,0.6), transparent); }
  90%      { background: linear-gradient(90deg, transparent, rgba(16,185,129,0.6), transparent); }
}
@keyframes borderPulse {
  0%, 100% {
    border-color: rgba(20,184,166,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(20,184,166,0.08);
  }
  10% {
    border-color: rgba(6,182,212,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(6,182,212,0.08);
  }
  20% {
    border-color: rgba(14,165,233,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(14,165,233,0.08);
  }
  30% {
    border-color: rgba(99,102,241,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(99,102,241,0.08);
  }
  40% {
    border-color: rgba(139,92,246,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(139,92,246,0.08);
  }
  50% {
    border-color: rgba(236,72,153,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(236,72,153,0.08);
  }
  60% {
    border-color: rgba(244,63,94,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(244,63,94,0.08);
  }
  70% {
    border-color: rgba(249,115,22,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(249,115,22,0.08);
  }
  80% {
    border-color: rgba(245,158,11,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(245,158,11,0.08);
  }
  90% {
    border-color: rgba(16,185,129,0.35);
    box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04), 0 0 12px rgba(16,185,129,0.08);
  }
}
@keyframes borderPulseFocus {
  0%, 100% {
    border-color: rgba(20,184,166,0.7);
    box-shadow: 0 0 40px rgba(20,184,166,0.25), 0 0 0 3px rgba(20,184,166,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  10% {
    border-color: rgba(6,182,212,0.7);
    box-shadow: 0 0 40px rgba(6,182,212,0.25), 0 0 0 3px rgba(6,182,212,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  20% {
    border-color: rgba(14,165,233,0.7);
    box-shadow: 0 0 40px rgba(14,165,233,0.25), 0 0 0 3px rgba(14,165,233,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  30% {
    border-color: rgba(99,102,241,0.7);
    box-shadow: 0 0 40px rgba(99,102,241,0.25), 0 0 0 3px rgba(99,102,241,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  40% {
    border-color: rgba(139,92,246,0.7);
    box-shadow: 0 0 40px rgba(139,92,246,0.25), 0 0 0 3px rgba(139,92,246,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  50% {
    border-color: rgba(236,72,153,0.7);
    box-shadow: 0 0 40px rgba(236,72,153,0.25), 0 0 0 3px rgba(236,72,153,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  60% {
    border-color: rgba(244,63,94,0.7);
    box-shadow: 0 0 40px rgba(244,63,94,0.25), 0 0 0 3px rgba(244,63,94,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  70% {
    border-color: rgba(249,115,22,0.7);
    box-shadow: 0 0 40px rgba(249,115,22,0.25), 0 0 0 3px rgba(249,115,22,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  80% {
    border-color: rgba(245,158,11,0.7);
    box-shadow: 0 0 40px rgba(245,158,11,0.25), 0 0 0 3px rgba(245,158,11,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
  90% {
    border-color: rgba(16,185,129,0.7);
    box-shadow: 0 0 40px rgba(16,185,129,0.25), 0 0 0 3px rgba(16,185,129,0.12), inset 0 1px 0 rgba(255,255,255,0.06);
  }
}
@keyframes btnShift {
  0%, 100% { background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 2px 8px rgba(20,184,166,0.25); }
  10%      { background: linear-gradient(135deg, #06b6d4, #0891b2); box-shadow: 0 2px 8px rgba(6,182,212,0.25); }
  20%      { background: linear-gradient(135deg, #0ea5e9, #0284c7); box-shadow: 0 2px 8px rgba(14,165,233,0.25); }
  30%      { background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 2px 8px rgba(99,102,241,0.25); }
  40%      { background: linear-gradient(135deg, #8b5cf6, #7c3aed); box-shadow: 0 2px 8px rgba(139,92,246,0.25); }
  50%      { background: linear-gradient(135deg, #ec4899, #db2777); box-shadow: 0 2px 8px rgba(236,72,153,0.25); }
  60%      { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 2px 8px rgba(244,63,94,0.25); }
  70%      { background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 2px 8px rgba(249,115,22,0.25); }
  80%      { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 2px 8px rgba(245,158,11,0.25); }
  90%      { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 2px 8px rgba(16,185,129,0.25); }
}
@keyframes btnShiftActive {
  0%, 100% { background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 4px 20px rgba(20,184,166,0.4); }
  10%      { background: linear-gradient(135deg, #06b6d4, #0891b2); box-shadow: 0 4px 20px rgba(6,182,212,0.4); }
  20%      { background: linear-gradient(135deg, #0ea5e9, #0284c7); box-shadow: 0 4px 20px rgba(14,165,233,0.4); }
  30%      { background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 4px 20px rgba(99,102,241,0.4); }
  40%      { background: linear-gradient(135deg, #8b5cf6, #7c3aed); box-shadow: 0 4px 20px rgba(139,92,246,0.4); }
  50%      { background: linear-gradient(135deg, #ec4899, #db2777); box-shadow: 0 4px 20px rgba(236,72,153,0.4); }
  60%      { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 4px 20px rgba(244,63,94,0.4); }
  70%      { background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 4px 20px rgba(249,115,22,0.4); }
  80%      { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 4px 20px rgba(245,158,11,0.4); }
  90%      { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 4px 20px rgba(16,185,129,0.4); }
}
@keyframes btnShiftHover {
  0%, 100% { background: linear-gradient(135deg, #2dd4bf, #14b8a6); box-shadow: 0 6px 28px rgba(20,184,166,0.5); }
  10%      { background: linear-gradient(135deg, #22d3ee, #06b6d4); box-shadow: 0 6px 28px rgba(6,182,212,0.5); }
  20%      { background: linear-gradient(135deg, #38bdf8, #0ea5e9); box-shadow: 0 6px 28px rgba(14,165,233,0.5); }
  30%      { background: linear-gradient(135deg, #818cf8, #6366f1); box-shadow: 0 6px 28px rgba(99,102,241,0.5); }
  40%      { background: linear-gradient(135deg, #a78bfa, #8b5cf6); box-shadow: 0 6px 28px rgba(139,92,246,0.5); }
  50%      { background: linear-gradient(135deg, #f472b6, #ec4899); box-shadow: 0 6px 28px rgba(236,72,153,0.5); }
  60%      { background: linear-gradient(135deg, #fb7185, #f43f5e); box-shadow: 0 6px 28px rgba(244,63,94,0.5); }
  70%      { background: linear-gradient(135deg, #fb923c, #f97316); box-shadow: 0 6px 28px rgba(249,115,22,0.5); }
  80%      { background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 6px 28px rgba(245,158,11,0.5); }
  90%      { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 6px 28px rgba(16,185,129,0.5); }
}

.input-area {
  border-top: 1px solid transparent;
  padding: 16px 5% 18px;
  background: linear-gradient(180deg, transparent 0%, rgba(15,23,42,0.95) 30%, rgba(15,23,42,1) 100%);
  backdrop-filter: blur(24px) saturate(1.4);
  flex-shrink: 0;
  position: relative;
}
.input-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  animation: accentLine 12s ease-in-out infinite;
}

.input-wrapper {
  width: 100%;
  max-width: 100%;
  margin: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: linear-gradient(135deg, rgba(30,41,59,0.95), rgba(15,23,42,0.98));
  border: 2px solid rgba(20,184,166,0.3);
  border-radius: 16px;
  padding: 6px 6px 6px 4px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04);
  animation: borderPulse 12s ease-in-out infinite;
}

@media (min-width: 1200px) {
  .input-area {
    padding: 20px 10% 24px;
  }
}

@media (min-width: 1600px) {
  .input-area {
    padding: 20px 15% 24px;
  }
}

.input-wrapper:focus-within {
  border-color: rgba(20,184,166,0.6);
  box-shadow: 0 0 30px rgba(20,184,166,0.15), 0 0 0 3px rgba(20,184,166,0.1), inset 0 1px 0 rgba(255,255,255,0.06);
  background: linear-gradient(135deg, rgba(30,41,59,1), rgba(15,23,42,1));
  animation: borderPulseFocus 12s ease-in-out infinite;
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  padding: 12px 16px;
  resize: none;
  min-height: 24px;
  max-height: 150px;
}

.input-wrapper textarea::placeholder {
  color: rgba(148,163,184,0.5);
  font-size: 14px;
  letter-spacing: 0.3px;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.25s ease;
  flex-shrink: 0;
  opacity: 0.5;
  animation: btnShift 12s ease-in-out infinite;
}

.send-btn.active {
  opacity: 1;
  animation: btnShiftActive 12s ease-in-out infinite;
}

.send-btn.active:hover {
  transform: scale(1.08) translateY(-1px);
  animation: btnShiftHover 12s ease-in-out infinite;
}

.send-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  box-shadow: none !important;
  animation: none;
  background: rgba(100,116,139,0.3);
}

.input-tools {
  max-width: 820px;
  margin: 6px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.input-tools .tool-hint {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-tools .tool-hint kbd {
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
}

/* ============================================================
   SEARCH OVERLAY (for patient search)
   ============================================================ */
.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

.search-overlay.active {
  display: flex;
}

.search-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  width: 600px;
  max-width: 90vw;
  max-height: 70vh;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.search-modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-modal-header input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
}

.search-modal-header input::placeholder {
  color: var(--text-muted);
}

.search-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-modal-close:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.search-modal-body {
  padding: 8px;
  max-height: calc(70vh - 70px);
  overflow-y: auto;
}

.search-result-item {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background var(--transition-fast);
}

.search-result-item:hover {
  background: var(--bg-surface);
}

.search-result-item .sr-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-result-item .sr-info {
  flex: 1;
  min-width: 0;
}

.search-result-item .sr-name {
  font-size: 14px;
  font-weight: 600;
}

.search-result-item .sr-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   FILE UPLOAD
   ============================================================ */

.attach-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: all 0.2s;
}
.attach-btn:hover {
  color: var(--accent-color);
  background: rgba(255,255,255,0.05);
}

.file-previews {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  max-width: 90vw;
  max-height: 100px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.file-previews:empty {
  display: none;
}
@media (max-width: 768px) {
  .file-previews { bottom: 100px; max-width: 95vw; }
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-primary);
  animation: fileIn 0.25s ease-out;
}
.file-preview-info {
  display: flex;
  gap: 10px;
  min-width: 0;
}
.file-preview-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}
.file-preview-meta {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
}
.file-status {
  white-space: nowrap;
}
.file-size {
  opacity: 0.6;
}
.file-preview-item .remove-file {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  padding: 0 2px;
}
.file-preview-item .remove-file:hover {
  color: #ef4444;
}
.file-preview-item i {
  font-size: 14px;
  color: var(--accent-color);
}

@keyframes fileIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Drag & Drop Overlay */
.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.drop-overlay.active {
  display: flex;
}
.drop-overlay .drop-content {
  text-align: center;
  color: var(--text-accent);
  padding: 40px;
  border: 2px dashed var(--accent-color);
  border-radius: var(--radius-lg);
  background: rgba(0,0,0,0.4);
}
.drop-overlay .drop-content i {
  font-size: 48px;
  margin-bottom: 12px;
}
.drop-overlay .drop-content p {
  font-size: 16px;
  margin: 0;
}

/* Attached files in messages */
.message-attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  padding: 8px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}
.message-attachment i {
  font-size: 18px;
  color: var(--accent-color);
}
.message-attachment .att-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-attachment .att-size {
  color: var(--text-muted);
  flex-shrink: 0;
}
.message-attachment img.preview {
  max-width: 200px;
  max-height: 150px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

/* ============================================================
   SKILLS UI
   ============================================================ */

.skills-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.skills-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.skills-panel {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 320px;
  max-height: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  overflow: hidden;
  z-index: 50;
}
.skills-panel.active {
  display: block;
}
.skills-panel .panel-header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.skills-panel .panel-list {
  overflow-y: auto;
  max-height: 300px;
  padding: 8px 0;
}
.skills-panel .skill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.skills-panel .skill-item:hover {
  background: rgba(255,255,255,0.04);
}
.skills-panel .skill-item i {
  width: 16px;
  color: var(--accent-color);
}
.skills-panel .skill-item .skill-name {
  flex: 1;
  color: var(--text-primary);
}
.skills-panel .skill-item .skill-desc {
  color: var(--text-muted);
  font-size: 11px;
}

/* ============================================================
   PROGRESS PANEL
   ============================================================ */

.progress-panel {
  margin: 8px 48px 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  font-size: 12px;
  line-height: 1.6;
  animation: progressIn 0.3s ease-out;
}

@keyframes progressIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.progress-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.progress-item.active {
  color: var(--text-secondary);
}

.progress-item.done {
  color: var(--text-muted);
  opacity: 0.7;
}

.progress-item i {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.progress-item.active i.fa-spinner,
.progress-item.active i.fa-cog {
  color: var(--accent-color);
}

.progress-item.done i {
  color: var(--success);
}

/* Chat Image */
.chat-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-md);
  margin: 12px auto;
  display: block;
  object-fit: contain;
  background: rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-image:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* Chat Download Link — styled like a button */
.chat-download-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  margin: 8px 0;
  background: linear-gradient(135deg, rgba(16,185,129,0.15), rgba(59,130,246,0.10));
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: var(--radius-md);
  color: var(--accent-color, #10b981);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
}
.chat-download-link:hover {
  background: linear-gradient(135deg, rgba(16,185,129,0.25), rgba(59,130,246,0.15));
  border-color: rgba(16,185,129,0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16,185,129,0.2);
}
.chat-download-link i {
  font-size: 16px;
}

/* Code Block — with header + copy button */
.code-block {
  margin: 10px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
  background: rgba(0,0,0,0.25);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid var(--border-light);
}
.code-lang {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-mono);
}
.code-copy-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  font-family: var(--font-sans);
}
.code-copy-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
}
.code-block pre {
  margin: 0;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-radius: 0;
  overflow-x: auto;
}
.code-block pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.6;
}

/* Chat links in message */
.message-bubble a:not(.chat-download-link):not(.chat-image) {
  color: var(--accent-color, #3b82f6);
  text-decoration: none;
  border-bottom: 1px dashed rgba(59,130,246,0.4);
  transition: border-color 0.2s;
}
.message-bubble a:not(.chat-download-link):not(.chat-image):hover {
  border-bottom: 1px solid var(--accent-color, #3b82f6);
}

/* ============================================================
   CONFIRM MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.modal-overlay.active {
  opacity: 1;
}
.modal-box {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 36px 40px 28px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-overlay.active .modal-box {
  transform: scale(1);
}
.modal-icon {
  font-size: 48px;
  color: var(--error);
  margin-bottom: 16px;
}
.modal-icon i {
  background: rgba(239,68,68,0.1);
  padding: 16px;
  border-radius: 50%;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text-color);
}
.modal-message {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 0 4px;
  line-height: 1.5;
}
.modal-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 4px;
}
.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 20px;
  opacity: 0.7;
}
.modal-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  min-width: 20px;
  text-align: center;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.modal-btn {
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.1s;
}
.modal-btn:active {
  transform: scale(0.97);
}
.modal-btn-cancel {
  background: var(--bg-tertiary);
  color: var(--text-color);
}
.modal-btn-cancel:hover {
  background: var(--bg-hover);
}
.modal-btn-confirm {
  background: var(--error);
  color: #fff;
}
.modal-btn-confirm:hover {
  background: #dc2626;
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  width: 360px;
  background: #0c1022;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  overflow: hidden;
  position: relative;
}

.toast-item.removing {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100px) scale(0.92); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(100px) scale(0.92); }
}

.toast-item .toast-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast-item .toast-body {
  flex: 1;
  min-width: 0;
}

.toast-item .toast-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.toast-item .toast-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.toast-item .toast-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.4;
  font-size: 14px;
  transition: opacity var(--transition-fast);
}

.toast-item .toast-close:hover { opacity: 0.8; }

/* ============================================================
   Summary Bar — แถบสรุปด้านบน (Top-level rules)
   ============================================================ */
.dash-summary-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 10px 16px;
  margin: 0 0 12px 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  flex-wrap: wrap;
}
.dash-summary-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  white-space: nowrap;
}
.dash-summary-item i {
  font-size: 14px;
  color: var(--accent-color);
}
.dash-summary-item:nth-child(3) i { color: #fbbf24; }
.dash-summary-item:nth-child(5) i { color: #f43f5e; }
.dash-summary-item:nth-child(7) i { color: #34d399; }
.dash-summary-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
}
.dash-summary-value {
  font-size: 16px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
}
.dash-summary-item:nth-child(1) .dash-summary-value { color: var(--accent-color); }
.dash-summary-item:nth-child(3) .dash-summary-value { color: #fbbf24; }
.dash-summary-item:nth-child(5) .dash-summary-value { color: #f43f5e; }
.dash-summary-item:nth-child(7) .dash-summary-value { color: #34d399; }
.dash-summary-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
}
.dash-summary-clock {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.35);
}

/* Dashboard sections */
.dashboard-section {
  margin-top: 12px;
  padding: 12px;
}
.dashboard-stats {
  grid-template-columns: repeat(2, 1fr);
}
.dash-total-badge {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-color);
  background: rgba(59, 130, 246, 0.12);
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.dash-total-badge::before {
  content: "👥 ";
}

/* ============================================================
   RESPONSIVE — Tablette (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .header {
    padding: 0 16px;
  }

  .messages-container {
    padding: 0px 4%;
  }
  .messages-container:not(.has-messages) {
    padding: 8px 4% 0px;
  }

  .message-bubble {
    max-width: 90%;
    font-size: 13px;
  }

  .input-area {
    padding: 8px 4% 10px;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-top: 8px;
  }

  .welcome-message {
    padding: 16px 16px 8px;
  }
  .welcome-icon {
    width: 56px;
    height: 56px;
    font-size: 24px;
    margin-bottom: 12px;
    border-radius: 18px;
  }

  /* Summary bar — compact on tablet */
  .dash-summary-bar {
    gap: 0;
    padding: 8px 10px;
    border-radius: 10px;
  }
  .dash-summary-item { padding: 2px 6px; }
  .dash-summary-item i { font-size: 12px; }
  .dash-summary-label { font-size: 11px; }
  .dash-summary-value { font-size: 14px; }
  .dash-summary-divider { height: 16px; }
  .dash-summary-clock { display: none; }

  .dashboard-chart-wrapper {
    height: 220px;
  }

  .suggestion-btn {
    font-size: 12px;
    padding: 12px 14px;
  }

  /* Hide header center (clock + titles) on tablet/mobile — keep only user + logout */
  .header-center {
    display: none !important;
  }

  .header-left .conv-name {
    max-width: 160px;
    font-size: 14px;
  }

  /* Compact user info */
  .header-user-info {
    gap: 6px;
  }
  .header-user-details .header-user-name {
    font-size: 12px;
  }
  .header-user-details .header-user-code {
    font-size: 10px;
  }
}


@media (max-width: 480px) {
  .messages-container {
    padding: 0px 3%;
  }

  .message-bubble {
    max-width: 95%;
    font-size: 13px;
    padding: 10px 14px;
  }
  
  .patient-card-result {
    flex-direction: column;
    align-items: stretch;
  }
  
  .patient-card-result .patient-photo {
    width: 60px;
    height: 60px;
  }

  .provider-badge {
    display: none;
  }

  .welcome-message h2 {
    font-size: 20px;
  }

  .welcome-message > p {
    font-size: 13px;
  }

  .patient-search {
    max-width: 100%;
  }

  .dashboard-section {
    padding: 10px;
    margin-top: 8px;
  }

  .dashboard-chart-wrapper {
    min-height: 200px;
  }

  .dashboard-chart-wrapper > div {
    min-height: 180px;
  }

  .stat-value {
    font-size: 20px;
  }

  .input-area {
    padding: 10px 3% 14px;
  }
}

/* ============================================================
   MARKDOWN EXTRA
   ============================================================ */
.message-bubble blockquote {
  border-left: 3px solid var(--accent-blue);
  padding: 6px 14px;
  margin: 8px 0;
  background: rgba(59,130,246,0.04);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.message-bubble h1, .message-bubble h2, .message-bubble h3, .message-bubble h4 {
  margin: 12px 0 6px;
  color: var(--text-primary);
  font-weight: 600;
}

.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }

.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 14px 0;
}

.message-bubble .table-wrap,
.message-content .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px 0;
  border-radius: var(--radius-md);
}

.message-bubble table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  table-layout: fixed;
  word-break: break-word;
}

.message-bubble table td {
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.08);
  text-align: left;
  line-height: 1.5;
  color: var(--text-primary);
  font-size: 12.5px;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 280px;
}

.message-bubble table thead th {
  background: linear-gradient(135deg, rgba(59,130,246,0.18), rgba(6,182,212,0.10));
  font-weight: 700;
  font-size: 12px;
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  text-align: left;
  white-space: nowrap;
  max-width: 200px;
}

.message-bubble table tbody tr:last-child td {
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.message-bubble table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}

.message-bubble table tbody tr:hover {
  background: rgba(59,130,246,0.04);
}

.message-bubble table td:first-child {
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  padding-right: 16px;
}

.message-bubble table td:last-child {
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   SCROLL TO BOTTOM BUTTON
   ============================================================ */
.scroll-bottom-btn {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
  z-index: 10;
}

.scroll-bottom-btn.visible {
  display: flex;
}

.scroll-bottom-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
  color: var(--text-primary);
}

/* ============================================================
   MARKDOWN RENDERED
   ============================================================ */
.chat-area {
  position: relative;
}

/* Copy Message Button */
.copy-msg-btn {
  position: absolute;
  bottom: 6px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 2;
}

.message-bubble:hover .copy-msg-btn {
  opacity: 0.6;
}

.copy-msg-btn:hover {
  opacity: 1 !important;
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

.copy-msg-btn.copied {
  opacity: 1 !important;
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.tool-result-box {
  margin: 6px 0;
  padding: 12px 14px;
  background: rgba(59, 130, 246, 0.04);
  border: 1px solid rgba(59, 130, 246, 0.12);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

.tool-result-box .tool-result-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-blue);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   ERROR MESSAGE
   ============================================================ */
.message.error .message-bubble {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
}

.sidebar-overlay.active {
  display: block;
}

@media (min-width: 769px) {
  .sidebar-overlay.active {
    display: none;
  }
}

/* ============================================================
   TABLES IN CHAT (สวยงาม)
   ============================================================ */
.table-scroll {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: var(--radius-md);
  border: 1px solid rgba(59, 130, 246, 0.1);
  background: rgba(15, 23, 42, 0.25);
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: 'TH Sarabun', 'Sarabun', sans-serif;
  min-width: 400px;
}

.chat-table thead {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(59, 130, 246, 0.04));
  border-bottom: 2px solid rgba(59, 130, 246, 0.2);
}

.chat-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 700;
  color: #60a5fa;
  white-space: nowrap;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
  user-select: none;
}

.chat-table td {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  vertical-align: middle;
  line-height: 1.4;
}

.chat-table tbody tr {
  transition: background 0.12s ease;
}

.chat-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.06);
}

.chat-table tbody tr:last-child td {
  border-bottom: none;
}

/* Striped rows */
.chat-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.018);
}

.chat-table tbody tr:nth-child(even):hover {
  background: rgba(59, 130, 246, 0.07);
}

/* ตัวเลขเรียงแถว auto-numbering (optional) */
.chat-table tbody tr td:first-child {
  font-weight: 500;
  color: #94a3b8;
}

/* ============================================================
   PATIENT SEARCH
   ============================================================ */
.patient-search {
  margin: 20px 0 16px;
  width: 100%;
  max-width: 540px;
}

.patient-search-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 4px 4px 4px 16px;
  transition: all var(--transition-base);
}

.patient-search-wrapper:focus-within {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.patient-search-wrapper .search-icon {
  color: var(--text-muted);
  font-size: 14px;
}

.patient-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 0;
}

.patient-search-input::placeholder {
  color: var(--text-muted);
  font-size: 13px;
}

.patient-search-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.patient-search-btn.active {
  background: var(--accent-color);
  color: #fff;
}

.patient-search-btn.active:hover {
  background: var(--accent-hover);
}

/* Search Results */
.patient-search-results {
  display: none;
  margin-top: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
}

.patient-search-results.active {
  display: block;
}

.search-loading,
.search-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-light);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: rgba(59, 130, 246, 0.08);
}

.search-result-item.highlight {
  background: rgba(59, 130, 246, 0.22) !important;
  border-left: 4px solid #3b82f6 !important;
  padding-left: 12px !important;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.3);
}

.search-result-item.highlight .result-name {
  color: #60a5fa;
}

.search-result-item.highlight .result-detail {
  color: rgba(255,255,255,0.7);
}

.result-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.result-avatar-text {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}
.result-sex {
  font-size: 13px;
  margin-left: 2px;
}

.result-detail {
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 3px;
}


.result-select-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.result-select-btn:hover {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
}

/* ============================================================
   DASHBOARD SECTION (Welcome Screen)
   ============================================================ */
.dashboard-section {
  margin-top: 28px;
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.dashboard-header h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dashboard-header h4 i {
  color: var(--accent-blue);
}

.dashboard-clock {
  font-size: 13px;
  color: var(--text-accent);
  font-weight: 500;
  background: rgba(59, 130, 246, 0.08);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.dash-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-total-badge {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-color);
  background: rgba(59, 130, 246, 0.12);
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.dash-total-badge::before {
  content: "👥 ";
}

.dash-auto-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(16, 185, 129, 0.08);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.dash-auto-badge.refreshing {
  color: #34d399;
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.2);
  animation: badgePulse 0.6s ease-in-out 2;
}

.dash-auto-badge i {
  font-size: 10px;
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}

.dashboard-chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 300px;
  height: auto;
  aspect-ratio: 16 / 10;
  margin-bottom: 16px;
  padding: 8px 0;
}

.dashboard-chart-wrapper > div {
  width: 100% !important;
  height: 100% !important;
  min-height: 280px;
  max-height: 500px;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
  background: rgba(13, 18, 37, 0.6);
  border-radius: var(--radius-md);
  z-index: 5;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px 8px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  opacity: 0.6;
}

.stat-card[data-stat="total"]::before { background: var(--accent-color); }
.stat-card[data-stat="waiting"]::before { background: var(--accent-amber); }
.stat-card[data-stat="exam"]::before { background: var(--accent-cyan); }
.stat-card[data-stat="complete"]::before { background: var(--accent-green); }

.stat-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  transition: all 0.3s ease;
}

.stat-card[data-stat="total"] .stat-value { color: var(--accent-color); }
.stat-card[data-stat="waiting"] .stat-value { color: var(--accent-amber); }
.stat-card[data-stat="exam"] .stat-value { color: var(--accent-cyan); }
.stat-card[data-stat="complete"] .stat-value { color: var(--accent-green); }

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

@media (max-width: 480px) {
  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 8px;
  }
  .dashboard-chart-wrapper {
    height: 160px;
  }
  .ipd-charts-section {
    margin-top: 8px;
  }
  .ipd-chart-container {
    min-height: 160px;
    height: 160px;
  }
  .ipd-occupancy-section {
    margin-top: 8px;
  }
}

/* ============================================================
   IPD CHARTS — 2 Donuts Side by Side
   ============================================================ */
.ipd-charts-section {
  margin-top: 16px;
}

.ipd-total-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-accent);
  background: rgba(59, 130, 246, 0.1);
  padding: 4px 14px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.ipd-charts-row {
  display: flex;
  gap: 14px;
  width: 100%;
}

.ipd-chart-frame {
  flex: 1;
  min-width: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition-base);
}

.ipd-chart-frame:hover {
  border-color: var(--border-accent);
}

.ipd-chart-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  background: rgba(255,255,255,0.02);
}

.ipd-chart-header i {
  font-size: 13px;
  color: var(--text-accent);
  opacity: 0.7;
}

.ipd-chart-container {
  position: relative;
  width: 100%;
  min-height: 240px;
  height: 240px;
  padding: 4px;
  box-sizing: border-box;
}

.ipd-chart-container > div {
  width: 100% !important;
  height: 100% !important;
}

/* Mobile: stack vertically */
@media (max-width: 640px) {
  .ipd-charts-row {
    flex-direction: column;
  }
  .ipd-chart-container {
    min-height: 200px;
    height: 200px;
  }
}

/* ============================================================
   IPD OCCUPANCY RATE TABLE
   ============================================================ */
.ipd-occupancy-section {
  margin-top: 16px;
}

.occ-table-wrapper {
  position: relative;
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
}

.table-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}

.occ-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.occ-table thead {
  background: rgba(255,255,255,0.03);
}

.occ-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.occ-table th:first-child {
  text-align: center;
  width: 50px;
}
.occ-table th:nth-child(2) {
  text-align: left;
}
.occ-table th:nth-child(4) {
  text-align: center;
}
.occ-table th:last-child {
  text-align: right;
}

.occ-table td {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

.occ-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.04);
}

.occ-table tbody tr:last-child td {
  border-bottom: none;
}

.occ-rank {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-align: center;
  width: 50px;
  font-family: 'Sarabun', sans-serif;
}

.occ-ward-name {
  color: var(--text-primary);
  font-weight: 500;
  min-width: 180px;
  text-align: left;
}

.occ-bed-count {
  color: #818cf8;
  font-family: 'Sarabun', sans-serif;
  text-align: center;
  width: 80px;
  font-weight: 600;
}

.occ-patient-count {
  color: #34d399;
  font-family: 'Sarabun', sans-serif;
  text-align: center;
  width: 80px;
  font-weight: 600;
}

.occ-avail-count {
  color: #fbbf24;
  font-family: 'Sarabun', sans-serif;
  text-align: center;
  width: 70px;
  font-weight: 600;
}

.occ-rate-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  min-width: 160px;
}

.occ-bar-bg {
  flex: 1;
  max-width: 120px;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.occ-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.occ-rate-label {
  font-weight: 700;
  font-size: 13px;
  min-width: 48px;
  text-align: right;
  font-family: 'Sarabun', sans-serif;
}

/* Mobile responsive */
@media (max-width: 640px) {
  .occ-table {
    font-size: 12px;
  }
  .occ-table th,
  .occ-table td {
    padding: 8px 10px;
  }
  .occ-ward-name {
    min-width: 120px;
  }
  .occ-bar-bg {
    max-width: 80px;
  }
}

/* === Web Search / News Result Styles === */
.news-result-header {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-accent);
  margin: 12px 0;
  padding: 8px 12px;
  background: rgba(59, 130, 246, 0.08);
  border-radius: 8px;
  border-left: 3px solid var(--accent-color);
}
.news-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-surface);
  border-radius: 8px;
  border: 1px solid var(--border-light);
  transition: background 0.2s;
}
.news-item:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
}
.news-item-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 1em;
  margin-bottom: 4px;
  word-break: break-word;
}
.news-item-title a {
  color: var(--text-accent);
  text-decoration: none;
}
.news-item-title a:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}
.news-item-snippet {
  color: var(--text-secondary);
  font-size: 0.9em;
  line-height: 1.5;
  margin-bottom: 4px;
  word-break: break-word;
}
.news-item-url {
  color: var(--text-muted);
  font-size: 0.8em;
  word-break: break-all;
}
.news-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--accent-color);
  color: #fff;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 700;
  margin-right: 6px;
}
.news-count {
  color: var(--text-muted);
  font-size: 0.85em;
  text-align: right;
  padding: 4px 8px;
}

/* ===== Artifact System ===== */
.artifact-container {
  border: 1px solid #2d3748;
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0;
  background: #1a202c;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.artifact-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(135deg, #2d3748, #1a202c);
  border-bottom: 1px solid #2d3748;
}
.artifact-badge {
  font-size: 12px;
  font-weight: 600;
  color: #a0aec0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.artifact-badge i { color: #667eea; }
.artifact-btn {
  background: transparent;
  border: 1px solid #4a5568;
  color: #a0aec0;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.artifact-btn:hover { background: #4a5568; color: #e2e8f0; }
.artifact-iframe {
  width: 100%;
  min-height: 200px;
  border: none;
  display: block;
  background: #fff;
}
.artifact-chart-wrap {
  padding: 16px;
  display: flex;
  justify-content: center;
  background: #1a202c;
  min-height: 200px;
}
.artifact-chart-wrap canvas { max-width: 100%; max-height: 400px; }
.artifact-mermaid-wrap {
  padding: 16px;
  background: #1a202c;
  overflow-x: auto;
  font-size: 13px;
  white-space: pre;
  color: #e2e8f0;
}
.artifact-svg-wrap {
  padding: 16px;
  display: flex;
  justify-content: center;
  background: #1a202c;
}
.artifact-svg-wrap svg { max-width: 100%; height: auto; }
.artifact-modal-overlay {
  position: fixed;
  top:0; left:0; right:0; bottom:0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.artifact-modal {
  background: #1a202c;
  border: 1px solid #2d3748;
  border-radius: 16px;
  width: 95vw;
  height: 90vh;
  max-width: 1400px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.artifact-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg,#2d3748,#1a202c);
  border-bottom: 1px solid #2d3748;
}
.artifact-modal-title { font-weight: 600; color: #e2e8f0; display: flex; align-items: center; gap: 8px; }
.artifact-modal-close {
  background: transparent; border: none; color: #a0aec0; font-size: 20px; cursor: pointer;
}
.artifact-modal-body { padding: 20px; overflow-y: auto; flex: 1; min-height: 0; position: relative; }
.artifact-modal-body iframe { width: 100%; height: 60vh; border: none; border-radius: 8px; background: #fff; }
