html,
body {
  overflow-x: hidden;
}

:root {
  color-scheme: dark;
}

html.dark,
html[data-theme="dark"] {
  color-scheme: dark;
}

html.light,
html[data-theme="light"] {
  color-scheme: light;
}

html.theme-init *,
html.theme-init *::before,
html.theme-init *::after {
  transition: none !important;
  animation: none !important;
}

body {
  min-height: 100vh;
  background-color: #000000;
}

body.camera-open {
  overflow: hidden;
}

body.camera-open #main-navbar {
  display: none !important;
}

body.camera-open #main-navbar * {
  pointer-events: none !important;
}

body.camera-open #route-transition-overlay {
  display: none !important;
}

/* Unified themed scrollbars across the app */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 197, 94, 0.72) rgba(15, 23, 42, 0.42);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.45);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.9), rgba(16, 185, 129, 0.85));
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.35);
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(74, 222, 128, 0.95), rgba(16, 185, 129, 0.95));
}

html.light *,
html[data-theme="light"] * {
  scrollbar-color: rgba(5, 150, 105, 0.65) rgba(148, 163, 184, 0.3);
}

html.light *::-webkit-scrollbar-track,
html[data-theme="light"] *::-webkit-scrollbar-track {
  background: rgba(148, 163, 184, 0.26);
}

html.light *::-webkit-scrollbar-thumb,
html[data-theme="light"] *::-webkit-scrollbar-thumb {
  border-color: rgba(255, 255, 255, 0.6);
}

html.dark body,
html[data-theme="dark"] body {
  background-color: #000000;
}

html.light body,
html[data-theme="light"] body {
  background-color: #f9fafb;
}

.font-display {
  font-family: Poppins, system-ui, sans-serif;
}

#page-shell {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  will-change: opacity, transform;
  isolation: isolate;
}

/* Layered atmosphere for app pages (classify/prices/profile) */
body[data-page="predict"],
body[data-page="prices"],
body[data-page="profile"] {
  --page-bg-a: rgba(16, 185, 129, 0.24);
  --page-bg-b: rgba(37, 99, 235, 0.2);
  --page-bg-c: rgba(34, 197, 94, 0.14);
  --page-grid-a: rgba(110, 231, 183, 0.1);
  --page-grid-b: rgba(20, 184, 166, 0.08);
  --page-base-start: #010711;
  --page-base-mid: #030b1a;
  --page-base-end: #0f0a14;
}

body[data-page="prices"] {
  --page-bg-a: rgba(2, 132, 199, 0.25);
  --page-bg-b: rgba(249, 115, 22, 0.18);
  --page-bg-c: rgba(14, 165, 233, 0.15);
  --page-grid-a: rgba(56, 189, 248, 0.1);
  --page-grid-b: rgba(251, 146, 60, 0.08);
  --page-base-start: #020812;
  --page-base-mid: #081225;
  --page-base-end: #140b09;
}

body[data-page="profile"] {
  --page-bg-a: rgba(52, 211, 153, 0.22);
  --page-bg-b: rgba(14, 165, 233, 0.17);
  --page-bg-c: rgba(34, 197, 94, 0.16);
  --page-grid-a: rgba(52, 211, 153, 0.1);
  --page-grid-b: rgba(59, 130, 246, 0.08);
  --page-base-start: #010812;
  --page-base-mid: #020b1b;
  --page-base-end: #0b0f1c;
}

body[data-page="predict"] #page-shell::before,
body[data-page="prices"] #page-shell::before,
body[data-page="profile"] #page-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  background:
    radial-gradient(850px 520px at -10% 18%, var(--page-bg-a), transparent 68%),
    radial-gradient(760px 540px at 110% 82%, var(--page-bg-b), transparent 64%),
    radial-gradient(680px 420px at 52% -16%, var(--page-bg-c), transparent 70%),
    linear-gradient(125deg, var(--page-base-start) 0%, var(--page-base-mid) 48%, var(--page-base-end) 100%);
  animation: appAtmosphereDrift 20s ease-in-out infinite alternate;
}

body[data-page="predict"] #page-shell::after,
body[data-page="prices"] #page-shell::after,
body[data-page="profile"] #page-shell::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.75;
  background:
    linear-gradient(var(--page-grid-a) 1px, transparent 1px),
    linear-gradient(90deg, var(--page-grid-b) 1px, transparent 1px),
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.06), transparent 58%);
  background-size:
    100% 130px,
    130px 100%,
    100% 100%;
  mask-image: radial-gradient(circle at 50% 44%, #000 34%, transparent 100%);
  animation: appGridPulse 12s ease-in-out infinite;
}

html.light body[data-page="predict"],
html.light body[data-page="prices"],
html.light body[data-page="profile"],
html[data-theme="light"] body[data-page="predict"],
html[data-theme="light"] body[data-page="prices"],
html[data-theme="light"] body[data-page="profile"] {
  --page-bg-a: rgba(16, 185, 129, 0.12);
  --page-bg-b: rgba(59, 130, 246, 0.1);
  --page-bg-c: rgba(34, 197, 94, 0.08);
  --page-grid-a: rgba(16, 185, 129, 0.08);
  --page-grid-b: rgba(56, 189, 248, 0.06);
  --page-base-start: #f4f9ff;
  --page-base-mid: #eef7ff;
  --page-base-end: #f6fbff;
}

html.light body[data-page="predict"] #page-shell::after,
html.light body[data-page="prices"] #page-shell::after,
html.light body[data-page="profile"] #page-shell::after,
html[data-theme="light"] body[data-page="predict"] #page-shell::after,
html[data-theme="light"] body[data-page="prices"] #page-shell::after,
html[data-theme="light"] body[data-page="profile"] #page-shell::after {
  opacity: 0.5;
}

@keyframes appAtmosphereDrift {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(1.2%, -1%, 0) scale(1.04);
  }
}

@keyframes appGridPulse {
  0%,
  100% {
    opacity: 0.62;
  }
  50% {
    opacity: 0.85;
  }
}

#route-transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000 !important;
  pointer-events: none;
  isolation: isolate;
}

#route-transition-panel {
  transform: scaleY(0);
  transform-origin: top;
  will-change: transform;
}

#route-transition-logo {
  opacity: 0;
  transform: scale(0.5);
  will-change: transform, opacity;
}

#route-transition-scan-line {
  transform: translateY(-100%);
  will-change: transform;
}

html.route-transition-pending #route-transition-panel {
  transform: scaleY(1);
  transform-origin: bottom;
}

html.route-transition-pending #page-shell {
  opacity: 0;
  transform: translate3d(0, 10px, 0);
}

@media (prefers-reduced-motion: reduce) {
  #page-shell {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  body[data-page="predict"] #page-shell::before,
  body[data-page="prices"] #page-shell::before,
  body[data-page="profile"] #page-shell::before,
  body[data-page="predict"] #page-shell::after,
  body[data-page="prices"] #page-shell::after,
  body[data-page="profile"] #page-shell::after {
    animation: none !important;
  }
}

#mobile-menu {
  transform-origin: top;
}

#chat-messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 197, 94, 0.7) transparent;
}

#chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(34, 197, 94, 0.6);
  border-radius: 6px;
}

.prediction-batch-scroll {
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 197, 94, 0.68) transparent;
  scroll-behavior: smooth;
}

.prediction-batch-scroll::-webkit-scrollbar {
  height: 8px;
}

.prediction-batch-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.prediction-batch-scroll::-webkit-scrollbar-thumb {
  background: rgba(34, 197, 94, 0.68);
  border-radius: 999px;
}

.prediction-batch-card {
  scroll-snap-align: start;
}

.chat-bubble {
  border-radius: 1rem;
  border: 1px solid transparent;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.chat-bubble-user {
  background-image: linear-gradient(135deg, #16a34a, #22c55e);
  color: #ffffff;
}

.chat-bubble-bot {
  background: rgba(248, 250, 252, 0.95);
  color: #0f172a;
  border-color: rgba(148, 163, 184, 0.28);
}

html.dark .chat-bubble-bot {
  background: rgba(30, 41, 59, 0.86);
  color: #f8fafc;
  border-color: rgba(148, 163, 184, 0.32);
}

.chat-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: #9ca3af;
  animation: chatBounce 1s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

#camera-modal video,
#camera-modal img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#camera-modal canvas {
  display: none;
}

#camera-modal {
  z-index: 2147482000 !important;
  isolation: isolate;
}

#camera-modal .camera-toolbar {
  z-index: 2147483002 !important;
  top: max(0.75rem, env(safe-area-inset-top));
  pointer-events: auto;
}

#camera-modal .camera-toolbar > * {
  pointer-events: auto;
}

#camera-modal .camera-stage {
  z-index: 1;
}

#camera-modal .camera-controls {
  position: relative;
  z-index: 2;
}

#camera-modal button {
  touch-action: manipulation;
}

#camera-detection-region {
  z-index: 3;
  border: 2px solid rgba(74, 222, 128, 0.98);
  border-radius: 1rem;
  background: rgba(34, 197, 94, 0.08);
  box-shadow:
    0 0 0 1px rgba(16, 185, 129, 0.28) inset,
    0 0 26px rgba(34, 197, 94, 0.3);
  transition:
    left 180ms ease,
    top 180ms ease,
    width 180ms ease,
    height 180ms ease,
    opacity 180ms ease;
}

#camera-detection-region::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(110, 231, 183, 0.55);
  border-radius: 0.7rem;
}

#camera-detection-label {
  position: absolute;
  top: -2.2rem;
  left: 0;
  max-width: 12rem;
  padding: 0.22rem 0.6rem;
  border: 1px solid rgba(16, 185, 129, 0.55);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  color: #d1fae5;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.predict-dropzone-empty {
  pointer-events: none;
}

#classify-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 28rem);
  gap: 0.375rem;
}

#tab-classify,
#tab-history {
  width: 100%;
  min-width: 0;
}

@media (max-width: 767px) {
  #chat-panel {
    left: 1rem;
    width: calc(100vw - 2rem);
    right: 1rem;
    bottom: 6rem;
    height: min(72vh, 36rem);
    max-height: calc(100vh - 7rem);
  }

  #home-hero {
    min-height: auto;
  }

  #hero-title {
    font-size: clamp(2rem, 10vw, 2.75rem);
    line-height: 1.1;
  }

  #hero-subtitle {
    font-size: 0.95rem;
  }

  #hero-cta > a {
    width: 100%;
    justify-content: center;
  }

  #hero-stats {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  #features,
  #how-it-works,
  #showcase,
  #home-cta {
    padding-top: 4.5rem;
    padding-bottom: 4.5rem;
  }

  #classify-tabs {
    width: 100%;
  }

  #tab-classify,
  #tab-history {
    width: 100%;
  }

  #history-shell {
    height: auto;
    min-height: 0;
  }

  #history-list {
    grid-template-columns: 1fr;
  }

  #camera-mode-capture,
  #camera-mode-live {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    gap: 0.25rem;
  }

  #camera-overlay {
    border-width: 2px;
  }

  #camera-focus-box {
    width: min(72vw, 280px);
    height: min(72vw, 280px);
  }

  #camera-detection-label {
    top: -1.95rem;
    font-size: 0.68rem;
    max-width: 10rem;
    padding: 0.2rem 0.5rem;
  }

  #camera-live-result {
    width: calc(100vw - 2rem);
    min-width: 0;
    bottom: 7.5rem;
    padding: 1rem;
  }

  #camera-detect-error {
    width: calc(100vw - 2rem);
    text-align: center;
    bottom: 6.25rem;
  }

  #camera-preview-actions > button {
    width: 100%;
    justify-content: center;
  }

  #price-modal {
    padding: 0.75rem;
  }

  #price-modal-card {
    max-height: calc(100vh - 1.5rem);
    border-radius: 1rem;
  }

  #price-modal-header {
    padding: 1rem;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
  }

  #price-modal-market {
    font-size: 1.5rem;
    line-height: 1.2;
  }

  #price-modal-vegetable {
    font-size: 1rem;
  }

  #price-modal-prices,
  #price-modal-locations {
    font-size: 0.95rem;
  }
}
