/* ===========================================================
   Vredehoek CID Info Assistant — design tokens & base styles
   Palette derived from the Vredehoek CID brand: teal green (primary/civic
   trust), warm orange & gold (energy/community), muted pink (warmth accent)
   =========================================================== */

:root,
[data-theme='light'] {
  /* Surfaces */
  --color-bg: #faf8f4;
  --color-surface: #ffffff;
  --color-surface-2: #fdfcfa;
  --color-surface-offset: #f2eee6;
  --color-surface-offset-2: #eae4d8;
  --color-divider: #e2dccd;
  --color-border: #d8d0bd;

  /* Text */
  --color-text: #1f2b26;
  --color-text-muted: #5f6b62;
  --color-text-faint: #a1a99f;
  --color-text-inverse: #f9f8f4;

  /* Primary accent — Teal green */
  --color-primary: #146b5c;
  --color-primary-hover: #0f5148;
  --color-primary-active: #0b3d36;
  --color-primary-highlight: #d3e6e0;

  /* Warm accent — Orange */
  --color-orange: #d97a1f;
  --color-orange-hover: #b8641a;
  --color-orange-highlight: #f3e0c8;

  /* Accent — Gold */
  --color-gold: #d9a824;

  /* Accent — Pink (used sparingly) */
  --color-pink: #c65a72;
  --color-pink-highlight: #f2dbe1;

  /* Error / warning */
  --color-error: #b3402f;
  --color-error-highlight: #f1dad5;

  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1.25rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px oklch(0.2 0.02 160 / 0.06);
  --shadow-md: 0 6px 20px oklch(0.2 0.02 160 / 0.10);
  --shadow-lg: 0 16px 40px oklch(0.2 0.02 160 / 0.16);

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: 'Cabinet Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;

  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.3rem + 1vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.5rem + 2vw, 3rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
}

[data-theme='dark'] {
  --color-bg: #121916;
  --color-surface: #182220;
  --color-surface-2: #1c2724;
  --color-surface-offset: #202a27;
  --color-surface-offset-2: #263330;
  --color-divider: #2a3532;
  --color-border: #37433f;

  --color-text: #dce6e1;
  --color-text-muted: #8ea099;
  --color-text-faint: #5c6b65;
  --color-text-inverse: #142320;

  --color-primary: #4fa896;
  --color-primary-hover: #6cbfae;
  --color-primary-active: #85cdbe;
  --color-primary-highlight: #24403a;

  --color-orange: #e6a355;
  --color-orange-hover: #f0b978;
  --color-orange-highlight: #4a3a26;

  --color-gold: #e0be5f;

  --color-pink: #d98297;
  --color-pink-highlight: #472e37;

  --color-error: #d97363;
  --color-error-highlight: #4a2a24;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 6px 20px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 16px 40px oklch(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #121916;
    --color-surface: #182220;
    --color-surface-2: #1c2724;
    --color-surface-offset: #202a27;
    --color-surface-offset-2: #263330;
    --color-divider: #2a3532;
    --color-border: #37433f;
    --color-text: #dce6e1;
    --color-text-muted: #8ea099;
    --color-text-faint: #5c6b65;
    --color-text-inverse: #142320;
    --color-primary: #4fa896;
    --color-primary-hover: #6cbfae;
    --color-primary-active: #85cdbe;
    --color-primary-highlight: #24403a;
    --color-orange: #e6a355;
    --color-orange-hover: #f0b978;
    --color-orange-highlight: #4a3a26;
    --color-gold: #e0be5f;
    --color-pink: #d98297;
    --color-pink-highlight: #472e37;
    --color-error: #d97363;
    --color-error-highlight: #4a2a24;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body, sans-serif);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition-interactive), color var(--transition-interactive);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

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

/* ---------- Layout ---------- */
.page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* ---------- Header ---------- */
.site-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-text h1 {
  font-family: var(--font-display, sans-serif);
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.brand-text p {
  margin: 2px 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  transition: border-color var(--transition-interactive), color var(--transition-interactive), background var(--transition-interactive);
}
.icon-btn:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* ---------- Intro banner ---------- */
.intro {
  flex-shrink: 0;
  background: var(--color-primary-highlight);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  transition: padding 0.35s ease, margin-bottom 0.35s ease;
}

.intro-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}

.intro h2 {
  font-family: var(--font-display, sans-serif);
  font-size: var(--text-base);
  margin: 0;
  color: var(--color-primary-active, var(--color-primary));
}

.intro-chevron {
  flex-shrink: 0;
  color: var(--color-primary-active, var(--color-primary));
  transition: transform 0.3s ease;
}

.intro-body {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transition: grid-template-rows 0.35s ease, opacity 0.25s ease, margin-top 0.35s ease;
  margin-top: var(--space-2);
}

.intro-body > * {
  min-height: 0;
  overflow: hidden;
}

.intro-body-inner {
  overflow: hidden;
}

.intro.collapsed {
  padding: var(--space-3) var(--space-5);
  margin-bottom: var(--space-3);
}

.intro.collapsed .intro-chevron {
  transform: rotate(-90deg);
}

.intro.collapsed .intro-body {
  grid-template-rows: 0fr;
  opacity: 0;
  margin-top: 0;
}

.intro p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.suggested-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.chip {
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition-interactive), color var(--transition-interactive);
}
.chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Chat area ---------- */
.chat-window {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-2) 0 var(--space-4);
  overflow-y: auto;
}

.msg {
  display: flex;
  gap: var(--space-3);
  max-width: 90%;
  animation: fade-in 220ms ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-inverse);
}

.msg.bot .msg-avatar {
  background: var(--color-primary);
}
.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg.user .msg-avatar {
  background: var(--color-orange);
}

.msg-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-sm);
}

.msg.user .msg-bubble {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.msg-bubble p {
  margin: 0 0 var(--space-2);
}
.msg-bubble p:last-child {
  margin-bottom: 0;
}
.msg-bubble strong {
  font-weight: 700;
}
.msg-bubble ul,
.msg-bubble ol {
  margin: var(--space-2) 0;
  padding-left: var(--space-5);
}
.msg-bubble a {
  color: inherit;
  text-decoration: underline;
}

.msg-bubble.error {
  border-color: var(--color-error);
  background: var(--color-error-highlight);
  color: var(--color-text);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: var(--space-1) 0;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-faint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ---------- Input bar ---------- */
.input-bar {
  flex-shrink: 0;
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
  box-shadow: var(--shadow-md);
}

.input-bar input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-size: 16px; /* keeps mobile browsers (iOS Safari) from auto-zooming on focus */
  font-family: inherit;
  -webkit-appearance: none; /* strip native type="search" chrome (rounded box, inset shadow) so it matches our own pill styling */
  appearance: none;
}
/* Hide the native WebKit "clear" (x) icon on type="search" so it doesn't clash with the custom send button */
.input-bar input::-webkit-search-cancel-button,
.input-bar input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}
.input-bar input::placeholder {
  color: var(--color-text-faint);
}

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-orange);
  color: var(--color-text-inverse);
  transition: background var(--transition-interactive), transform var(--transition-interactive);
  flex-shrink: 0;
}
.send-btn:hover:not(:disabled) {
  background: var(--color-orange-hover);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

/* ---------- Footer ---------- */
.site-footer {
  flex-shrink: 0;
  margin-top: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}
.site-footer a {
  color: var(--color-text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .page {
    width: 100%;
    padding: var(--space-4) var(--space-3);
  }
  .msg {
    max-width: 96%;
  }
  .brand-text h1 {
    font-size: var(--text-base);
  }
  .intro {
    padding: var(--space-4);
  }
  .intro p {
    font-size: var(--text-xs);
  }
  .input-bar {
    width: 100%;
  }
}

/* ---------- Scrollbar ---------- */
.chat-window::-webkit-scrollbar {
  width: 6px;
}
.chat-window::-webkit-scrollbar-thumb {
  background: var(--color-divider);
  border-radius: var(--radius-full);
}
