:root {
  --background: #ffffff;
  --foreground: #0f172a;
  --card: #ffffff;
  --card-foreground: #0f172a;
  --popover: #ffffff;
  --popover-foreground: #0f172a;
  --primary: #0f172a;
  --primary-foreground: #f8fafc;
  --secondary: #f1f5f9;
  --secondary-foreground: #0f172a;
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --accent: #f1f5f9;
  --accent-foreground: #0f172a;
  --destructive: #ef4444;
  --destructive-foreground: #f8fafc;
  --border: #e2e8f0;
  --input: #e2e8f0;
  --ring: #94a3b8;
  --radius: 0.625rem;
  --success: #10b981;
  --warning: #f59e0b;
  --font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --header-h: 3.5rem;
  --footer-h: 2.25rem;
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

[data-theme="festival"] {
  --background: #fafaf9;
  --foreground: #1c1917;
  --card: #ffffff;
  --card-foreground: #1c1917;
  --primary: #ea580c;
  --primary-foreground: #fff7ed;
  --secondary: #fef3c7;
  --secondary-foreground: #78350f;
  --muted: #f5f5f4;
  --muted-foreground: #78716c;
  --accent: #f5f5f4;
  --accent-foreground: #1c1917;
  --border: #e7e5e4;
  --input: #e7e5e4;
  --ring: #ea580c;
  --success: #059669;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--foreground);
  background: var(--background);
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.025em;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
  font-size: 0.875rem;
}

.hidden {
  display: none !important;
}

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 1rem;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.logo-emoji {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.logo-text {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-pills {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  background: var(--muted);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-foreground);
}

.pill-live .pill-dot,
.pill.is-ok .pill-dot {
  background: var(--success);
}

.pill.is-warn .pill-dot {
  background: var(--warning);
}

.pill.is-error .pill-dot {
  background: var(--destructive);
}

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  width: 100%;
}

.chat-main {
  flex: 1 1 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, var(--background) 0%, var(--muted) 120%);
  position: relative;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 0.5rem;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: min(420px, 60vh);
  padding: 1rem 0 2rem;
  animation: messageIn 250ms ease-out;
}

.welcome-hero {
  text-align: center;
  max-width: 32rem;
  margin-bottom: 2rem;
}

.welcome-art {
  font-size: 2.75rem;
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
}

.welcome h2 {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
}

.welcome-sub {
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  width: 100%;
  max-width: 36rem;
}

.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
  cursor: pointer;
}

.feature-card:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
  border-color: var(--ring);
}

.feature-card-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.feature-card h3 {
  font-size: 0.8125rem;
  margin-bottom: 0.25rem;
}

.feature-card p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
  max-width: 100%;
  animation: messageIn 200ms ease-out;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-items: flex-end;
}

.message.agent {
  align-items: flex-start;
}

.bubble {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  line-height: 1.5;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--primary);
  color: var(--primary-foreground);
  border-bottom-right-radius: 0.25rem;
}

.message.agent .bubble {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.25rem;
  max-width: 85%;
}

.message-time {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-top: 0.25rem;
  padding: 0 0.25rem;
}

.bubble h3 {
  font-size: 0.9375rem;
  margin: 0.5rem 0 0.25rem;
  color: var(--primary);
}

.bubble strong {
  font-weight: 600;
}

/* Bundle cards */
.bundle-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
  width: 100%;
}

.bundle-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: bundleIn 250ms ease-out;
}

@keyframes bundleIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.bundle-card-inner {
  padding: 1rem 1rem 1rem calc(1rem + 4px);
  border-left: 4px solid var(--category-color, var(--primary));
}

.bundle-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.bundle-card-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.bundle-category {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bundle-items {
  list-style: disc;
  padding-left: 1.25rem;
  margin: 0 0 0.75rem;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}

.bundle-items li {
  margin-bottom: 0.15rem;
}

.bundle-price-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.price-retail {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  text-decoration: line-through;
}

.price-bundle {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.savings-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border-radius: 999px;
}

.bundle-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.margin-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.margin-excellent {
  background: #d1fae5;
  color: #047857;
}

.margin-good {
  background: #fef3c7;
  color: #b45309;
}

.margin-tight,
.margin-unprofitable {
  background: #fee2e2;
  color: #b91c1c;
}

.promo-block {
  margin-top: 0.75rem;
  width: 100%;
}

.promo-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  margin-bottom: 0.35rem;
}

.promo-copy-wrap {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.promo-copy {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.45;
  padding: 0.5rem 0.65rem;
  background: var(--muted);
  border-radius: calc(var(--radius) - 2px);
  color: var(--foreground);
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-copy {
  flex-shrink: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.6875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
  transition: background 150ms ease, transform 150ms ease;
}

.btn-copy:hover {
  background: var(--secondary);
  transform: scale(1.02);
}

.btn-copy.copied {
  border-color: var(--success);
  color: var(--success);
}

/* Loading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  gap: 1rem;
  animation: messageIn 200ms ease-out;
}

.loading-orb {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--primary);
  animation: pulseOrb 1.2s ease-in-out infinite;
}

@keyframes pulseOrb {
  0%, 100% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1); opacity: 1; }
}

.loading-text {
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.skeleton-wrap {
  width: min(420px, 90%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-line {
  height: 0.75rem;
  border-radius: var(--radius);
  background: linear-gradient(
    90deg,
    var(--muted) 0%,
    var(--border) 50%,
    var(--muted) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-line.w-80 { width: 80%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-40 { width: 40%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Scroll to bottom */
.scroll-bottom-btn {
  position: absolute;
  bottom: 7.5rem;
  right: 1.25rem;
  z-index: 10;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-md);
  transition: transform 150ms ease, opacity 150ms ease;
}

.scroll-bottom-btn:hover {
  transform: scale(1.05);
}

/* Fallback mode banner */
.fallback-banner {
  margin: 0;
  padding: 0.65rem 1rem;
  background: #fffbeb;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
}

.fallback-banner-inner {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  max-width: 72rem;
  margin: 0 auto;
}

.fallback-banner-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  line-height: 1.4;
}

.fallback-banner-title {
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.1rem;
}

.fallback-banner-message {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #92400e;
}

/* Error */
.error-card {
  margin: 0 1rem 0.5rem;
  padding: 0.875rem 1rem;
  background: var(--card);
  border: 1px solid var(--destructive);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.error-card-body {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}

.error-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.error-title {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.15rem;
}

.error-message {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.btn {
  padding: 0.4rem 0.85rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius);
  transition: transform 150ms ease, background 150ms ease;
}

.btn:hover {
  transform: scale(1.02);
}

.btn-outline {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
}

.btn-outline:hover {
  background: var(--muted);
}

/* Input area */
.input-area {
  flex-shrink: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem 1rem;
}

.prompt-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.65rem;
  margin-bottom: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.prompt-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: 0.35rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}

.chip:hover {
  background: var(--primary);
  color: var(--primary-foreground);
  transform: scale(1.02);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#message-input {
  flex: 1;
  padding: 0.65rem 1.15rem;
  border: 1px solid var(--input);
  border-radius: 999px;
  background: var(--background);
  color: var(--foreground);
  transition: box-shadow 150ms ease, border-color 150ms ease;
}

#message-input::placeholder {
  color: var(--muted-foreground);
}

#message-input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent);
}

.send-btn {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  transition: transform 150ms ease, opacity 150ms ease;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Footer */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: var(--footer-h);
  padding: 0 1rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  background: var(--card);
  border-top: 1px solid var(--border);
}

.footer-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
  flex-shrink: 0;
}

.footer-dot.is-ok {
  background: var(--success);
}

/* Responsive */
@media (max-width: 1024px) {
  .feature-grid {
    grid-template-columns: 1fr;
    max-width: 16rem;
  }

  .message.user .bubble,
  .message.agent .bubble {
    max-width: 90%;
  }
}

@media (max-width: 768px) {
  .header-pills .pill:not(.pill-live) {
    display: none;
  }

  .logo-text {
    font-size: 0.875rem;
  }

  .chat-scroll {
    padding: 1rem 0.875rem 0.5rem;
  }

  .message.user .bubble,
  .message.agent .bubble {
    max-width: 92%;
  }

  .scroll-bottom-btn {
    right: 0.875rem;
    bottom: 7rem;
  }
}
