:root {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-surface-alt: #f4f4f5;
  --color-text: #0f0f0f;
  --color-muted: #707579;
  --color-border: #e7e7e9;
  --color-accent: #3390ec;
  --color-accent-contrast: #ffffff;
  --color-accent-soft: #e5f1fd;
  --color-success: #4fae4e;
  --color-warning: #e39d2b;
  --color-danger: #e53935;
  --color-bubble-in: #ffffff;
  --color-bubble-out: #eeffde;
  --color-bubble-out-meta: #4fae4e;
  --color-bubble-out-accent: #3a8e26;
  --color-chat-bg: #99ba92;
  --color-date-pill: rgba(0, 0, 0, 0.18);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #181818;
    --color-surface: #212121;
    --color-surface-alt: #2c2c2c;
    --color-text: #ffffff;
    --color-muted: #aaaaaa;
    --color-border: #303030;
    --color-accent: #8774e1;
    --color-accent-contrast: #ffffff;
    --color-accent-soft: #2f2a47;
    --color-success: #5cc85a;
    --color-warning: #f0ad4e;
    --color-danger: #ff595a;
    --color-bubble-in: #212121;
    --color-bubble-out: #766ac8;
    --color-bubble-out-meta: rgba(255, 255, 255, 0.6);
    --color-bubble-out-accent: #ffffff;
    --color-bubble-out-link: #ffffff;
    --color-chat-bg: #0f0f0f;
    --color-date-pill: rgba(255, 255, 255, 0.12);
  }
}

:root[data-theme="dark"] {
  --color-bg: #181818;
  --color-surface: #212121;
  --color-surface-alt: #2c2c2c;
  --color-text: #ffffff;
  --color-muted: #aaaaaa;
  --color-border: #303030;
  --color-accent: #8774e1;
  --color-accent-contrast: #ffffff;
  --color-accent-soft: #2f2a47;
  --color-success: #5cc85a;
  --color-warning: #f0ad4e;
  --color-danger: #ff595a;
  --color-bubble-in: #212121;
  --color-bubble-out: #766ac8;
  --color-bubble-out-meta: rgba(255, 255, 255, 0.6);
  --color-bubble-out-accent: #ffffff;
  --color-bubble-out-link: #ffffff;
  --color-chat-bg: #0f0f0f;
  --color-date-pill: rgba(255, 255, 255, 0.12);
}

:root[data-theme="light"] {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-surface-alt: #f4f4f5;
  --color-text: #0f0f0f;
  --color-muted: #707579;
  --color-border: #e7e7e9;
  --color-accent: #3390ec;
  --color-accent-contrast: #ffffff;
  --color-accent-soft: #e5f1fd;
  --color-success: #4fae4e;
  --color-warning: #e39d2b;
  --color-danger: #e53935;
  --color-bubble-in: #ffffff;
  --color-bubble-out: #eeffde;
  --color-bubble-out-meta: #4fae4e;
  --color-bubble-out-link: var(--color-accent);
  --color-bubble-out-accent: #3a8e26;
  --color-chat-bg: #99ba92;
  --color-date-pill: rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

html[data-reduce-motion] *,
html[data-reduce-motion] *::before,
html[data-reduce-motion] *::after {
  transition-duration: 0.001ms !important;
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

::selection {
  background: var(--color-accent-soft);
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline-offset: 0;
}

button,
a,
.rail-btn,
.chat-list-item,
.settings-chip,
.settings-row,
.info-panel-row,
.login-input,
.settings-input {
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
button:active:not(:disabled) {
  transform: scale(0.97);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ===== Lightweight Boot Splash ===== */
#boot-splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3d6df0;
  z-index: 10000;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
#boot-splash.boot-splash-hidden {
  opacity: 0;
  visibility: hidden;
}
#boot-splash svg {
  width: 84px;
  height: 84px;
  transform-origin: center;
}
#boot-splash .bs-word {
  display: flex;
  gap: 2px;
  font: 700 28px/1 var(--font-sans);
  color: #fff;
  text-transform: none;
}
#boot-splash .bs-word i {
  display: inline-block;
  opacity: 0;
  transform: translateY(30px) rotate(-45deg) scale(0.5);
  transition: opacity 0.4s cubic-bezier(0.2, 0, 0.2, 1),
              transform 0.4s cubic-bezier(0.2, 0, 0.2, 1);
}
#boot-splash .bs-word i:nth-child(1) { transition-delay: 0.00s; }
#boot-splash .bs-word i:nth-child(2) { transition-delay: 0.05s; }
#boot-splash .bs-word i:nth-child(3) { transition-delay: 0.10s; }
#boot-splash .bs-word i:nth-child(4) { transition-delay: 0.15s; }
#boot-splash .bs-word i:nth-child(5) { transition-delay: 0.20s; }
#boot-splash .bs-word i:nth-child(6) { transition-delay: 0.25s; }
#boot-splash .bs-word i:nth-child(7) { transition-delay: 0.30s; }
#boot-splash.boot-splash-hidden .bs-word i {
  opacity: 0;
  transform: translateY(-30px) rotate(45deg) scale(0.5);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 1, 1);
}
#boot-splash.boot-splash-hidden .bs-word i:nth-child(1) { transition-delay: 0.00s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(2) { transition-delay: 0.03s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(3) { transition-delay: 0.06s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(4) { transition-delay: 0.09s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(5) { transition-delay: 0.12s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(6) { transition-delay: 0.15s; }
#boot-splash.boot-splash-hidden .bs-word i:nth-child(7) { transition-delay: 0.18s; }

/* ===== Landscape phone fixes ===== */
@media (orientation: landscape) and (max-height: 500px) {
  /* Reduce vertical padding/margins globally */
  .shell { height: 100dvh; }
  
  /* Nav rail - make more compact */
  .nav-rail {
    padding: 4px 2px;
    gap: 2px;
  }
  .rail-btn {
    height: 36px;
    width: 36px;
    border-radius: 10px;
  }
  .nav-rail-account { margin-bottom: 0; }
  
  /* Composer - compact */
  .composer-row { padding: 4px 8px; gap: 4px; }
  .composer-textarea { 
    min-height: 28px; 
    max-height: 60px; 
    padding: 6px 10px; 
    font-size: 14px;
  }
  .composer-icon-btn { height: 32px; width: 32px; }
  .composer-send-btn { height: 32px; width: 32px; }
  .composer-staged-tray { padding: 4px 8px 0; gap: 4px; }
  .composer-staged-item { width: 48px; height: 48px; }
  .composer-banner { padding: 4px 12px; }
  .composer-banner-body { gap: 2px; }
  .composer-banner-label { font-size: 10px; }
  .composer-banner-text { font-size: 12px; }
  
  /* Chat list - more compact */
  .chat-list-item { padding: 6px 10px; gap: 8px; }
  .chat-list-item-avatar { width: 36px; height: 36px; }
  .chat-list-item-content { gap: 2px; }
  .chat-list-item-name { font-size: 13px; }
  .chat-list-item-preview { font-size: 12px; }
  
  /* Messages - tighter spacing */
  .message-bubble { padding: 6px 10px; margin: 2px 8px; }
  .message-bubble-text { font-size: 13px; line-height: 1.3; }
  .message-meta { font-size: 10px; margin-top: 2px; }
  
  /* Chat header */
  .chat-header { padding: 6px 10px; min-height: 44px; }
  .chat-header-title { font-size: 14px; }
  .chat-header-subtitle { font-size: 11px; }
  
  /* Sidebar / panels */
  .sidebar-menu-btn { height: 32px; width: 32px; }
  .sidebar-fab { height: 44px; width: 44px; bottom: 10px; right: 10px; }
  
  /* Settings / profile */
  .settings-section { padding: 8px 0; }
  .settings-row { padding: 8px 12px; }
  .profile-avatar-row { padding: 8px; }
  
  /* Search bar */
  .chat-search-bar { padding: 8px 8px 4px; }
  .chat-search-input { padding: 6px 10px 6px 30px; font-size: 13px; }
  
  /* Tabs */
  .chat-tabs-row { padding: 6px 6px; }
  .chat-tab { padding: 4px 10px; font-size: 12px; }
  
  /* Dismissible banner */
  .dismissible-banner { padding: 6px 10px; font-size: 12px; }
  
  /* Holiday banner */
  .holiday-banner { padding: 5px 10px; font-size: 12px; }
  
  /* Incoming call banner */
  .incoming-call-screen { padding: 12px; gap: 8px; }
  .incoming-call-avatar { width: 60px; height: 60px; }
  
  /* Call bubble */
  .call-bubble { padding: 6px 10px; }
  
  /* Toasts */
  .tw-toast { padding: 8px 12px; font-size: 12px; }
  
  /* Modals */
  .modal-overlay { padding: 10px; }
  .modal-dialog { max-height: 90vh; }
}

/* Extra compact for very short landscape (e.g., iPhone SE landscape ~320px) */
@media (orientation: landscape) and (max-height: 360px) {
  .nav-rail { padding: 2px; }
  .rail-btn { height: 32px; width: 32px; }
  .composer-row { padding: 2px 6px; }
  .composer-textarea { min-height: 24px; max-height: 48px; padding: 4px 8px; }
  .composer-staged-item { width: 40px; height: 40px; }
  .chat-list-item { padding: 4px 8px; }
  .chat-list-item-avatar { width: 32px; height: 32px; }
  .message-bubble { padding: 4px 8px; margin: 1px 6px; }
  .chat-header { min-height: 38px; padding: 4px 8px; }
}

/* Fix for notched phones in landscape - ensure safe area */
@supports (padding: max(0px)) {
  @media (orientation: landscape) {
    .shell {
      padding-left: max(0px, env(safe-area-inset-left));
      padding-right: max(0px, env(safe-area-inset-right));
    }
    .composer {
      padding-left: max(0px, env(safe-area-inset-left));
      padding-right: max(0px, env(safe-area-inset-right));
    }
    .nav-rail {
      padding-left: max(4px, env(safe-area-inset-left));
      padding-right: max(4px, env(safe-area-inset-right));
    }
    .chat-header {
      padding-left: max(10px, env(safe-area-inset-left));
      padding-right: max(10px, env(safe-area-inset-right));
    }
  }
}

/* Fix for virtual keyboard on mobile - use dvh/dvw */
@supports (height: 100dvh) {
  #view-root {
    height: 100dvh;
  }
  .shell {
    height: 100dvh;
  }
}

#view-root {
  position: fixed;
  top: var(--app-top, 0px);
  left: 0;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  width: 100%;
  overflow: hidden;
}

:root,
:root[data-theme="light"] {
  --chat-gradient: linear-gradient(135deg, #dbddbb 0%, #a8c89a 30%, #d5d88d 60%, #88b884 100%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chat-gradient: linear-gradient(135deg, #1f2b23 0%, #121a16 45%, #1c2420 100%);
  }
}
:root[data-theme="dark"] {
  --chat-gradient: linear-gradient(135deg, #1f2b23 0%, #121a16 45%, #1c2420 100%);
}
