/* ============================================
   WizBI Premium Chat UI v3
   Tab-Based Layout + Glassmorphism + RTL + Mobile-First
   ============================================ */

/* === Design Tokens (aligned with wizbi.ai) === */
:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #0e0e0e;
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);

  --surface-1: #121212;
  --surface-2: #1a1a1a;
  --surface-3: #1e1e1e;
  --surface-border: #2a2a2a;
  --surface-border-hover: #404040;

  --accent-1: #3b82f6;
  --accent-2: #60a5fa;
  --accent-3: #93c5fd;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #60a5fa 50%, #6366f1 100%);
  --accent-gradient-subtle: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(99, 102, 241, 0.04));

  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  --text-1: #ffffff;
  --text-2: #a1a1aa;
  --text-3: #71717a;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', monospace;
  --font-hebrew: 'Heebo', 'Inter', 'Assistant', sans-serif;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px var(--accent-glow);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 150ms;
  --t-norm: 300ms;
  --t-slow: 400ms;

  --header-height: 52px;
  --tab-bar-height: 52px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* === Light Theme Override === */
[data-theme="light"] {
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-glass: rgba(0, 0, 0, 0.02);
  --bg-glass-hover: rgba(0, 0, 0, 0.05);

  --surface-1: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e4e4e7;
  --surface-border: #e4e4e7;
  --surface-border-hover: #d4d4d8;

  --accent-glow: rgba(59, 130, 246, 0.12);
  --success-bg: rgba(34, 197, 94, 0.06);

  --text-1: #09090b;
  --text-2: #52525b;
  --text-3: #a1a1aa;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 20px var(--accent-glow);
}

[data-theme="light"] body::before {
  background:
    radial-gradient(ellipse 600px 400px at 15% 10%, rgba(59, 130, 246, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 500px 500px at 85% 85%, rgba(99, 102, 241, 0.03) 0%, transparent 60%);
}

/* === LTR Override (English mode) === */
html[dir="ltr"] .chat-form {
  flex-direction: row;
}

html[dir="ltr"] .input-actions {
  flex-direction: row;
}

html[dir="ltr"] .dropdown-item {
  text-align: left;
}

html[dir="ltr"] .message.user {
  flex-direction: row;
}

html[dir="ltr"] .user-dropdown {
  left: auto;
  right: 0;
}

html[dir="ltr"] .setting-row {
  direction: ltr;
}

html[dir="ltr"] .header-right {
  align-items: flex-start;
}

html[dir="ltr"] .brand-sub {
  text-align: left;
}

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

html,
body {
  height: 100%;
  font-family: var(--font-hebrew);
  background: var(--bg-primary);
  color: var(--text-1);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}




/* === RTL Support === */
html[dir="rtl"] .message.user {
  flex-direction: row-reverse;
}

html[dir="rtl"] .chat-form {
  flex-direction: row-reverse;
}

html[dir="rtl"] .input-actions {
  flex-direction: row-reverse;
}

/* ============================================
   App Shell — Full-Viewport Container
   ============================================ */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
  z-index: 1;
  border-left: 1px solid var(--surface-border);
  border-right: 1px solid var(--surface-border);
  animation: containerReveal 0.6s var(--ease-out);
}

@keyframes containerReveal {
  from {
    opacity: 0;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================
   Header
   ============================================ */

.app-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: var(--accent-gradient);
  opacity: 0.4;
}

.header-right {
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-1);
  line-height: 1;
}

.brand-prefix {
  color: var(--text-3);
  font-weight: 400;
}

.brand-suffix {
  color: var(--accent-2);
  font-weight: 500;
}

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

/* Header Icon Buttons */
.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
  background: var(--bg-glass);
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--t-norm) var(--ease-out);
}

.header-icon-btn svg {
  width: 22px;
  height: 22px;
}

.header-icon-btn:hover {
  background: var(--bg-glass-hover);
  border-color: var(--accent-1);
  color: var(--text-1);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.telegram-btn {
  color: #229ED9;
  border: none;
  background: none;
}

.telegram-btn svg {
  width: 28px;
  height: 28px;
}

.telegram-btn:hover {
  background: none;
  color: #4dc3ff;
  transform: translateY(-1px);
  box-shadow: none;
}

/* Google Connect Button */
.connection-status {
  display: flex;
  align-items: center;
}

.connect-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-full);
  background: var(--bg-glass);
  backdrop-filter: blur(10px);
  color: var(--text-2);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all var(--t-norm) var(--ease-out);
  white-space: nowrap;
}

.connect-btn:hover {
  background: var(--bg-glass-hover);
  border-color: var(--accent-1);
  color: var(--text-1);
  transform: translateY(-1px);
}

.connect-btn.connected {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.connect-btn.loading {
  opacity: 0.6;
  cursor: wait;
}

.status-icon {
  font-size: 0.85rem;
}

/* User Avatar Button */
.user-menu-wrapper {
  position: relative;
}

.user-avatar-btn {
  background: none;
  border: 2px solid var(--surface-border);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: all var(--t-norm) var(--ease-out);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.user-avatar-btn:hover {
  border-color: var(--accent-1);
  transform: scale(1.05);
  box-shadow: 0 0 16px var(--accent-glow);
}

.avatar-circle {
  width: 100%;
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: white;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ============================================
   User Menu (Bottom Sheet / Drawer)
   ============================================ */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out);
  backdrop-filter: blur(4px);
  display: flex;
  /* alignment for desktop modal feel */
  align-items: flex-end;
  /* Mobile default: bottom */
  justify-content: center;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-content {
  background: var(--surface-1);
  width: 100%;
  max-width: 600px;
  /* Limit width on desktop */
  border-radius: 24px 24px 0 0;
  padding: 16px 16px var(--safe-area-bottom);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
  border-top: 1px solid var(--surface-border);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

@media (min-width: 768px) {
  .drawer-backdrop {
    align-items: center;
    /* Center on desktop */
  }

  .drawer-content {
    border-radius: 24px;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    width: 400px;
    /* Fixed width dropdown feel */
  }

  .drawer-backdrop.open .drawer-content {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.drawer-backdrop.open .drawer-content {
  transform: translateY(0);
}

.drawer-handle {
  width: 36px;
  height: 5px;
  background: var(--surface-border-hover);
  border-radius: 3px;
  margin: 0 auto 20px;
}

/* Drawer Profile Header */
.user-profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  text-align: center;
}

.profile-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 12px;
  border: 3px solid var(--bg-secondary);
  box-shadow: var(--shadow-md);
  color: white;
}

.profile-avatar-large img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.profile-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-1);
}

.profile-email {
  font-size: 0.85rem;
  color: var(--text-3);
  margin-top: 2px;
}

/* Drawer Menu Items */
.drawer-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-glass);
  border-radius: 16px;
  margin-bottom: 8px;
  color: var(--text-1);
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--t-fast);
  border: 1px solid transparent;
}

.drawer-menu-item:hover {
  background: var(--bg-glass-hover);
  border-color: var(--surface-border);
}

.drawer-menu-item:active {
  transform: scale(0.98);
}

.drawer-menu-item.danger {
  color: var(--error);
  background: rgba(239, 68, 68, 0.08);
}

.drawer-menu-item.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

.drawer-menu-item svg {
  color: var(--accent-2);
}

.drawer-menu-item.danger svg {
  color: var(--error);
}

/* Settings Toggle Pill */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 12px;
}

.setting-label {
  font-size: 0.82rem;
  color: var(--text-2);
  font-weight: 500;
}

.setting-toggle {
  display: flex;
  background: var(--bg-glass);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 2px;
}

.toggle-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 28px;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--t-fast) var(--ease-out);
  line-height: 1;
}

.toggle-option:hover {
  color: var(--text-1);
  background: var(--bg-glass-hover);
}

.toggle-option.active {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.toggle-option svg {
  width: 14px;
  height: 14px;
}

/* ============================================
   Tab Content Area
   ============================================ */

.tab-content-area {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-20px);
  transition: all var(--t-slow) var(--ease-out);
}

.tab-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  position: relative;
  height: 100%;
}

/* ============================================
   Bottom Tab Bar
   ============================================ */

.tab-bar {
  display: flex;
  height: var(--tab-bar-height);
  background: var(--surface-1);
  border-top: 1px solid var(--surface-border);
  flex-shrink: 0;
  position: relative;
  z-index: 20;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-family: var(--font-hebrew);
  font-size: 0.72rem;
  font-weight: 600;
  transition: all var(--t-norm) var(--ease-out);
  position: relative;
  padding: 8px 0;
}

.tab-item svg {
  transition: all var(--t-norm) var(--ease-out);
}

.tab-item:hover {
  color: var(--text-2);
}

.tab-item:hover svg {
  transform: translateY(-1px);
}

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

.tab-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--accent-gradient);
  border-radius: 0 0 4px 4px;
}

/* ============================================
   Chat Messages Area
   ============================================ */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
  position: relative;
  z-index: 1;
  overscroll-behavior: contain;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--r-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ============================================
   Message Bubbles
   ============================================ */

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 88%;
  animation: msgIn 0.25s var(--ease-out);
}

/* User messages — no avatar, just a clean bubble */
.message.user .message-avatar {
  display: none;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Content */
.message-content {
  background: var(--surface-1);
  padding: 0.85rem 1.1rem;
  border-radius: var(--r-lg);
  border: 1px solid var(--surface-border);
  position: relative;
  min-width: 60px;
  transition: border-color var(--t-norm);
}

.message-content:hover {
  border-color: var(--surface-border-hover);
}

.message-content p {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-content p+p {
  margin-top: 0.5rem;
}

/* Timestamp */
.message-time {
  font-size: 0.7rem;
  color: var(--text-3);
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--t-fast);
}

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

/* User Messages */
.message.user {
  align-self: flex-end;
}

/* user avatar is hidden via display:none above */

.message.user .message-content {
  background: var(--accent-1);
  border: none;
  color: white;
}

/* AI Messages */
.message.model .message-avatar {
  background: var(--surface-2);
  border-color: var(--accent-1);
  box-shadow: 0 0 16px var(--accent-glow);
}

/* ============================================
   Media in Messages
   ============================================ */

.message-content img {
  max-width: 100%;
  border-radius: var(--r-md);
  margin: 8px 0;
  cursor: pointer;
  transition: transform var(--t-norm) var(--ease-out);
}

.message-content img:hover {
  transform: scale(1.02);
}

.message-content audio {
  width: 100%;
  margin: 8px 0;
  border-radius: var(--r-sm);
  filter: invert(1) hue-rotate(180deg);
}

/* ============================================
   Input Area
   ============================================ */

/* ============================================
   Chat Input — WhatsApp Style
   ============================================ */

.chat-input-area {
  padding: 8px 12px calc(8px + var(--safe-area-bottom));
  background: var(--surface-1);
  border-top: 1px solid var(--surface-border);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

/* Attachment Preview */
.attachment-preview {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  border: 1px solid var(--surface-border);
  animation: msgIn 0.25s var(--ease-out);
}

.attachment-preview.active {
  display: flex;
}

.attachment-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--r-sm);
}

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

.attachment-preview .attachment-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-preview .attachment-size {
  font-size: 0.7rem;
  color: var(--text-3);
}

.attachment-preview .remove-attachment {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.15);
  border: none;
  border-radius: var(--r-sm);
  color: var(--error);
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--t-fast);
}

.attachment-preview .remove-attachment:hover {
  background: rgba(239, 68, 68, 0.3);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

/* Input Actions (Left) */
.input-actions {
  display: flex;
  align-items: center;
  padding-bottom: 8px;
}

.action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--accent-2);
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  overflow: hidden;
}

.action-btn:hover {
  background: var(--bg-glass-hover);
}

.action-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Textarea Wrapper (Center) */
.input-wrapper {
  flex: 1;
  background: var(--bg-glass);
  /* Darker/Lighter background */
  border-radius: 20px;
  /* Pill shape */
  padding: 6px 4px;
  border: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
}

textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-1);
  font-family: var(--font-hebrew);
  font-size: 1rem;
  padding: 8px 12px;
  resize: none;
  max-height: 120px;
  min-height: 36px;
  line-height: 1.4;
  outline: none;
}

textarea:focus {
  box-shadow: none;
  border: none;
  background: transparent;
}

/* Send/Mic FAB (Right) */
.send-mic-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  /* Start as gray (mic style) */
  color: var(--accent-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--t-norm) var(--ease-spring);
  box-shadow: var(--shadow-sm);
  margin-bottom: 2px;
}

.send-mic-btn svg {
  width: 24px;
  height: 24px;
}

/* Active State (Send) */
.send-mic-btn.active-send {
  background: var(--accent-gradient);
  color: white;
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

/* Active State (Recording) */
.send-mic-btn.recording {
  background: var(--error);
  color: white;
  transform: scale(1.15);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
  animation: pulseRecording 1.5s infinite;
}

@keyframes pulseRecording {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

.send-mic-btn:active {
  transform: scale(0.95);
}

/* ============================================
   Tool Indicator — Premium
   ============================================ */

.tool-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--accent-gradient-subtle);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(59, 130, 246, 0.15);
  color: var(--accent-3);
  border-radius: var(--r-full);
  font-size: 0.82rem;
  font-weight: 500;
  align-self: center;
  animation: toolFloat 2.5s ease-in-out infinite;
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.08);
  margin: 4px 0;
}

@keyframes toolFloat {

  0%,
  100% {
    transform: translateY(0);
    opacity: 1;
  }

  50% {
    transform: translateY(-3px);
    opacity: 0.85;
  }
}

.tool-indicator.hidden {
  display: none;
}

.tool-icon {
  display: inline-block;
  animation: toolSpin 1.5s linear infinite;
}

@keyframes toolSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--accent-2);
  border-radius: 50%;
  animation: typeDot 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

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

@keyframes typeDot {

  0%,
  80%,
  100% {
    transform: scale(0.5);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.hidden {
  display: none !important;
}

/* Tool Execution Chips */
.tool-indicator {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
  align-items: flex-start;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  padding: 6px 12px;
  border-radius: var(--r-full);
  font-size: 0.85rem;
  color: var(--text-2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-family: var(--font-hebrew);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tool-chip.thinking-chip {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.3);
  color: var(--accent-2);
}

.tool-chip.done {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #10b981;
}

.chip-icon {
  font-size: 1rem;
}

.spinner-icon {
  display: inline-block;
  animation: slowSpin 1.5s linear infinite;
  transform-origin: center;
}

@keyframes slowSpin {
  100% {
    transform: rotate(360deg);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ============================================
   Markdown Rendering (inside messages)
   ============================================ */

.message-content ul,
.message-content ol {
  margin: 0.4rem 0;
  padding-right: 1.4rem;
}

.message-content li {
  margin: 0.2rem 0;
}

.message-content code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-3);
}

.message-content pre {
  background: rgba(0, 0, 0, 0.45);
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  overflow-x: auto;
  margin: 0.5rem 0;
  border: 1px solid var(--surface-border);
}

.message-content pre code {
  background: none;
  padding: 0;
  color: var(--text-1);
}

.message-content strong {
  font-weight: 600;
}

.message-content em {
  color: var(--text-2);
}

.message-content a {
  color: var(--accent-2);
  text-decoration: none;
  border-bottom: 1px solid rgba(167, 139, 250, 0.3);
  transition: border-color var(--t-fast);
}

.message-content a:hover {
  border-color: var(--accent-2);
}

.message-content blockquote {
  border-right: 3px solid var(--accent-1);
  padding-right: 12px;
  margin: 0.5rem 0;
  color: var(--text-2);
  font-style: italic;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.9em;
}

.message-content th,
.message-content td {
  border: 1px solid var(--surface-border);
  padding: 6px 10px;
  text-align: right;
}

.message-content th {
  background: var(--surface-2);
  font-weight: 600;
}

/* ============================================
   Welcome Screen
   ============================================ */

.welcome-message {
  text-align: center;
  padding: 60px 20px 40px;
  animation: welcomeIn 0.7s var(--ease-out);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

@keyframes welcomeIn {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.welcome-message h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text-1);
}

.welcome-message>p {
  color: var(--text-2);
  font-size: 1rem;
  margin-bottom: 32px;
  max-width: 400px;
}

.capabilities-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 480px;
  width: 100%;
}

.capability-card {
  background: var(--surface-1);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-lg);
  padding: 18px 12px 14px;
  cursor: pointer;
  transition: all var(--t-norm) var(--ease-out);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.capability-card:hover {
  border-color: var(--accent-1);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.capability-card:active {
  transform: translateY(-1px);
}

.capability-icon {
  font-size: 1.6rem;
  position: relative;
  z-index: 1;
}

.capability-card span:last-child {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  position: relative;
  z-index: 1;
}

/* ============================================
   Connectors Page (Tab 2)
   ============================================ */

.connectors-page {
  height: 100%;
  overflow-y: auto;
  padding: 24px 20px 20px;
}

.connectors-page::-webkit-scrollbar {
  width: 5px;
}

.connectors-page::-webkit-scrollbar-track {
  background: transparent;
}

.connectors-page::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--r-full);
}

.connectors-header {
  text-align: center;
  margin-bottom: 28px;
}

.connectors-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.connectors-header p {
  color: var(--text-3);
  font-size: 0.88rem;
}

/* Search Bar */
.connectors-search {
  margin-bottom: 16px;
}

.connectors-search input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
  color: var(--text-1);
  font-family: var(--font-hebrew);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--t-fast);
}

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

.connectors-search input::placeholder {
  color: var(--text-3);
}

/* Category Group */
.category-group {
  margin-bottom: 24px;
}

.category-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--surface-border);
}

/* Connector Cards Grid */
.connectors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.connectors-section-header {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.02em;
  padding: 12px 0 6px;
  margin-top: 8px;
  border-bottom: 1px solid var(--surface-border);
}

.connectors-section-header:first-child {
  margin-top: 0;
  padding-top: 0;
}

.connector-card {
  background: var(--surface-1);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-lg);
  padding: 16px;
  transition: all var(--t-norm) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.connector-card:hover {
  border-color: var(--surface-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.connector-card.enabled {
  border-color: rgba(59, 130, 246, 0.25);
  background: rgba(59, 130, 246, 0.05);
}

.connector-card.enabled::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-gradient);
}

.connector-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connector-chat-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--t-fast);
}

.connector-chat-btn:hover {
  color: var(--accent-2);
  border-color: var(--accent-2);
  background: rgba(59, 130, 246, 0.06);
}

.connector-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.connector-card-icon {
  font-size: 1.5rem;
}

.connector-card-icon--svg {
  font-size: initial;
  display: flex;
  align-items: center;
  justify-content: center;
}

.connector-card-icon--svg svg,
.connector-card-icon--svg img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  object-fit: contain;
}

.connector-card-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.connector-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-1);
}

.connector-card-desc {
  font-size: 0.8rem;
  color: var(--text-3);
  line-height: 1.4;
}

/* Auth Badge */
.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  margin-top: 8px;
  cursor: default;
  position: relative;
  z-index: 1;
}

.auth-badge.needs-auth {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
  cursor: pointer;
  transition: all var(--t-fast);
}

.auth-badge.needs-auth:hover {
  background: rgba(245, 158, 11, 0.25);
}

.auth-badge.connected {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.auth-badge-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
  position: relative;
  z-index: 1;
}

.auth-badge-actions .auth-badge {
  margin-top: 0;
}

.auth-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r-sm);
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.78rem;
  transition: all var(--t-fast);
}

.auth-action-btn:hover {
  color: var(--text-1);
  border-color: var(--accent-2);
  background: rgba(59, 130, 246, 0.06);
}

.auth-action-btn.danger:hover {
  color: var(--error);
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.08);
}

/* API Key Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease;
}

.modal-overlay .modal-content {
  text-align: start;
  max-width: 420px;
}

.modal-overlay .modal-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 4px;
}

.api-key-field {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-1);
  font-size: 0.9rem;
  font-family: var(--font-mono);
  box-sizing: border-box;
  outline: none;
  transition: border-color var(--t-fast);
}

.api-key-field:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.api-key-field::placeholder {
  color: var(--text-3);
  font-family: var(--font-hebrew);
}

.api-key-form-group {
  margin-bottom: 12px;
}

.api-key-form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

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

.modal-btn {
  padding: 9px 22px;
  border-radius: var(--r-md);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: var(--font-hebrew);
}

.modal-btn-secondary {
  background: transparent;
  border: 1px solid var(--surface-border);
  color: var(--text-2);
}

.modal-btn-secondary:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

.modal-btn-primary {
  background: var(--accent-1);
  border: none;
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.modal-btn-primary:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.modal-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.api-key-help {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.4;
}

/* Toggle Switch */
.connector-toggle-wrap {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 1;
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-block;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--surface-3);
  border-radius: 24px;
  transition: .3s;
  border: 1px solid var(--surface-border);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: .3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toggle-switch input:checked+.toggle-slider {
  background-color: var(--accent-1);
  border-color: var(--accent-1);
  box-shadow: 0 0 12px var(--accent-glow);
}

.toggle-switch input:checked+.toggle-slider:before {
  transform: translateX(18px);
}

.connectors-loading {
  text-align: center;
  color: var(--text-3);
  font-size: 0.9rem;
  padding: 40px 0;
}

/* ============================================
   Modal
   ============================================ */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.modal-content {
  background: var(--surface-1);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-xl);
  padding: 36px 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  position: relative;
  z-index: 1;
  animation: modalIn 0.35s var(--ease-spring);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 14px;
  left: 14px;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  font-size: 1rem;
  color: var(--text-3);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}

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

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.modal-content h2 {
  margin-bottom: 12px;
  color: var(--text-1);
  font-weight: 700;
}

.modal-content p {
  color: var(--text-2);
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.linking-code {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 8px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 20px;
  margin: 16px 0;
}

.code-expiry {
  font-size: 0.8rem;
  color: var(--warning);
  margin-bottom: 16px !important;
}

.telegram-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #0088cc, #229ED9);
  color: white;
  padding: 12px 24px;
  border-radius: var(--r-full);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  transition: all var(--t-norm) var(--ease-out);
}

.telegram-open-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 136, 204, 0.35);
}

/* ============================================
   Responsive — Mobile First
   ============================================ */

@media (max-width: 768px) {
  .app-shell {
    border: none;
  }

  .app-header {
    padding: 0 0.875rem;
    height: 54px;
  }

  .brand {
    font-size: 1.15rem;
  }

  .brand-sub {
    font-size: 0.65rem;
  }

  .header-icon-btn {
    width: 38px;
    height: 38px;
  }

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

  .telegram-btn svg {
    width: 26px;
    height: 26px;
  }

  .user-avatar-btn {
    width: 34px;
    height: 34px;
  }

  .connect-btn {
    padding: 5px 10px;
    font-size: 0.72rem;
  }

  .connect-btn .status-text {
    display: none;
  }

  .chat-messages {
    padding: 0.875rem 0.75rem;
    gap: 0.75rem;
  }

  .message {
    max-width: 94%;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }

  .message-content {
    padding: 0.75rem 0.9rem;
    border-radius: var(--r-md);
    font-size: 0.92rem;
  }

  .chat-input-area {
    padding: 0.6rem 0.75rem 0.875rem;
  }

  .action-btn {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  textarea {
    font-size: 0.92rem;
    padding: 0.65rem 0.85rem;
    min-height: 40px;
  }

  #send-button,
  .send-btn {
    width: 40px;
    height: 40px;
  }

  .welcome-message {
    padding: 40px 16px 32px;
  }

  .welcome-message h2 {
    font-size: 1.6rem;
  }

  .welcome-message>p {
    font-size: 0.9rem;
  }

  .capabilities-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .capability-card {
    padding: 14px 10px 12px;
  }

  .capability-icon {
    font-size: 1.4rem;
  }

  .category-cards {
    grid-template-columns: 1fr;
  }

  .tab-bar {
    height: 54px;
  }

  .tab-item {
    font-size: 0.68rem;
  }

  .tab-item svg {
    width: 20px;
    height: 20px;
  }

  .connectors-page {
    padding: 20px 16px;
  }

  .connectors-header h2 {
    font-size: 1.3rem;
  }

  .user-dropdown {
    right: 0;
    left: auto;
    max-width: calc(100vw - 16px);
  }
}

@media (max-width: 380px) {
  .capabilities-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .input-actions {
    gap: 0;
  }

  .action-btn {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }

  .header-left {
    gap: 3px;
  }
}

/* Safe area support for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .tab-bar {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================
   Animations & Utilities
   ============================================ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Focus ring for accessibility */
:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
}

/* Selection */
::selection {
  background: rgba(59, 130, 246, 0.2);
  color: white;
}