/* Theme system: CSS variable definitions for all 12 themes */
@import './theme/css/themes.css';
@import './theme/css/base.css';

@tailwind base;
@tailwind components;
@tailwind utilities;

/* KaTeX styles */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1em 0;
  margin: 1em 0;
}

.katex {
  color: inherit;
}

.dark .katex {
  color: var(--lobster-text-primary);
}

/* Improve code block styles */
pre {
  background-color: var(--lobster-surface-raised);
  border-radius: 0.75rem !important;
  padding: 1em !important;
  margin: 1em 0 !important;
  overflow-x: auto !important;
}

/* CodeMirror: reset global pre/code overrides inside CM editor */
.cm-editor pre {
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  background-color: transparent !important;
}

.cm-editor code {
  font-family: inherit;
}

code {
  font-family: 'SF Mono', 'Fira Code', Menlo, Monaco, 'Courier New', monospace;
}

/* Improve table styles */
table {
  border-collapse: collapse;
  margin: 1em 0;
  width: 100%;
}

th, td {
  border-color: var(--lobster-border);
  padding: 0.5em;
}

th {
  background-color: var(--lobster-surface-raised);
  opacity: 0.8;
  font-weight: bold;
}

/* Style for blockquotes */
blockquote {
  border-left-color: var(--lobster-primary);
  color: var(--lobster-text-secondary);
  border-left-width: 3px;
  padding-left: 1em;
  font-style: italic;
  margin: 1em 0;
}

.chat-message {
  content-visibility: auto;
  contain-intrinsic-size: 500px;
}

:root {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', 'Helvetica Neue', 'Inter', system-ui, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  font-weight: 400;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Theme colors are driven by CSS variables from themes.css.
 * color-scheme is set by the [data-theme] selectors. */
body, #root, .App, main {
  background-color: var(--lobster-background);
  color: var(--lobster-foreground);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

#root {
  height: 100vh;
}

/* Custom scrollbar styles - cold modern */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background-color: var(--lobster-scroll-thumb);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--lobster-scroll-thumb-hover);
}

.model-selector-scroll {
  scrollbar-color: var(--lobster-scroll-thumb) transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.model-selector-scroll::-webkit-scrollbar {
  width: 10px;
}

.model-selector-scroll::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 10px;
}

.model-selector-scroll::-webkit-scrollbar-thumb {
  background-clip: content-box;
  background-color: var(--lobster-scroll-thumb);
  border: 3px solid transparent;
  border-radius: 999px;
}

.model-selector-scroll::-webkit-scrollbar-thumb:hover {
  background-color: var(--lobster-scroll-thumb-hover);
}

.scrollbar-hidden {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.scrollbar-hidden::-webkit-scrollbar {
  display: none;
}

.dreaming-scene-star {
  animation: dreaming-star-twinkle 3s ease-in-out infinite alternate;
}

.dreaming-scene-star-soft {
  background-color: rgba(59, 130, 246, 0.24);
}

.dreaming-scene-star-accent {
  background-color: rgba(255, 95, 86, 0.34);
}

.dark .dreaming-scene-star-soft {
  background-color: rgba(245, 246, 248, 0.7);
}

.dark .dreaming-scene-star-accent {
  background-color: rgba(255, 77, 77, 0.78);
}

.dreaming-scene {
  background:
    radial-gradient(circle at 20% 78%, rgba(59, 130, 246, 0.14), transparent 28%),
    linear-gradient(180deg, #eef7ff 0%, #f9fbff 52%, #fff6ee 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.dark .dreaming-scene {
  background: #090d13;
  box-shadow: none;
}

.dreaming-scene-orb {
  background: #f3c955;
  box-shadow: 0 0 44px rgba(243, 201, 85, 0.28);
}

.dark .dreaming-scene-orb {
  background: #d8b85b;
  box-shadow: 0 0 44px rgba(216, 184, 91, 0.22);
}

.dreaming-scene-orb-haze {
  background: rgba(255, 255, 255, 0.56);
}

.dark .dreaming-scene-orb-haze {
  background: rgba(255, 255, 255, 0.1);
}

.dreaming-insight-bubble {
  border-color: rgba(255, 95, 86, 0.22);
  background: rgba(255, 255, 255, 0.68);
  color: #d93636;
  box-shadow: 0 12px 34px rgba(255, 116, 84, 0.12);
  animation: dreaming-bubble-drift 5s ease-in-out infinite;
}

.dark .dreaming-insight-bubble {
  border-color: rgba(255, 77, 77, 0.2);
  background: rgba(51, 24, 29, 0.7);
  color: #ff5b5b;
  box-shadow: 0 0 32px rgba(255, 77, 77, 0.08);
}

.dreaming-scene-title {
  color: rgba(51, 65, 85, 0.58);
}

.dark .dreaming-scene-title {
  color: rgba(255, 255, 255, 0.45);
}

.dreaming-status-active {
  color: #16a34a;
}

.dark .dreaming-status-active {
  color: #27c469;
}

.dreaming-status-idle {
  color: rgba(71, 85, 105, 0.56);
}

.dark .dreaming-status-idle {
  color: rgba(255, 255, 255, 0.42);
}

.dreaming-status-dot-active {
  background: #22c55e;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.36);
}

.dark .dreaming-status-dot-active {
  background: #2bd46f;
  box-shadow: 0 0 14px rgba(43, 212, 111, 0.5);
}

.dreaming-status-dot-idle {
  background: rgba(100, 116, 139, 0.48);
}

.dark .dreaming-status-dot-idle {
  background: rgba(255, 255, 255, 0.4);
}

.dreaming-phase-card {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 28px rgba(59, 130, 246, 0.08);
}

.dark .dreaming-phase-card {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(12, 17, 25, 0.85);
  box-shadow: 0 0 20px rgba(43, 212, 111, 0.04);
}

.dreaming-phase-label {
  color: rgba(30, 41, 59, 0.82);
}

.dark .dreaming-phase-label {
  color: rgba(255, 255, 255, 0.8);
}

.dreaming-phase-time {
  color: rgba(71, 85, 105, 0.6);
}

.dark .dreaming-phase-time {
  color: rgba(255, 255, 255, 0.42);
}

.dreaming-mascot {
  position: relative;
  width: clamp(168px, 24vw, 200px);
  min-width: 168px;
  pointer-events: none;
}

.dreaming-mascot-glow {
  position: absolute;
  left: 50%;
  top: 58%;
  width: 92%;
  height: 42%;
  transform: translate(-50%, -50%);
  border-radius: 9999px;
  background: radial-gradient(ellipse, rgba(255, 77, 77, 0.16) 0%, rgba(255, 140, 78, 0.08) 42%, transparent 72%);
  filter: blur(18px);
  animation: dreaming-glow-pulse 4s ease-in-out infinite;
}

.dark .dreaming-mascot-glow {
  background: radial-gradient(ellipse, rgba(255, 77, 77, 0.2) 0%, rgba(255, 77, 77, 0.08) 40%, transparent 72%);
}

.dreaming-mascot-image {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 18px 26px rgba(148, 163, 184, 0.28)) drop-shadow(0 0 22px rgba(255, 77, 77, 0.14));
  user-select: none;
  animation: dreaming-breathe 4s ease-in-out infinite;
}

.dark .dreaming-mascot-image {
  filter: drop-shadow(0 0 38px rgba(255, 77, 77, 0.22));
}

.dreaming-z {
  position: absolute;
  z-index: 3;
  color: rgba(214, 54, 54, 0.7);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-weight: 800;
  line-height: 1;
  opacity: 0;
  animation: dreaming-float-z 4s ease-out infinite;
}

.dark .dreaming-z {
  color: #ff4d4d;
}

.dreaming-z-one {
  left: 70%;
  top: 31%;
  font-size: 14px;
  animation-delay: 0s;
}

.dreaming-z-two {
  left: 82%;
  top: 21%;
  font-size: 20px;
  animation-delay: 1.2s;
}

.dreaming-z-three {
  left: 95%;
  top: 10%;
  font-size: 28px;
  animation-delay: 2.4s;
}

@keyframes dreaming-breathe {
  0%, 100% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.04) translateY(-5px);
  }
}

@keyframes dreaming-float-z {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(-10deg);
  }
  15% {
    opacity: 0.72;
  }
  80% {
    opacity: 0.28;
  }
  100% {
    opacity: 0;
    transform: translate(22px, -42px) rotate(15deg);
  }
}

@keyframes dreaming-star-twinkle {
  0% {
    transform: scale(0.75);
    filter: blur(0);
  }
  100% {
    transform: scale(1.25);
    filter: blur(0.2px);
  }
}

@keyframes dreaming-glow-pulse {
  0%, 100% {
    opacity: 0.58;
  }
  50% {
    opacity: 1;
  }
}

@keyframes dreaming-bubble-drift {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dreaming-scene-star,
  .dreaming-mascot-glow,
  .dreaming-mascot-image,
  .dreaming-z,
  .dreaming-insight-bubble {
    animation: none;
  }

  .dreaming-z {
    opacity: 0.42;
  }
}

/* Style for select options to match theme */
option {
  background-color: var(--lobster-surface);
  color: var(--lobster-foreground);
}

/* Ensure select elements have proper styling in Firefox */
select {
  -moz-appearance: none;
  appearance: none;
}

select::-ms-expand {
  display: none;
}

.draggable {
  -webkit-app-region: drag;
  app-region: drag;
}

.non-draggable {
  -webkit-app-region: no-drag;
  app-region: no-drag;
}

.non-draggable * {
  -webkit-app-region: no-drag;
  app-region: no-drag;
}

.window-controls-floating {
  user-select: none;
}

/* Focus ring */
.focus-ring {
  @apply focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2;
  --tw-ring-offset-color: var(--lobster-background);
}

/* Button styles */
.btn-primary {
  @apply bg-primary hover:bg-primary-hover text-white font-medium py-2 px-4 rounded-lg transition-colors;
}

.btn-secondary {
  background-color: var(--lobster-surface);
  color: var(--lobster-text-primary);
  border: 1px solid var(--lobster-border);
  @apply font-medium py-2 px-4 rounded-lg transition-colors;
}
.btn-secondary:hover {
  background-color: var(--lobster-surface-raised);
}

/* Sidebar width transition */
.sidebar-transition {
  transition: width 200ms ease-out;
  will-change: width;
}

/* Subtle separator line */
.separator {
  border-color: var(--lobster-border-subtle);
  border-top-width: 1px;
}

/* Modal backdrop */
.modal-backdrop {
  @apply bg-black/40 backdrop-blur-sm;
  animation: fade-in 0.2s ease-out;
}

/* Modal content entrance */
.modal-content {
  animation: scale-in 0.2s ease-out;
}

/* Popover entrance */
.popover-enter {
  animation: fade-in-down 0.2s ease-out;
}

/* Skeleton loading */
.skeleton {
  background-color: var(--lobster-surface-raised);
  @apply rounded;
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  animation: shimmer 1.5s infinite;
}

/* Streaming activity bar */
.streaming-bar {
  position: relative;
  height: 2px;
  overflow: hidden;
  border-radius: 1px;
  background: var(--lobster-primary-muted);
}
.streaming-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  border-radius: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--lobster-primary) 50%, transparent 100%);
  opacity: 0.7;
  animation: streaming-slide 1.5s ease-in-out infinite;
}
/* Streaming bar glow uses primary color */
.streaming-bar::before {
  box-shadow: 0 0 6px var(--lobster-primary-muted);
}

.context-compaction-progress {
  position: relative;
  height: 3px;
  overflow: hidden;
  border-radius: 9999px;
  background: var(--lobster-primary-muted);
}

.context-compaction-progress::before {
  content: '';
  position: absolute;
  top: 0;
  left: -55%;
  height: 100%;
  width: 55%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent 0%, var(--lobster-primary) 50%, transparent 100%);
  box-shadow: 0 0 8px var(--lobster-primary);
  animation: context-compaction-slide 1.1s ease-in-out infinite;
}

@keyframes context-compaction-slide {
  0% { left: -55%; }
  100% { left: 100%; }
}

@keyframes streaming-slide {
  0% { left: -40%; }
  100% { left: 100%; }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
