/* ==========================================================================
   oryt.ai Design System
   A production-grade CSS foundation for the oryt.ai chat interface.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* — Color Palette — */
  --color-bg:              #09090b;
  --color-surface:         #131316;
  --color-surface-raised:  #1a1a1f;
  --color-surface-overlay: #222228;
  --color-border:          rgba(255, 255, 255, 0.08);
  --color-border-strong:   rgba(255, 255, 255, 0.14);

  /* Text */
  --color-text:            #fafafa;
  --color-text-secondary:  rgba(255, 255, 255, 0.64);
  --color-text-muted:      rgba(255, 255, 255, 0.38);
  --color-text-disabled:   rgba(255, 255, 255, 0.22);

  /* Brand / Accent */
  --color-accent:          #8b5cf6;
  --color-accent-hover:    #7c3aed;
  --color-accent-subtle:   rgba(139, 92, 246, 0.14);
  --color-accent-glow:     rgba(139, 92, 246, 0.30);

  /* Semantic */
  --color-success:         #22c55e;
  --color-success-subtle:  rgba(34, 197, 94, 0.12);
  --color-error:           #ef4444;
  --color-error-subtle:    rgba(239, 68, 68, 0.12);
  --color-info:            #3b82f6;
  --color-info-subtle:     rgba(59, 130, 246, 0.12);
  --color-warning:         #f59e0b;
  --color-warning-subtle:  rgba(245, 158, 11, 0.12);

  /* — Typography — */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', Monaco, Consolas,
               'Liberation Mono', 'Courier New', monospace;

  --text-xs:   0.75rem;     /* 12px */
  --text-sm:   0.8125rem;   /* 13px */
  --text-base: 0.9375rem;   /* 15px */
  --text-lg:   1.125rem;    /* 18px */
  --text-xl:   1.25rem;     /* 20px */
  --text-2xl:  1.5rem;      /* 24px */
  --text-3xl:  1.875rem;    /* 30px */

  --leading-tight:  1.3;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --tracking-tight: -0.01em;
  --tracking-normal: 0;

  /* — Spacing — */
  --space-1:  0.25rem;   /* 4px  */
  --space-2:  0.5rem;    /* 8px  */
  --space-3:  0.75rem;   /* 12px */
  --space-4:  1rem;      /* 16px */
  --space-5:  1.25rem;   /* 20px */
  --space-6:  1.5rem;    /* 24px */
  --space-8:  2rem;      /* 32px */
  --space-10: 2.5rem;    /* 40px */
  --space-12: 3rem;      /* 48px */

  /* — Radii — */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  /* — Shadows — */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-xl:  0 16px 48px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 24px var(--color-accent-glow);

  /* — Motion — */
  --ease-out:  cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 350ms;

  /* — Layout — */
  --header-height: 64px;
  --max-chat-width: 56rem;  /* 896px */
  --safe-area-top:    env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left:   env(safe-area-inset-left, 0px);
  --safe-area-right:  env(safe-area-inset-right, 0px);
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

img, svg, video {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

::selection {
  background: var(--color-accent);
  color: white;
}

/* --------------------------------------------------------------------------
   3. Accessibility
   -------------------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 9999;
  padding: var(--space-3) var(--space-4);
  background: var(--color-accent);
  color: white;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus {
  top: var(--space-4);
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   4. App Shell
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* --- Header --- */
.app-header {
  flex-shrink: 0;
  z-index: 100;
  border-bottom: 1px solid var(--color-border);
  background: rgba(9, 9, 11, 0.82);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  padding-top: var(--safe-area-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  max-width: var(--max-chat-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Logo area */
.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
  flex-shrink: 0;
}

.header-logo i {
  font-size: 16px;
  color: white;
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: 1;
}

.header-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- New Chat Button --- */
.new-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-strong);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--duration-base) var(--ease-out);
  white-space: nowrap;
}

.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.22);
}

.new-chat-btn:active {
  transform: scale(0.97);
}

/* --- Model Select (Desktop) --- */
.desktop-model-selector {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.desktop-model-selector label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.model-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-4);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  min-width: 200px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 24 24' stroke='rgba(255,255,255,0.5)' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.model-select:hover {
  background-color: rgba(255, 255, 255, 0.07);
  border-color: var(--color-border-strong);
}

.model-select:focus-visible {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
  outline: none;
}

.model-select option {
  background: var(--color-surface-raised);
  color: var(--color-text);
  padding: var(--space-2);
}

/* --- Auth Button --- */
.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-strong);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--duration-base) var(--ease-out);
  white-space: nowrap;
}

.auth-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.22);
}

.auth-btn.signed-in {
  background: var(--color-success-subtle);
  border-color: rgba(34, 197, 94, 0.28);
  color: var(--color-success);
}

/* --- Mobile Menu Button --- */
.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  align-items: center;
  justify-content: center;
  transition: all var(--duration-base) var(--ease-out);
}

.mobile-menu-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   5. Chat Area
   -------------------------------------------------------------------------- */
.chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-5) + var(--safe-area-bottom));
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  width: 100%;
  position: relative;
}

.chat-container > * {
  max-width: var(--max-chat-width);
  margin-left: auto;
  margin-right: auto;
}

/* Scrollbar */
.chat-container::-webkit-scrollbar {
  width: 6px;
}

.chat-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --------------------------------------------------------------------------
   6. Chat Messages
   -------------------------------------------------------------------------- */
.message {
  max-width: 82%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-3);
  line-height: var(--leading-relaxed);
  font-size: var(--text-base);
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  opacity: 0;
  transform: translateY(8px);
  animation: msg-appear var(--duration-slow) var(--ease-out) forwards;
}

@keyframes msg-appear {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger newly added messages */
.message:nth-child(1) { animation-delay: 60ms; }
.message:nth-child(2) { animation-delay: 120ms; }
.message:nth-child(3) { animation-delay: 180ms; }
.message:nth-child(4) { animation-delay: 240ms; }
.message:nth-child(n+5) { animation-delay: 300ms; }

/* -- User bubble -- */
.message.user {
  align-self: flex-end;
  margin-left: auto;
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: var(--shadow-md), 0 0 16px var(--color-accent-glow);
}

/* -- Assistant bubble -- */
.message.assistant {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-bottom-left-radius: var(--radius-sm);
}

/* Prose inside assistant messages */
.message.assistant p {
  margin: 0 0 var(--space-2) 0;
}

.message.assistant p:last-child {
  margin-bottom: 0;
}

.message.assistant ul,
.message.assistant ol {
  padding-left: 1.4em;
  margin: var(--space-2) 0;
}

.message.assistant li {
  margin-bottom: var(--space-1);
}

.message.assistant strong {
  font-weight: 600;
  color: var(--color-text);
}

.message.assistant a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  font-weight: 600;
  margin: var(--space-4) 0 var(--space-2);
  line-height: var(--leading-tight);
}

.message.assistant h1 { font-size: var(--text-xl); }
.message.assistant h2 { font-size: var(--text-lg); }
.message.assistant h3 { font-size: var(--text-base); }

.message.assistant hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-4) 0;
}

.message.assistant blockquote {
  border-left: 3px solid var(--color-accent);
  padding-left: var(--space-4);
  color: var(--color-text-secondary);
  margin: var(--space-3) 0;
}

.message.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
}

.message.assistant th,
.message.assistant td {
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

.message.assistant th {
  background: var(--color-surface-raised);
  font-weight: 600;
}

/* Code */
.message.assistant code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}

.message.assistant pre {
  background: #0c0c0e;
  border: 1px solid var(--color-border);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: var(--space-3) 0;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.message.assistant pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: var(--text-sm);
  line-height: 1.6;
}

/* Code block copy button */
.code-copy-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  opacity: 0;
  transition: all var(--duration-fast) var(--ease-out);
}

.message.assistant pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.1);
}

.code-copy-btn.copied {
  color: var(--color-success);
  border-color: rgba(34, 197, 94, 0.3);
}

/* -- System message -- */
.message.system-message,
.message.system {
  align-self: center;
  max-width: 90%;
  background: var(--color-error-subtle);
  border: 1px solid rgba(239, 68, 68, 0.22);
  color: var(--color-error);
  font-size: var(--text-sm);
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.message.system-message.success {
  background: var(--color-success-subtle);
  border-color: rgba(34, 197, 94, 0.22);
  color: var(--color-success);
}

.message.system-message.info {
  background: var(--color-info-subtle);
  border-color: rgba(59, 130, 246, 0.22);
  color: var(--color-info);
}

/* --------------------------------------------------------------------------
   7. Typing Indicator
   -------------------------------------------------------------------------- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: var(--space-4) var(--space-5);
  align-self: flex-start;
  animation: msg-appear var(--duration-slow) var(--ease-out) forwards;
  opacity: 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--color-text-muted);
  border-radius: var(--radius-full);
  animation: typing-bounce 1.2s ease-in-out infinite both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.28s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.14s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.7);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   8. Welcome Screen
   -------------------------------------------------------------------------- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-4);
  min-height: 50vh;
  animation: welcome-in 0.7s var(--ease-out) forwards;
  opacity: 0;
}

@keyframes welcome-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-glow);
  animation: welcome-icon-float 4s ease-in-out infinite;
}

@keyframes welcome-icon-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

.welcome-icon i {
  font-size: 24px;
  color: white;
}

.welcome-screen h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-3);
}

.welcome-screen p {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  max-width: 28rem;
  margin-bottom: var(--space-8);
  line-height: var(--leading-relaxed);
}

/* Prompt suggestion chips */
.prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  max-width: 32rem;
}

.prompt-suggestion {
  padding: var(--space-2) var(--space-4);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  white-space: nowrap;
}

.prompt-suggestion:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--color-border-strong);
  color: var(--color-text);
  transform: translateY(-1px);
}

.prompt-suggestion:active {
  transform: scale(0.97);
}

/* --------------------------------------------------------------------------
   9. Auth Notice
   -------------------------------------------------------------------------- */
.auth-notice {
  background: var(--color-accent-subtle);
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  animation: msg-appear var(--duration-slow) var(--ease-out) forwards;
  opacity: 0;
}

.auth-notice-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: center;
  text-align: center;
}

.auth-notice-text {
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.manual-auth-btn {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: white;
  border: none;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
}

.manual-auth-btn:hover {
  background: var(--color-accent-hover);
  box-shadow: var(--shadow-glow);
}

.manual-auth-btn:active {
  transform: scale(0.97);
}

.manual-auth-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   10. Input Area
   -------------------------------------------------------------------------- */
.input-area {
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  background: rgba(9, 9, 11, 0.92);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + var(--safe-area-bottom));
  padding-left: max(var(--space-4), var(--safe-area-left));
  padding-right: max(var(--space-4), var(--safe-area-right));
  position: sticky;
  bottom: 0;
  z-index: 50;
  transform: translateZ(0);
  will-change: transform;
}

.input-area .max-w-4xl {
  max-width: var(--max-chat-width);
  margin: 0 auto;
}

/* Status bar */
.status-bar {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-1) 0 var(--space-2);
  text-align: right;
  min-height: 20px;
  transition: color var(--duration-fast);
}

.status-bar.error   { color: var(--color-error); }
.status-bar.loading { color: var(--color-accent); }

/* Input wrapper */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 48px;
}

/* Textarea */
.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl);
  padding: 13px var(--space-4);
  padding-right: 96px;
  color: var(--color-text);
  font-size: 16px; /* Prevents iOS zoom */
  resize: none;
  outline: none;
  transition: all var(--duration-base) var(--ease-out);
  min-height: 48px;
  max-height: 150px;
  line-height: var(--leading-normal);
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.chat-input:focus {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.chat-input::placeholder {
  color: var(--color-text-muted);
}

/* Input action buttons */
.input-buttons {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  pointer-events: auto;
}

.input-buttons button {
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn {
  width: 38px;
  height: 38px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: white;
  transition: all var(--duration-base) var(--ease-out);
  flex-shrink: 0;
}

.send-btn i {
  font-size: 14px;
  line-height: 1;
}

.send-btn:hover:not(:disabled) {
  background: var(--color-accent-hover);
  box-shadow: var(--shadow-glow);
  transform: scale(1.05);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.mic-btn {
  width: 38px;
  height: 38px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  transition: all var(--duration-base) var(--ease-out);
  flex-shrink: 0;
}

.mic-btn i {
  font-size: 14px;
  line-height: 1;
}

.mic-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
}

.mic-btn.listening {
  color: var(--color-error);
  animation: pulse-mic 1.4s ease-in-out infinite;
}

@keyframes pulse-mic {
  0%, 100% { opacity: 1; box-shadow: none; }
  50%      { opacity: 0.6; box-shadow: 0 0 12px var(--color-error-subtle); }
}

/* --------------------------------------------------------------------------
   11. Modals
   -------------------------------------------------------------------------- */

/* Mobile model selector modal */
.mobile-model-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  padding: var(--space-5);
  padding-top: calc(var(--space-5) + var(--safe-area-top));
  padding-bottom: calc(var(--space-5) + var(--safe-area-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-model-modal.active {
  display: flex;
  flex-direction: column;
  animation: modal-in var(--duration-slow) var(--ease-out) forwards;
}

@keyframes modal-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.mobile-model-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
}

.mobile-model-modal .modal-title {
  font-size: var(--text-xl);
  font-weight: 700;
}

.mobile-model-modal .close-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-base);
}

.mobile-model-modal .close-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.mobile-model-modal select {
  width: 100%;
  padding: var(--space-4);
  font-size: 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.mobile-model-modal select option {
  background: var(--color-surface-raised);
  padding: var(--space-3);
}

.mobile-model-modal .apply-btn {
  width: 100%;
  padding: var(--space-4);
  margin-top: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  transition: all var(--duration-base) var(--ease-out);
}

.mobile-model-modal .apply-btn:hover {
  background: var(--color-accent-hover);
}

/* Exit confirmation modal */
.exit-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.exit-modal.active {
  display: flex;
  animation: modal-in var(--duration-slow) var(--ease-out);
}

.exit-modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: modal-content-in var(--duration-slow) var(--ease-spring);
}

@keyframes modal-content-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.exit-modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.exit-modal-text {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-6);
  line-height: var(--leading-relaxed);
  font-size: var(--text-sm);
}

.exit-modal-buttons {
  display: flex;
  gap: var(--space-3);
}

.exit-modal-btn {
  flex: 1;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exit-modal-btn.cancel {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
}

.exit-modal-btn.cancel:hover {
  background: rgba(255, 255, 255, 0.12);
}

.exit-modal-btn.exit {
  background: var(--color-error-subtle);
  color: var(--color-error);
}

.exit-modal-btn.exit:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* --------------------------------------------------------------------------
   12. Touch-Scroll Utility
   -------------------------------------------------------------------------- */
.touch-scroll {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
}

/* --------------------------------------------------------------------------
   13. Responsive — Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  .chat-container {
    padding: var(--space-3);
    padding-bottom: calc(80px + var(--safe-area-bottom));
    padding-left: max(var(--space-3), var(--safe-area-left));
    padding-right: max(var(--space-3), var(--safe-area-right));
  }

  .message {
    max-width: 90%;
    padding: var(--space-3) var(--space-3);
    font-size: var(--text-base);
    margin-bottom: var(--space-2);
  }

  .message.assistant pre {
    padding: var(--space-3);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
  }

  /* Show mobile menu, hide desktop selector */
  .mobile-menu-btn { display: flex; }
  .desktop-model-selector { display: none !important; }

  /* Header */
  .header-logo {
    width: 32px;
    height: 32px;
  }

  .header-logo i { font-size: 14px; }
  .header-title  { font-size: var(--text-lg); }
  .header-subtitle { display: none; }

  /* Auth button */
  .auth-btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    min-height: 40px;
  }

  .auth-btn span { display: none; }

  /* New Chat — icon only */
  .new-chat-btn span { display: none; }
  .new-chat-btn { padding: var(--space-2) var(--space-3) !important; min-width: 40px; }

  /* Auth notice */
  .auth-notice {
    font-size: var(--text-xs);
    padding: var(--space-3);
  }

  .manual-auth-btn { width: 100%; }

  /* Input area */
  .input-area {
    padding: var(--space-3);
    padding-bottom: calc(var(--space-3) + var(--safe-area-bottom));
    padding-left: max(var(--space-3), var(--safe-area-left));
    padding-right: max(var(--space-3), var(--safe-area-right));
  }

  .chat-input {
    font-size: 16px !important;
    padding: 12px 14px;
    padding-right: 96px;
    min-height: 48px;
    max-height: 120px;
    border-radius: var(--radius-xl);
  }

  .input-buttons { right: 6px; gap: 2px; }
  .send-btn, .mic-btn { width: 34px; height: 34px; }
  .send-btn i, .mic-btn i { font-size: 13px; }

  /* Welcome */
  .welcome-screen {
    padding: var(--space-8) var(--space-4);
    min-height: 40vh;
  }

  .welcome-screen h2 { font-size: var(--text-xl); }
  .welcome-screen p  { font-size: var(--text-sm); }
  .welcome-icon { width: 56px; height: 56px; }
  .welcome-icon i { font-size: 20px; }

  .prompt-suggestion {
    font-size: var(--text-sm);
    padding: var(--space-2) var(--space-3);
  }
}

@media (max-width: 480px) {
  .message {
    max-width: 94%;
    padding: var(--space-2) var(--space-3);
  }

  .prompt-suggestion {
    font-size: var(--text-xs);
    padding: 6px var(--space-3);
  }
}

/* --------------------------------------------------------------------------
   14. Responsive — Landscape Mobile
   -------------------------------------------------------------------------- */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --header-height: 48px; }

  .chat-container { padding: var(--space-2); }
  .message { padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
  .input-area { padding: var(--space-2) var(--space-3); }
  .welcome-screen { min-height: 30vh; padding: var(--space-4); }
}

/* --------------------------------------------------------------------------
   15. Touch Device Optimizations
   -------------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  .send-btn,
  .mic-btn,
  .mobile-menu-btn,
  .auth-btn,
  .new-chat-btn,
  .prompt-suggestion {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remove hover transforms on touch */
  .message:hover,
  .prompt-suggestion:hover {
    transform: none;
  }

  .message {
    user-select: text;
    -webkit-user-select: text;
  }

  /* Disable tap highlight */
  button, a, .prompt-suggestion {
    -webkit-tap-highlight-color: transparent;
  }
}

/* --------------------------------------------------------------------------
   16. Reduced Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .welcome-icon { animation: none; }
}

/* --------------------------------------------------------------------------
   17. High Contrast
   -------------------------------------------------------------------------- */
@media (prefers-contrast: high) {
  :root {
    --color-border:        rgba(255, 255, 255, 0.3);
    --color-border-strong: rgba(255, 255, 255, 0.5);
    --color-text-secondary: rgba(255, 255, 255, 0.8);
    --color-text-muted:    rgba(255, 255, 255, 0.6);
  }

  .message.assistant {
    border-width: 2px;
  }
}

/* --------------------------------------------------------------------------
   18. Print
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: white;
    color: black;
  }

  .input-area,
  .app-header,
  .exit-modal,
  .mobile-model-modal,
  .welcome-screen,
  .auth-notice {
    display: none !important;
  }

  .chat-container {
    overflow: visible;
    height: auto;
  }

  .message {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .message.user {
    background: #f0f0f0;
    color: black;
  }
}

/* --------------------------------------------------------------------------
   19. Scrollbar (Firefox)
   -------------------------------------------------------------------------- */
.chat-container {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
