/*
  AI packaging advisor — scoped to `.ai-*`, loaded only on /ai-pidbir-upakovky/
  and /en/ai-packaging-assistant/ via pages/ai_assistant.py head_extra. Calm
  premium B2B workspace using the site's own tokens — no gradients, robots,
  neon, avatars or emoji in the interface. No global stylesheet is affected.
*/

.ai-shell {
  padding-block: var(--space-lg) var(--space-2xl);
  /* Fill the viewport so the start card reads as a complete screen and the
     footer never crowds it. svh has a vh fallback for older/desktop browsers
     and is stable on mobile Safari (no jump when the URL bar hides). */
  min-height: 72vh;
  min-height: 72svh;
}

/* ---- First screen: one centered, self-contained product ---- */
.ai-intro {
  max-width: 880px;
  margin-inline: auto;
  padding-top: var(--space-md);
}
.ai-intro__title {
  margin: var(--space-xs) 0 var(--space-sm);
  font-size: clamp(2.25rem, 2vw + 1.1rem, 3rem);
  line-height: 1.08;
  overflow-wrap: normal;
  word-break: normal;
}
.ai-intro__lede {
  margin: 0 0 var(--space-lg);
  max-width: 46rem;
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--graphite-900);
}
.ai-intro__box {
  padding: var(--space-xl);
  background: var(--surface-card);
  border: var(--hairline) solid var(--metal-300);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.ai-intro__input {
  width: 100%;
  min-height: 132px;
  padding: var(--space-md);
  font: inherit;
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--graphite-950);
  background: var(--warm-white-50);
  border: var(--hairline) solid var(--metal-300);
  border-radius: var(--radius-md);
  resize: vertical;
}
.ai-intro__input:focus-visible {
  outline: 2px solid var(--brand-accent);
  outline-offset: 1px;
}
.ai-intro__examples {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin: var(--space-md) 0;
}
.ai-example {
  min-height: 44px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--graphite-900);
  background: var(--surface-card);
  border: var(--hairline) solid var(--metal-400);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.ai-example:hover { border-color: var(--brand-accent); color: var(--brand-accent); }
.ai-example:active { background: rgba(47, 111, 94, 0.08); }
.ai-example:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; }
.ai-intro__start {
  min-height: 52px;
  padding-inline: var(--space-xl);
  font-size: 1.0625rem;
}

/* Benefits — compact row of what the customer receives. */
.ai-intro__benefits {
  margin-top: var(--space-lg);
}
.ai-intro__benefits-title {
  margin: 0 0 var(--space-sm);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand-accent);
}
.ai-intro__benefits-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-md);
}
.ai-intro__benefit {
  padding-top: var(--space-sm);
  border-top: 2px solid var(--metal-300);
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--graphite-900);
}
.ai-intro__trust,
.ai-shell__trust {
  margin: var(--space-lg) auto 0;
  max-width: 880px;
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--graphite-700);
}

/* Soft start -> active transition. */
.ai-workspace[data-entering] {
  animation: ai-enter 0.22s ease both;
}
@keyframes ai-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---- Workspace: dialog + live summary ---- */
/* The `hidden` attribute must win over the display rules below, otherwise the
   empty dialog/summary panels show on the start screen (the whole point of
   this sprint). Attribute-qualified selectors beat the plain class rules. */
.ai-intro[hidden],
.ai-workspace[hidden] {
  display: none;
}

.ai-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--space-lg);
  align-items: start;
}

.ai-dialog {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-card);
  border: var(--hairline) solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.ai-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: var(--hairline) solid var(--border-hairline);
}
.ai-dialog__title {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand-accent);
}
.ai-linkbtn {
  min-height: 44px;
  padding: 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand-accent);
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.ai-linkbtn:hover { text-decoration: underline; }
.ai-linkbtn:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; }
/* Restart is a quiet secondary action in the header — never louder than the
   main flow. Muted until hovered/focused. */
.ai-dialog__head .ai-linkbtn {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--graphite-700);
}
.ai-dialog__head .ai-linkbtn:hover { color: var(--brand-accent); }

.ai-log {
  padding: var(--space-md) var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  /* No fixed height or inner scrollbar on a normal screen: the dialog grows
     with the conversation and the whole page scrolls as one column. A capped,
     scrollable log is a fallback only on very short viewports (see the
     max-height media query at the end of this file). */
}
.ai-msg { display: flex; flex-direction: column; gap: 4px; max-width: 90%; }
.ai-msg--user { align-self: flex-end; align-items: flex-end; }
.ai-msg__who {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--graphite-700);
}
/* The assistant speaks as plain, readable copy — no frame around it. The
   customer's own answers get a light cold-green field so the two voices read
   differently without turning into loud messenger bubbles. */
.ai-msg__bubble {
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--graphite-950);
  white-space: pre-wrap;
}
.ai-msg--user .ai-msg__bubble {
  padding: var(--space-2xs) var(--space-md);
  background: rgba(47, 111, 94, 0.08);
  border-radius: var(--radius-md);
}
.ai-msg--in { animation: ai-fade 0.18s ease both; }
@keyframes ai-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Light "analysing" indicator while the advisor is queried. */
.ai-typing {
  align-self: flex-start;
  padding: var(--space-2xs) var(--space-md);
  font-size: 0.9rem;
  font-style: italic;
  color: var(--graphite-700);
  background: var(--warm-white-50);
  border: var(--hairline) solid var(--border-hairline);
  border-radius: var(--radius-md);
}

.ai-input {
  padding: var(--space-md);
  border-top: var(--hairline) solid var(--border-hairline);
  /* Set the compose zone subtly apart so the input reads as the tool's
     answer area, not a stray contact field. */
  background: var(--warm-white-50);
}
.ai-answer__input {
  width: 100%;
  min-height: 64px;
  padding: var(--space-sm) var(--space-md);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--graphite-950);
  background: var(--surface-card);
  border: 1.5px solid var(--metal-300);
  border-radius: var(--radius-md);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ai-answer__input:hover { border-color: var(--metal-400); }
.ai-answer__input:focus-visible {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 94, 0.15);
}
.ai-answer__row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-2xs);
}
.ai-options { display: flex; flex-wrap: wrap; gap: var(--space-2xs); }
.ai-option {
  min-height: 44px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--graphite-950);
  background: var(--surface-card);
  border: var(--hairline) solid var(--metal-300);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.ai-option:hover { border-color: var(--brand-accent); color: var(--brand-accent); }
.ai-option:focus-visible { outline: 2px solid var(--brand-accent); outline-offset: 2px; }
.ai-options__idk, .ai-answer__idk { align-self: center; }

/* ---- Recommendation ---- */
.ai-rec {
  padding: var(--space-md);
  background: var(--warm-white-50);
  border: var(--hairline) solid var(--metal-300);
  border-radius: var(--radius-md);
}
.ai-rec__head { display: flex; gap: var(--space-md); align-items: center; margin-bottom: var(--space-sm); }
.ai-rec__media { flex: 0 0 40%; max-width: 220px; border-radius: var(--radius-md); overflow: hidden; border: var(--hairline) solid var(--border-hairline); }
.ai-rec__media img { display: block; width: 100%; height: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.ai-rec__name { margin: 0; font-size: 1.25rem; line-height: 1.2; color: var(--graphite-950); }
.ai-rec__cat { margin: 2px 0 0; font-size: 0.9rem; color: var(--graphite-700); }
.ai-rec__confidence {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  margin: 0 0 var(--space-md);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--graphite-900);
}
.ai-rec__dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--brand-accent); }
.ai-rec__confidence--high .ai-rec__dot { background: var(--brand-accent); }
.ai-rec__confidence--medium .ai-rec__dot { background: transparent; }
.ai-rec__confidence--manager_required .ai-rec__dot { border-color: var(--metal-400); background: transparent; }
.ai-rec__block { margin-top: var(--space-sm); }
.ai-rec__blocktitle {
  margin: 0 0 var(--space-3xs);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-accent);
}
.ai-rec__list { margin: 0; padding-left: 1.1rem; }
.ai-rec__list li { font-size: 0.95rem; line-height: 1.5; color: var(--graphite-900); margin-bottom: 2px; }
.ai-rec__view { display: inline-block; margin-top: var(--space-sm); }

/* ---- Lead form ---- */
.ai-lead {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--surface-card);
  border: var(--hairline) solid var(--metal-300);
  border-radius: var(--radius-md);
}
.ai-lead__title { margin: 0 0 var(--space-3xs); font-size: 1.125rem; }
.ai-lead__intro { margin: 0 0 var(--space-sm); font-size: 0.95rem; color: var(--graphite-700); }

/* ---- Live summary ---- */
.ai-summary {
  position: sticky;
  top: calc(var(--mobile-header-height) + var(--space-md));
  padding: var(--space-md);
  background: var(--surface-card);
  border: var(--hairline) solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.ai-summary__toggle {
  width: 100%;
  text-align: left;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1875rem;
  line-height: 1.2;
  color: var(--graphite-950);
  background: none;
  border: 0;
  padding: 0 0 var(--space-sm);
  border-bottom: 2px solid var(--metal-300);
  cursor: default;
}
.ai-summary__list { margin: var(--space-md) 0 0; }
.ai-summary__row { padding: var(--space-xs) 0; border-top: var(--hairline) solid var(--border-hairline); }
.ai-summary__row:first-child { border-top: 0; padding-top: 0; }
.ai-summary__row dt { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--graphite-700); }
/* Value is the signal — make it read stronger than its label. */
.ai-summary__row dd { margin: 3px 0 0; font-size: 1rem; font-weight: 600; color: var(--graphite-950); }
.ai-summary__state {
  font-size: var(--text-xs);
  font-weight: 400;
  margin-left: 0.4rem;
  color: var(--graphite-700);
  white-space: nowrap;
}
.ai-summary__state--user { color: var(--brand-accent); }
.ai-summary__missing { margin-top: var(--space-sm); padding-top: var(--space-sm); border-top: var(--hairline) solid var(--border-hairline); }
.ai-summary__missingtitle { margin: 0 0 var(--space-3xs); font-size: var(--text-sm); font-weight: 700; color: var(--graphite-900); }
.ai-summary__missing ul { margin: 0; padding-left: 1.1rem; }
.ai-summary__missing li { font-size: 0.9rem; color: var(--graphite-700); }

/* ---- Tablet / mobile ---- */
@media (max-width: 1023px) {
  .ai-workspace { grid-template-columns: 1fr; }
  .ai-summary { position: static; order: 2; }
  .ai-intro__benefits-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  .ai-shell { padding-block: var(--space-md) var(--space-xl); }
  .ai-intro__title { font-size: clamp(1.75rem, 7vw, 2.25rem); }
  .ai-intro__box { padding: var(--space-md); }
  .ai-intro__input { min-height: 120px; }
  .ai-intro__start { width: 100%; justify-content: center; }
  .ai-intro__benefits-list { grid-template-columns: 1fr; gap: var(--space-sm); }
  .ai-msg { max-width: 100%; }
  /* When a new question / recommendation is scrolled into view on mobile it is
     top-aligned; this margin keeps it clear of the fixed site header (same
     header offset the rest of the site uses for anchor targets). */
  .ai-msg,
  .ai-rec { scroll-margin-top: calc(var(--mobile-header-height) + 16px); }
  .ai-answer__row { flex-wrap: wrap; }
  .ai-answer__send { flex: 1 1 auto; min-height: 44px; justify-content: center; }
  .ai-rec__head { flex-direction: column; align-items: stretch; }
  .ai-rec__media { flex: none; max-width: none; }
  /* Collapsible summary on phones */
  .ai-summary__toggle { cursor: pointer; position: relative; min-height: 44px; padding-right: 1.5rem; }
  .ai-summary__toggle::after { content: "▾"; position: absolute; right: 0; top: 0; color: var(--brand-accent); }
  .ai-summary--collapsed .ai-summary__body { display: none; }
  .ai-summary--collapsed .ai-summary__toggle::after { content: "▸"; }
}

/* Fallback ONLY for very short viewports (e.g. a landscape phone): cap the log
   so the compose field and its buttons stay reachable. This is not the desktop
   behaviour — on a normal screen the whole page scrolls as one column. */
@media (max-height: 560px) {
  .ai-log { max-height: 62vh; overflow-y: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-msg--in,
  .ai-workspace[data-entering] { animation: none; }
}
