/* ==========================================================================
   KINDEE interface
   --------------------------------------------------------------------------
   Strict three-colour system. Only these three values exist, plus opacity
   variations and blends of them with white. No green, red, purple, teal,
   orange, black or independent grey.

   Status is never communicated by hue alone: every state carries an icon, a
   border treatment and a text label as well.
   ========================================================================== */

:root {
  --primary-blue: #1434CB;
  --background-white: #FFFFFF;
  --accent-yellow: #F7B600;

  /* Surfaces: blue or yellow blended with white. Nothing else. */
  --surface-page: color-mix(in srgb, var(--primary-blue) 3%, var(--background-white));
  --surface-raised: var(--background-white);
  --surface-tint: color-mix(in srgb, var(--primary-blue) 6%, var(--background-white));
  --surface-tint-strong: color-mix(in srgb, var(--primary-blue) 12%, var(--background-white));
  --surface-accent: color-mix(in srgb, var(--accent-yellow) 14%, var(--background-white));
  --surface-accent-strong: color-mix(in srgb, var(--accent-yellow) 28%, var(--background-white));

  /* Type: blue at reduced opacity over white. Never black, never grey. */
  --text-primary: var(--primary-blue);
  --text-secondary: color-mix(in srgb, var(--primary-blue) 88%, var(--background-white));
  --text-muted: color-mix(in srgb, var(--primary-blue) 80%, var(--background-white));
  --text-on-blue: var(--background-white);

  --border-soft: color-mix(in srgb, var(--primary-blue) 16%, var(--background-white));
  --border-medium: color-mix(in srgb, var(--primary-blue) 60%, var(--background-white));
  --border-strong: var(--primary-blue);
  --border-accent: var(--accent-yellow);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px color-mix(in srgb, var(--primary-blue) 10%, transparent);
  --shadow-md: 0 4px 16px color-mix(in srgb, var(--primary-blue) 12%, transparent);
  --shadow-lg: 0 10px 32px color-mix(in srgb, var(--primary-blue) 16%, transparent);

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;

  --font-en: 'Noto Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-th: 'Noto Sans Thai', 'Noto Sans', system-ui, sans-serif;
  --font-stack: var(--font-en), var(--font-th);

  --tap-target: 48px;
  --header-height: 60px;
  --composer-height: 92px;
}

/* Browsers without color-mix still get a compliant palette. */
@supports not (color: color-mix(in srgb, #1434CB 50%, #FFFFFF)) {
  :root {
    /* Exact equivalents of the color-mix values above, computed from
       #1434CB and #F7B600 blended with #FFFFFF. No other colour is used. */
    --surface-page: #F8F9FD;
    --surface-tint: #F1F3FC;
    --surface-tint-strong: #E3E7F9;
    --surface-accent: #FEF5DB;
    --surface-accent-strong: #FDEBB8;
    --text-secondary: #304CD1;
    --text-muted: #435DD5;
    --border-soft: #D9DFF7;
    --border-medium: #7285E0;
    --shadow-sm: 0 1px 2px rgba(20, 52, 203, 0.10);
    --shadow-md: 0 4px 16px rgba(20, 52, 203, 0.12);
    --shadow-lg: 0 10px 32px rgba(20, 52, 203, 0.16);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-stack);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

html[lang="th"] body,
[lang="th"] { font-family: var(--font-th), var(--font-en), sans-serif; }

h1, h2, h3, h4 { margin: 0 0 var(--space-3); font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary-blue); }

/* ------------------------------------------------------------- a11y core */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--space-3); top: -100px; z-index: 100;
  background: var(--primary-blue); color: var(--text-on-blue);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: var(--space-3); }

:focus-visible {
  /* Two-tone so the indicator clears 3:1 against both light and blue
     surfaces: the blue outline carries it on white (8.8:1), the yellow inner
     edge carries it on blue (4.9:1). Yellow alone on white is only 1.8:1. */
  outline: 3px solid var(--primary-blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--accent-yellow);
  border-radius: var(--radius-sm);
}

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

/* ---------------------------------------------------------------- layout */
.app {
  display: flex; flex-direction: column;
  min-height: 100dvh;
  max-width: 720px; margin: 0 auto;
  background: var(--surface-page);
}

.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--header-height);
  padding: var(--space-2) var(--space-4);
  background: var(--primary-blue);
  color: var(--text-on-blue);
  box-shadow: var(--shadow-sm);
}

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

.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: var(--radius-md);
  background: var(--accent-yellow);
  color: var(--primary-blue);
  font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em;
}

.brand-text { min-width: 0; }
.brand-name {
  font-size: 1.1rem; font-weight: 600; letter-spacing: 0.02em;
  line-height: 1.2; color: var(--text-on-blue);
}
.brand-tagline {
  font-size: 0.72rem; line-height: 1.3;
  color: color-mix(in srgb, var(--background-white) 82%, var(--primary-blue));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------- language switch */
.lang-switch {
  display: flex; flex: none;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--background-white) 18%, var(--primary-blue));
  border: 1px solid color-mix(in srgb, var(--background-white) 40%, var(--primary-blue));
}
.lang-btn {
  min-height: 34px; min-width: 52px;
  padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-on-blue);
  font: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer;
}
.lang-btn[aria-pressed="true"] {
  background: var(--accent-yellow);
  color: var(--primary-blue);
}

/* --------------------------------------------------------------- notices */
.notice-bar {
  display: flex; align-items: flex-start; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-accent);
  border-bottom: 1px solid var(--border-accent);
  color: var(--text-secondary);
  font-size: 0.78rem; line-height: 1.4;
}
.notice-bar .icon { flex: none; margin-top: 2px; }

/* ------------------------------------------------------------------ chat */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4) var(--space-4) var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-4);
}

.welcome {
  padding: var(--space-5) var(--space-4);
  text-align: center;
}
.welcome h1 { font-size: 1.4rem; margin-bottom: var(--space-2); }
.welcome p { color: var(--text-secondary); max-width: 40ch; margin: 0 auto; }

.msg { display: flex; flex-direction: column; gap: var(--space-2); max-width: 100%; }
.msg-user { align-items: flex-end; }
.msg-assistant { align-items: stretch; }

.bubble {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  word-break: break-word;
}
.msg-user .bubble {
  background: var(--primary-blue);
  color: var(--text-on-blue);
  border-bottom-right-radius: var(--radius-sm);
}
.msg-assistant .bubble {
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.msg-role {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-muted);
}

/* ------------------------------------------------------- status panels
   Status is carried by icon + border + label, never by hue alone. */
.panel {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
}
.panel-title {
  display: flex; align-items: center; gap: var(--space-2);
  font-weight: 600; margin-bottom: var(--space-2);
}

.panel-warning {
  background: var(--surface-accent);
  border: 1px solid var(--border-accent);
  border-left-width: 5px;
}
.panel-success {
  background: var(--surface-tint);
  border: 1px solid var(--border-medium);
  border-left: 5px solid var(--primary-blue);
}
.panel-info {
  background: var(--surface-tint);
  border: 1px solid var(--border-soft);
  border-left: 5px solid var(--border-medium);
}
.panel-error {
  background: var(--background-white);
  border: 2px solid var(--primary-blue);
  border-left-width: 5px;
}
.panel-error .panel-title { color: var(--primary-blue); }
.panel-error .error-detail {
  margin-top: var(--space-3); padding: var(--space-3);
  background: var(--surface-accent-strong);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.15em; }
.icon-lg { width: 1.5em; height: 1.5em; }

/* ---------------------------------------------------------- product card */
.product-grid { display: flex; flex-direction: column; gap: var(--space-3); }

.product-card {
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.product-card.is-best {
  border: 2px solid var(--accent-yellow);
  box-shadow: var(--shadow-md);
}

.product-media { position: relative; aspect-ratio: 16 / 9; background: var(--surface-tint); }
.product-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.best-badge {
  position: absolute; top: var(--space-3); left: var(--space-3);
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--accent-yellow);
  color: var(--primary-blue);
  font-size: 0.75rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.product-body { padding: var(--space-4); }
.product-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-2);
}
.product-name { font-size: 1.05rem; font-weight: 600; margin: 0; }
.product-price { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.product-desc { font-size: 0.88rem; color: var(--text-secondary); margin-bottom: var(--space-3); }

.facts {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2); margin-bottom: var(--space-3);
}
.fact {
  padding: var(--space-2) var(--space-3);
  background: var(--surface-tint);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}
.fact-label { display: block; color: var(--text-muted); font-size: 0.72rem; }
.fact-value { font-weight: 600; }

.tag-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.tag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 3px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 0.75rem; font-weight: 500;
  border: 1px solid var(--border-medium);
  background: var(--surface-tint);
  color: var(--text-secondary);
}
.tag-allergen {
  background: var(--surface-accent);
  border-color: var(--border-accent);
  color: var(--text-primary);
}
.tag-availability {
  background: var(--surface-raised);
  border: 1px solid var(--primary-blue);
  font-weight: 600;
}
.tag-availability.is-out { background: var(--surface-accent-strong); border-color: var(--border-accent); }

.why-match {
  padding: var(--space-3);
  background: var(--surface-accent);
  border-left: 4px solid var(--accent-yellow);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin-bottom: var(--space-3);
}
.why-match strong { display: block; margin-bottom: 2px; font-size: 0.75rem; }

.fictional-note { font-size: 0.7rem; color: var(--text-muted); margin-top: var(--space-2); }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  font: inherit; font-weight: 600; font-size: 0.95rem;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--primary-blue); color: var(--text-on-blue);
  border: 2px solid var(--primary-blue);
}
.btn-secondary {
  background: var(--background-white); color: var(--primary-blue);
  border: 2px solid var(--primary-blue);
}
.btn-accent {
  background: var(--accent-yellow); color: var(--primary-blue);
  /* Blue, not yellow: a yellow edge on a white surface is only 1.8:1 and
     would leave the control's boundary invisible. */
  border: 2px solid var(--primary-blue);
}
.btn-quiet {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border-soft);
}
.btn-block { width: 100%; }

/* ----------------------------------------------------------- suggestions */
.suggestions { padding: 0 var(--space-4) var(--space-4); }
.suggestions-title {
  font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: var(--space-2);
}
.suggestion-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.suggestion {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border-medium);
  background: var(--surface-raised);
  color: var(--text-primary);
  font: inherit; font-size: 0.85rem; font-weight: 500;
  cursor: pointer; text-align: left;
}
.suggestion:hover { background: var(--surface-tint); }
.suggestion[aria-pressed="true"] {
  background: var(--surface-accent-strong);
  border-color: var(--accent-yellow);
  font-weight: 600;
}
.suggestion-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: var(--space-2); }

/* -------------------------------------------------------------- composer */
.composer {
  position: sticky; bottom: 0; z-index: 15;
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--background-white);
  border-top: 1px solid var(--border-soft);
}
.composer-row { display: flex; gap: var(--space-2); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none;
  min-height: var(--tap-target); max-height: 120px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border-medium);
  background: var(--surface-page);
  color: var(--text-primary);
  font: inherit; font-size: 1rem;
}
.composer textarea::placeholder { color: var(--text-muted); }
.send-btn {
  flex: none; width: var(--tap-target); height: var(--tap-target);
  border-radius: 50%;
  border: 0; background: var(--primary-blue); color: var(--text-on-blue);
  display: grid; place-items: center; cursor: pointer;
}
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* -------------------------------------------------------------- typing */
.typing { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-muted); font-size: 0.85rem; }
/* An author display rule otherwise beats the UA [hidden] rule, so this
   indicator would stay visible regardless of the hidden attribute. */
.typing[hidden] { display: none; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary-blue); opacity: 0.35;
  animation: pulse 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ------------------------------------------------------------ timeline */
.timeline { list-style: none; margin: var(--space-3) 0 0; padding: 0; }
.timeline li {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.timeline-marker {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--border-medium);
  background: var(--background-white);
  font-size: 0.7rem; font-weight: 700;
}
.timeline li.is-done { color: var(--text-primary); font-weight: 500; }
.timeline li.is-done .timeline-marker {
  background: var(--primary-blue); border-color: var(--primary-blue); color: var(--background-white);
}
.timeline li.is-active { color: var(--text-primary); font-weight: 600; }
.timeline li.is-active .timeline-marker {
  background: var(--accent-yellow); border-color: var(--accent-yellow); color: var(--primary-blue);
}
.timeline li.is-skipped .timeline-marker { border-style: dashed; }

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-sandbox { background: var(--accent-yellow); color: var(--primary-blue); }
.badge-blue { background: var(--primary-blue); color: var(--text-on-blue); }
.badge-outline { border: 1.5px solid var(--primary-blue); color: var(--primary-blue); }

/* ------------------------------------------------------------- checkout */
.checkout-card { display: flex; flex-direction: column; gap: var(--space-3); }
.kv { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--border-soft); font-size: 0.88rem; }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; word-break: break-all; }

.credential-line {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3);
  background: var(--surface-tint);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  font-weight: 600; font-variant-numeric: tabular-nums;
}

.threeds-frame {
  width: 100%; min-height: 420px;
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--background-white);
}
.hidden-frame { position: absolute; width: 0; height: 0; border: 0; visibility: hidden; }

/* ---------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--primary-blue) 45%, transparent);
  display: grid; place-items: end center;
  padding: var(--space-4);
}
.modal {
  width: 100%; max-width: 560px;
  max-height: 88dvh; overflow-y: auto;
  background: var(--background-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
}
@media (min-width: 640px) { .modal-backdrop { place-items: center; } }

.footer-note {
  padding: var(--space-4);
  font-size: 0.72rem; color: var(--text-muted); text-align: center;
}

.offline-banner {
  padding: var(--space-2) var(--space-4);
  background: var(--surface-accent-strong);
  border-bottom: 1px solid var(--border-accent);
  font-size: 0.8rem; font-weight: 600; text-align: center;
}
