/* ============================================
   AIQYN Design System — CSS Variables v2
   Modern, airy, light design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* ── Typography ── */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  /* ── Spacing ── */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* ── Radius ── */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* ── Transitions ── */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Sidebar ── */
  --sidebar-width: 280px;
}

/* ── LIGHT THEME (default) ── */
[data-theme="light"],
:root {
  --color-bg: #F5F3EF;
  --color-bg-secondary: #EDEAE4;
  --color-surface: #FFFFFF;
  --color-surface-hover: #FAF9F7;
  --color-surface-active: #F0EDE8;

  --color-sidebar-bg: #FAFAF8;
  --color-sidebar-hover: #F0EDE6;
  --color-sidebar-text: #3D3329;
  --color-sidebar-text-muted: #9A8E7C;
  --color-sidebar-border: #E8E4DC;

  --color-primary: #A08B6E;
  --color-primary-hover: #8D7A5F;
  --color-primary-text: #FFFFFF;

  --color-text: #2C2418;
  --color-text-secondary: #6B5D4A;
  --color-text-muted: #A89D8E;
  --color-text-inverse: #FFFFFF;

  --color-border: rgba(60, 51, 41, 0.08);
  --color-border-strong: rgba(60, 51, 41, 0.15);

  --color-user-bubble: #A08B6E;
  --color-user-bubble-text: #FFFFFF;
  --color-ai-bubble: #FFFFFF;
  --color-ai-bubble-text: #2C2418;

  --color-input-bg: #FFFFFF;
  --color-input-border: rgba(60, 51, 41, 0.12);
  --color-input-focus-border: #A08B6E;

  --color-accent: #C4B896;
  --color-accent-soft: rgba(196, 184, 150, 0.15);

  --color-error: #C0392B;
  --color-success: #6A8C5E;

  --shadow-sm: 0 1px 3px rgba(60, 51, 41, 0.05);
  --shadow-md: 0 4px 16px rgba(60, 51, 41, 0.07);
  --shadow-lg: 0 8px 30px rgba(60, 51, 41, 0.1);
  --shadow-xl: 0 20px 60px rgba(60, 51, 41, 0.12);
  --shadow-input: 0 2px 8px rgba(60, 51, 41, 0.06);

  --color-ornament: rgba(160, 139, 110, 0.05);
  --color-ornament-strong: rgba(160, 139, 110, 0.1);
  --color-glass: rgba(255, 255, 255, 0.85);
  --color-glass-border: rgba(255, 255, 255, 0.6);

  --color-logo: #1C1A17;
  /* Dark logo for light theme */
}

/* ── DARK THEME ── */
[data-theme="dark"] {
  --color-bg: #161412;
  --color-bg-secondary: #1E1B18;
  --color-surface: #252220;
  --color-surface-hover: #2E2A27;
  --color-surface-active: #38332E;

  --color-sidebar-bg: #1C1A17;
  --color-sidebar-hover: #2A2723;
  --color-sidebar-text: #E8E4DB;
  --color-sidebar-text-muted: #8A7E6F;
  --color-sidebar-border: #2E2A26;

  --color-primary: #C4B08A;
  --color-primary-hover: #D4C49E;
  --color-primary-text: #161412;

  --color-text: #E8E4DB;
  --color-text-secondary: #B4A99A;
  --color-text-muted: #6A6055;
  --color-text-inverse: #161412;

  --color-border: rgba(240, 237, 229, 0.06);
  --color-border-strong: rgba(240, 237, 229, 0.12);

  --color-user-bubble: #C4B08A;
  --color-user-bubble-text: #161412;
  --color-ai-bubble: #252220;
  --color-ai-bubble-text: #E8E4DB;

  --color-input-bg: #252220;
  --color-input-border: rgba(240, 237, 229, 0.08);
  --color-input-focus-border: #C4B08A;

  --color-accent: #D4C88F;
  --color-accent-soft: rgba(212, 200, 143, 0.1);

  --color-error: #E74C3C;
  --color-success: #7EC96A;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.4);
  --shadow-input: 0 2px 8px rgba(0, 0, 0, 0.15);

  --color-ornament: rgba(196, 176, 138, 0.03);
  --color-ornament-strong: rgba(196, 176, 138, 0.06);
  --color-glass: rgba(37, 34, 32, 0.85);
  --color-glass-border: rgba(196, 176, 138, 0.1);

  --color-logo: #C4B08A;
  /* Light beige logo for dark theme */
}

/* ── Invert Logo for Dark Theme ── */
[data-theme="dark"] img[src*="logo.svg"] {
  filter: invert(80%) sepia(35%) saturate(300%) hue-rotate(5deg) brightness(1.1) contrast(0.9);
}

/* ── Theme Icons (Ornaments) ── */
/* The icons are natively light beige (#EDECE3) */
/* In light theme, we invert them so they become dark and visible against the light background */
[data-theme="light"] img[src*="assets/icons/"] {
  filter: invert(1) brightness(0.2);
}

/* In dark theme, they remain their native light beige color. We ensure the invert logic from logo doesn't override them if not needed. */
[data-theme="dark"] img[src*="assets/icons/"] {
  filter: none;
}

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

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

body {
  font-family: var(--font-primary);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background-color var(--transition-base), color var(--transition-base);
  overscroll-behavior: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea {
  font-family: inherit;
  font-size: 16px;
  /* prevents iOS zoom */
  color: inherit;
  -webkit-appearance: none;
}

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-text-muted);
  border-radius: var(--radius-full);
  opacity: 0.5;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

/* ── Loading Screen ── */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

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

.loader-logo {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-xl);
  animation: loaderPulse 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loader-logo img,
.loader-logo svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes loaderPulse {

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

  50% {
    transform: scale(0.95);
    opacity: 0.7;
  }
}

.loader-icons-swap {
  position: relative;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-md);
}

.swap-icon {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transform: scale(0.8);
  animation: iconSwap 3.2s infinite ease-in-out;
}

/* 4 Icons, each takes 25% of the 3.2s animation = 0.8s per icon */
.swap-icon:nth-child(1) {
  animation-delay: 0s;
}

.swap-icon:nth-child(2) {
  animation-delay: 0.8s;
}

.swap-icon:nth-child(3) {
  animation-delay: 1.6s;
}

.swap-icon:nth-child(4) {
  animation-delay: 2.4s;
}

@keyframes iconSwap {
  0% {
    opacity: 0;
    transform: scale(0.5) rotate(-30deg);
  }

  10% {
    opacity: 1;
    transform: scale(1.1) rotate(0deg);
  }

  15% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  25% {
    opacity: 0;
    transform: scale(0.8) rotate(20deg);
  }

  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

.loader-text {
  margin-top: var(--space-lg);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

/* ── Smooth Theme Transition ── */
.theme-transitioning,
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease !important;
}