/* ============================================================================
   RetailAssist AI — Application styles
   Base layout, chrome (header / nav / footer), and the reusable component
   library that every screen draws from. All values reference tokens.css.
   ========================================================================== */

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--athera-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  color: var(--athera-charcoal);
  background: var(--athera-off-white);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--athera-blue-deep);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--athera-navy);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
}
.skip-link:focus {
  left: 16px;
  top: 16px;
}

/* -------------------------------------------------------- Typography ------ */
.display-xl { font-family: var(--athera-display); font-size: var(--fs-display-xl); font-weight: var(--fw-light); line-height: 0.95; letter-spacing: -0.02em; }
.display-lg { font-family: var(--athera-display); font-size: var(--fs-display-lg); font-weight: var(--fw-light); line-height: var(--lh-tight); letter-spacing: var(--ls-display); }
.display-md { font-family: var(--athera-display); font-size: var(--fs-display-md); font-weight: var(--fw-regular); line-height: var(--lh-tight); letter-spacing: -0.01em; }
.display-sm { font-family: var(--athera-display); font-size: var(--fs-display-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); }

.body-lg { font-size: var(--fs-body-lg); font-weight: var(--fw-light); line-height: var(--lh-relaxed); color: var(--athera-charcoal-light); }
.body-sm { font-size: var(--fs-body-sm); line-height: 1.55; color: var(--athera-grey); }

.label {
  font-size: var(--fs-label);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--athera-grey);
}
.label--blue { color: var(--athera-blue-deep); }

.mono {
  font-family: var(--athera-mono);
  font-size: var(--fs-mono);
  font-weight: var(--fw-regular);
  color: var(--athera-grey);
}

.blue-rule {
  width: 48px;
  height: 1px;
  background: var(--athera-blue);
  border: 0;
  margin: var(--space-3) 0;
}

/* -------------------------------------------------------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(248, 247, 244, 0.92);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--athera-line);
}
.app-header__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  min-height: var(--header-height);
  padding: 0 var(--page-pad-x);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand__logo { width: 132px; height: auto; }
.brand__divider {
  width: 1px;
  height: 34px;
  background: var(--athera-line);
}
.brand__product { display: flex; flex-direction: column; line-height: 1.2; }
.brand__product-name {
  font-family: var(--athera-display);
  font-size: 19px;
  font-weight: var(--fw-medium);
  color: var(--athera-charcoal);
}
.brand__product-tag {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--athera-grey);
}

.app-nav {
  margin-left: auto;
}
.app-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: var(--space-1);
}
.app-nav__link {
  display: inline-block;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: var(--fw-regular);
  color: var(--athera-grey);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.app-nav__link:hover {
  color: var(--athera-charcoal);
  background: var(--state-neutral-tint);
  text-decoration: none;
}
.app-nav__link.is-active {
  color: var(--athera-charcoal);
  position: relative;
}
.app-nav__link.is-active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--athera-blue);
}

.app-nav__toggle {
  display: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.app-nav__toggle span {
  display: block;
  height: 1.5px;
  background: var(--athera-charcoal);
  margin: 0 auto;
  width: 18px;
}

/* -------------------------------------------------------- View root ------- */
.view-root {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-7) var(--page-pad-x) var(--space-8);
}
.view-root:focus {
  outline: none;
}

/* View section building blocks (used across screens) */
.section-head {
  max-width: var(--content-max);
  margin-bottom: var(--space-5);
}
.section-head .label {
  display: block;
  margin-bottom: var(--space-2);
}
.section-head__title {
  margin: 0;
}
.section-head__intro {
  margin: var(--space-3) 0 0;
  max-width: 560px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-2);
}
.eyebrow .num { font-family: var(--athera-mono); font-size: 11px; color: var(--athera-grey-light); }

/* -------------------------------------------------------- Footer ---------- */
.app-footer {
  flex-shrink: 0;
  background: var(--athera-navy);
  color: rgba(255, 255, 255, 0.75);
  margin-top: var(--space-8);
}
.app-footer__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-5) var(--page-pad-x);
  display: grid;
  gap: var(--space-3);
}
.app-footer__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-footer__emblem { width: 26px; height: 26px; }
.app-footer__firm {
  font-family: var(--athera-display);
  font-size: 18px;
  font-weight: var(--fw-light);
  color: #fff;
  letter-spacing: -0.01em;
}
.app-footer__disclaimer {
  margin: 0;
  max-width: 640px;
  font-size: 13px;
  font-weight: var(--fw-light);
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.6);
}
.app-footer__meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--athera-line-dark);
  padding-top: var(--space-3);
}
.app-footer__meta .mono { color: rgba(255, 255, 255, 0.45); }
.app-footer__meta [aria-hidden] { color: rgba(255, 255, 255, 0.25); }

/* ============================================================================
   REUSABLE COMPONENTS — every screen composes from these.
   ========================================================================== */

/* --------------------------------------------------------- Buttons -------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 26px;
  font-family: var(--athera-sans);
  font-size: 12px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--athera-blue);
  color: var(--athera-navy);
}
.btn--primary:hover { background: var(--athera-blue-deep); color: #fff; }

.btn--secondary {
  background: transparent;
  color: var(--athera-charcoal);
  border-color: var(--athera-line);
}
.btn--secondary:hover { background: var(--athera-white); border-color: var(--athera-grey-light); }

.btn--ghost {
  background: transparent;
  color: var(--athera-blue-deep);
  padding: 10px 14px;
}
.btn--ghost:hover { background: var(--state-positive-tint); }

.btn--lg { padding: 16px 34px; font-size: 13px; }
.btn--block { width: 100%; }

.btn__spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

/* --------------------------------------------------------- Cards ---------- */
.card {
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.card--pad-lg { padding: var(--space-5); }
.card--dark {
  background: var(--athera-navy);
  color: rgba(255, 255, 255, 0.85);
  border-color: var(--athera-line-dark);
}
.card--flush { padding: 0; overflow: hidden; }

.card-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* --------------------------------------------------- Form controls -------- */
.form-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.field { display: flex; flex-direction: column; gap: 8px; }
.field--full { grid-column: 1 / -1; }

.field__label {
  font-size: var(--fs-label);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--athera-grey);
}
.field__hint {
  font-size: 12px;
  color: var(--athera-grey-light);
}
.field__optional {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--athera-grey-light);
  font-weight: var(--fw-regular);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--athera-sans);
  font-size: 15px;
  color: var(--athera-charcoal);
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  transition: var(--transition);
}
.input::placeholder,
.textarea::placeholder { color: var(--athera-grey-light); }
.input:hover,
.select:hover,
.textarea:hover { border-color: var(--athera-grey-light); }
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--athera-blue-deep);
  box-shadow: 0 0 0 3px var(--state-positive-tint);
}
.textarea { resize: vertical; min-height: 130px; line-height: 1.6; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236B7280' stroke-width='1.5' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* --------------------------------------------------------- Badges --------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-family: var(--athera-sans);
  font-size: 11px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
/* Confidence */
.badge--confidence-high { color: var(--state-positive); background: var(--state-positive-tint); }
.badge--confidence-medium { color: var(--state-caution); background: var(--state-caution-tint); }
.badge--confidence-low { color: var(--athera-grey); background: var(--state-neutral-tint); }
/* Escalation / review */
.badge--escalation { color: var(--state-critical); background: var(--state-critical-tint); }
.badge--review { color: var(--state-caution); background: var(--state-caution-tint); }
.badge--grounded { color: var(--state-positive); background: var(--state-positive-tint); }
/* Neutral / meta */
.badge--neutral { color: var(--athera-grey); background: var(--state-neutral-tint); border-color: var(--athera-line); }

/* --------------------------------------------------------- Tables --------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--athera-sans);
  font-size: 13px;
}
.table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 10px;
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label-tight);
  text-transform: uppercase;
  color: var(--athera-grey-light);
  border-bottom: 1px solid var(--athera-line);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  color: var(--athera-charcoal);
  border-bottom: 1px solid var(--athera-line-light);
  vertical-align: top;
}
.table tbody tr:nth-child(even) td { background: rgba(212, 223, 232, 0.14); }

/* --------------------------------------------------------- Callouts ------- */
.callout {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--athera-line);
  background: var(--athera-white);
}
.callout__bar {
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--athera-blue);
  flex-shrink: 0;
}
.callout__body { display: flex; flex-direction: column; gap: 4px; }
.callout__title {
  font-size: 12px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--athera-charcoal);
}
.callout__text { font-size: 14px; color: var(--athera-charcoal-light); margin: 0; line-height: 1.6; }
.callout--info .callout__bar { background: var(--athera-blue); }
.callout--caution .callout__bar { background: var(--state-caution); }
.callout--critical .callout__bar { background: var(--state-critical); }
.callout--muted {
  background: var(--athera-surface);
  border-color: transparent;
}
.callout--muted .callout__bar { background: var(--athera-grey-light); }

/* --------------------------------------------------------- Toasts --------- */
.toast-region {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: min(360px, calc(100vw - 48px));
}
.toast {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--athera-navy);
  color: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 3px solid var(--athera-blue);
  font-size: 13px;
  line-height: 1.5;
  animation: toast-in 0.25s ease;
}
.toast--error { border-left-color: var(--state-critical); }
.toast--success { border-left-color: var(--athera-blue); }
.toast__close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.toast__close:hover { color: #fff; }

/* --------------------------------------------------- Loading / spinner ---- */
.loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-3);
  text-align: center;
  color: var(--athera-grey);
}
.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--athera-line);
  border-top-color: var(--athera-blue);
  animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------- Empty state ---- */
.empty-state {
  max-width: var(--content-max);
  padding: var(--space-6) 0;
}
.empty-state__badge {
  display: inline-block;
  margin-bottom: var(--space-3);
}

/* --------------------------------------------------------- Utilities ------ */
.stack { display: flex; flex-direction: column; }
.stack-1 > * + * { margin-top: var(--space-1); }
.stack-2 > * + * { margin-top: var(--space-2); }
.stack-3 > * + * { margin-top: var(--space-3); }
.stack-4 > * + * { margin-top: var(--space-4); }
.stack-5 > * + * { margin-top: var(--space-5); }
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.muted { color: var(--athera-grey); }
.text-max { max-width: var(--content-max); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.is-hidden { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ============================================================================
   VIEW LAYOUTS — screen-specific composition on top of the component library.
   ========================================================================== */

/* --------------------------------------------------------- Home ----------- */
.home { display: grid; gap: var(--space-8); }
.home__intro { max-width: 720px; }
.home__headline { margin: var(--space-2) 0 0; color: var(--athera-charcoal); }
.home__lede { margin: 0; max-width: 620px; }
.home__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-5);
}
.home__note { margin: var(--space-4) 0 0; color: var(--athera-grey-light); }

.home__cap { display: flex; flex-direction: column; gap: 10px; }
.home__cap-num { color: var(--athera-grey-light); }
.home__cap-title { margin: 0; color: var(--athera-charcoal); }

.home__disclaimer { max-width: 620px; }

/* ============================================================================
   ASSISTANT — the chat surface.
   One centred column, full available height: a scrolling thread above a pinned
   composer. Restraint over decoration: user and assistant turns are told apart
   by alignment, a quiet surface tint, and a small label — no coloured bubbles,
   no tails, no shadows. The single A! Blue accent in view is the send button.
   ========================================================================== */

/* The chat owns the viewport: the page itself does not scroll, the thread does.
   The global footer is replaced by the disclaimer under the composer. */
body.is-chat { height: 100vh; height: 100dvh; overflow: hidden; }
body.is-chat .view-root {
  max-width: none;
  padding: 0;
  /* The base rule is `flex: 1 0 auto`, which refuses to shrink and would push
     the composer below the fold. The chat column must fit the viewport exactly. */
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.is-chat .app-footer { display: none; }

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--page-pad-x));
  margin: 0 auto;
  padding: 0 var(--page-pad-x);
}

/* --- Header (identity, actions, collapsible context) --------------------- */
.chat__header {
  flex-shrink: 0;
  padding: var(--space-4) 0 var(--space-3);
  border-bottom: 1px solid var(--athera-line);
}
.chat__header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.chat__title { margin: 6px 0 0; color: var(--athera-charcoal); }
.chat__header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn--sm { padding: 9px 16px; font-size: 11px; }

.chat__context { margin-top: var(--space-3); }
.chat__context-summary {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  cursor: pointer;
  list-style: none;
  padding: 6px 0;
}
.chat__context-summary::-webkit-details-marker { display: none; }
.chat__context-summary::after {
  content: "+";
  margin-left: auto;
  font-family: var(--athera-mono);
  font-size: 15px;
  color: var(--athera-grey-light);
}
.chat__context[open] .chat__context-summary::after { content: "\2212"; }
.chat__context-preview { color: var(--athera-grey-light); }
.chat__context-body {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  padding: var(--space-3) 0 var(--space-2);
}
.chat__context-note { grid-column: 1 / -1; margin: 0; }

/* --- Thread ------------------------------------------------------------- */
.chat__thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5) 0 var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.chat__thread:focus-visible { outline: var(--focus-ring); outline-offset: -2px; }

/* --- Empty state -------------------------------------------------------- */
.chat-empty { margin: auto 0; padding: var(--space-3) 0; }
.chat-empty__title { margin: var(--space-2) 0 0; color: var(--athera-charcoal); }
.chat-empty__lede { margin: var(--space-2) 0 0; max-width: 540px; font-size: var(--fs-body-lg); }
.chat-empty__starters { margin-top: var(--space-4); }
/* Two columns where there is room, so all four openers stay in view. */
.starter-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 8px;
  margin-top: var(--space-2);
}
.starter-chip {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--athera-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--athera-charcoal);
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}
.starter-chip:hover { border-color: var(--athera-grey-light); background: var(--athera-off-white); }

/* --- Messages ----------------------------------------------------------- */
.msg { display: flex; flex-direction: column; gap: 8px; }
.msg--user { align-items: flex-end; }
.msg__meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.msg--user .msg__meta { flex-direction: row-reverse; }
.msg__author { color: var(--athera-grey-light); }
.msg__badges { display: flex; gap: 6px; flex-wrap: wrap; }

.msg__body { min-width: 0; max-width: 100%; }
.msg--user .msg__body {
  max-width: 84%;
  padding: 14px 18px;
  background: var(--athera-surface);
  border-radius: var(--radius-md);
}
.msg--assistant .msg__body { width: 100%; }

.msg__text {
  margin: 0;
  font-size: var(--fs-body-lg);
  font-weight: var(--fw-light);
  line-height: var(--lh-relaxed);
  color: var(--athera-charcoal);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg--user .msg__text { font-size: var(--fs-body); font-weight: var(--fw-regular); }
.msg__attachments:not(:empty) { margin-top: var(--space-4); }
.msg__error:not(:empty) { margin-top: var(--space-3); }

/* System line — a simulated action recorded in the thread. */
.msg--system { align-items: center; }
.msg-system__text {
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  color: var(--athera-grey);
  background: var(--athera-surface);
  border-radius: var(--radius-pill);
}

/* A block of rich content inside an assistant message. */
.msg-block + .msg-block { margin-top: var(--space-4); }
.msg-block__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.msg-block__count { color: var(--athera-grey-light); }
.msg-block__note { margin: 10px 0 0; color: var(--athera-grey-light); }

/* Retry affordance on a dropped stream. */
.msg-retry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--athera-line);
  border-left: 3px solid var(--state-critical);
  border-radius: var(--radius-md);
  background: var(--athera-white);
}

/* Typing indicator — quiet, three dots, no bounce. */
.typing { display: inline-flex; gap: 5px; align-items: center; height: 28px; }
.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--athera-grey-light);
  animation: typing-fade 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-fade {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.9; }
}

/* --- Composer ----------------------------------------------------------- */
.chat__composer {
  flex-shrink: 0;
  padding: var(--space-3) 0 var(--space-3);
  border-top: 1px solid var(--athera-line);
  background: var(--athera-off-white);
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-lg);
  transition: var(--transition);
}
.composer:focus-within { border-color: var(--athera-blue-deep); }
.composer__input {
  flex: 1;
  min-height: 40px;
  max-height: 200px;
  padding: 9px 0;
  font-family: var(--athera-sans);
  font-size: var(--fs-body);
  line-height: 1.6;
  color: var(--athera-charcoal);
  background: transparent;
  border: 0;
  resize: none;
  overflow-y: auto;
}
.composer__input:focus { outline: none; }
.composer__input::placeholder { color: var(--athera-grey-light); }

.composer__send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--athera-navy);
  background: var(--athera-blue);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}
.composer__send:hover:not(:disabled) { background: var(--athera-blue-deep); color: #fff; }
.composer__send:disabled { opacity: 0.4; cursor: not-allowed; }

.composer__stop {
  flex-shrink: 0;
  height: 40px;
  padding: 0 16px;
  font-family: var(--athera-sans);
  font-size: 11px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--athera-charcoal);
  background: transparent;
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.composer__stop:hover { border-color: var(--athera-grey-light); }

.chat__disclaimer {
  margin: var(--space-2) 0 0;
  font-size: 12px;
  font-weight: var(--fw-light);
  line-height: 1.6;
  color: var(--athera-grey-light);
}

/* Keep toasts clear of the composer and the disclaimer beneath it. */
body.is-chat .toast-region { bottom: 150px; }

/* Escalation banner — visually distinct, on-brand (restrained warm red). */
.escalation-banner {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--state-critical-tint);
  border: 1px solid rgba(180, 85, 47, 0.28);
}
.escalation-banner__bar {
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--state-critical);
  flex-shrink: 0;
}
.escalation-banner__title {
  font-size: 12px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--state-critical);
}
.escalation-banner__text {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--athera-charcoal);
}

/* Stock chips (extend the badge component). */
.badge--stock-in { color: var(--state-positive); background: var(--state-positive-tint); }
.badge--stock-low { color: var(--state-caution); background: var(--state-caution-tint); }
.badge--stock-out { color: var(--state-critical); background: var(--state-critical-tint); }

/* Product cards */
.product-list {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.product-card { display: flex; flex-direction: column; }
.product-card__head { display: flex; gap: var(--space-3); align-items: flex-start; }
.product-card__thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--athera-surface);
  border-radius: var(--radius-md);
  color: var(--athera-blue-deep);
}
.product-card__thumb svg { width: 28px; height: 28px; }
.product-card__titles { min-width: 0; flex: 1; }
.product-card__brand { display: block; margin-bottom: 4px; }
.product-card__name {
  font-family: var(--athera-display);
  font-size: 20px;
  font-weight: var(--fw-regular);
  line-height: var(--lh-snug);
  color: var(--athera-charcoal);
  margin: 0;
}
.product-card__sub { margin-top: 2px; }

.product-price { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.product-price__eff {
  font-family: var(--athera-mono);
  font-size: 16px;
  font-weight: var(--fw-regular);
  color: var(--athera-charcoal);
}
.product-price__was {
  font-family: var(--athera-mono);
  font-size: 12px;
  color: var(--athera-grey-light);
  text-decoration: line-through;
}

.spec-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 20px; margin: 0; }
.spec-list dt { font-size: 12px; color: var(--athera-grey); }
.spec-list dd { margin: 0; font-family: var(--athera-mono); font-size: 12px; color: var(--athera-charcoal); text-align: right; }

.flag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-pill);
  font-size: 11px;
  color: var(--athera-grey);
  white-space: nowrap;
}
.flag svg { width: 12px; height: 12px; color: var(--athera-blue-deep); flex-shrink: 0; }
.product-card__why { margin: 0; font-size: 13px; line-height: 1.6; color: var(--athera-charcoal-light); }

/* Source citation (policy_reference) */
.source-cite {
  border: 1px solid var(--athera-line);
  border-left: 3px solid var(--athera-blue);
  border-radius: var(--radius-md);
  background: var(--athera-white);
  padding: var(--space-3);
}
.source-cite__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); margin-bottom: 8px; }
.source-cite__id { font-family: var(--athera-mono); font-size: 11px; color: var(--athera-blue-deep); }
.source-cite__quote { margin: 0; font-size: 14px; line-height: 1.65; color: var(--athera-charcoal-light); }
.source-cite__quote::before { content: "\201C"; }
.source-cite__quote::after { content: "\201D"; }

/* Next-best-action bar */
.action-bar { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Comparison table — figures render in DM Mono via .mono spans. */
.compare-table th:first-child,
.compare-table td:first-child {
  font-size: 10px;
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-label-tight);
  text-transform: uppercase;
  color: var(--athera-grey);
  white-space: nowrap;
}
.compare-table td .mono { color: var(--athera-charcoal); font-size: 12px; }
.compare-col-head { display: flex; flex-direction: column; gap: 2px; }
.compare-col-head .brand { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--athera-grey-light); }
.compare-summary { margin: var(--space-3) 0 0; }

/* --------------------------------------------------------- Service Brief -- */
.brief { max-width: 860px; }
.brief-doc { background: var(--athera-white); border: 1px solid var(--athera-line); border-radius: var(--radius-md); padding: var(--space-5); }
.brief-doc__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  border-bottom: 1px solid var(--athera-line);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-2);
}
.brief-doc__title { margin: 6px 0 0; }
.brief-doc__stamp { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.brief-row {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--athera-line-light);
}
.brief-row:last-child { border-bottom: 0; }
.brief-row__label { padding-top: 2px; }
.brief-row__value { font-size: 14px; line-height: 1.65; color: var(--athera-charcoal); }
.brief-row__value .mono { color: var(--athera-charcoal); }
.brief__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-4); }
.brief__note { margin: 0; color: var(--athera-grey-light); }
.brief-doc__footer { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--athera-line); }

/* ============================================================================
   KNOWLEDGE BASE (Screen 3) — tabs, filters, product/policy/branch/order views.
   ========================================================================== */
.kb__demo-note { margin-bottom: var(--space-4); max-width: 720px; }

/* Tabs */
.kb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 1px solid var(--athera-line);
  margin-bottom: var(--space-4);
}
.kb-tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 12px 18px;
  font-family: var(--athera-sans);
  font-size: 13px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  color: var(--athera-grey);
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.kb-tab:hover { color: var(--athera-charcoal); }
.kb-tab.is-active { color: var(--athera-charcoal); border-bottom-color: var(--athera-blue); }
.kb-tab__count { font-family: var(--athera-mono); font-size: 10px; color: var(--athera-grey-light); }

/* Toolbar (filters + search + view toggle) */
.kb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.kb-toolbar .field { min-width: 150px; flex: 1 1 auto; }
.kb-toolbar .field--search { flex: 2 1 260px; }
.kb-toolbar__spacer { flex: 1 1 auto; }
.kb-toolbar__result { font-family: var(--athera-mono); font-size: 11px; color: var(--athera-grey-light); white-space: nowrap; align-self: center; }

.view-toggle { display: inline-flex; border: 1px solid var(--athera-line); border-radius: var(--radius-md); overflow: hidden; }
.view-toggle button {
  appearance: none; background: var(--athera-white); border: 0;
  padding: 9px 14px; font-family: var(--athera-sans); font-size: 11px;
  font-weight: var(--fw-medium); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--athera-grey); cursor: pointer; transition: var(--transition);
}
.view-toggle button + button { border-left: 1px solid var(--athera-line); }
.view-toggle button.is-active { background: var(--athera-blue); color: var(--athera-navy); }

/* Policy accordion */
.policy-list { display: grid; gap: var(--space-2); }
.policy-item { border: 1px solid var(--athera-line); border-left: 3px solid var(--athera-blue); border-radius: var(--radius-md); background: var(--athera-white); }
.policy-item > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-3);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.policy-item > summary::-webkit-details-marker { display: none; }
.policy-item > summary::after {
  content: "+"; margin-left: auto; font-family: var(--athera-mono);
  color: var(--athera-grey-light); font-size: 18px; line-height: 1;
}
.policy-item[open] > summary::after { content: "\2212"; }
.policy-item__type { font-family: var(--athera-display); font-size: 20px; color: var(--athera-charcoal); }
.policy-item__id { font-family: var(--athera-mono); font-size: 11px; color: var(--athera-blue-deep); }
.policy-body { padding: 0 var(--space-3) var(--space-3); }
.policy-body__summary { margin: 0 0 var(--space-3); font-size: 14px; line-height: 1.65; color: var(--athera-charcoal-light); }
.policy-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.policy-grid h4 { margin: 0 0 8px; font-size: 10px; font-weight: var(--fw-medium); letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--athera-grey); }
.policy-grid ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.policy-grid li { font-size: 13px; line-height: 1.5; color: var(--athera-charcoal); }
.policy-foot { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--athera-line-light); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
.policy-foot .mono { color: var(--athera-grey); }

/* Branch cards */
.branch-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.branch-card__city { font-family: var(--athera-mono); font-size: 11px; color: var(--athera-blue-deep); }
.branch-card__name { font-family: var(--athera-display); font-size: 22px; font-weight: var(--fw-regular); color: var(--athera-charcoal); margin: 4px 0 var(--space-2); line-height: var(--lh-snug); }
.channel-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* Order sample table cells */
.kb-order-items { display: grid; gap: 2px; }
.kb-order-items span { font-size: 12px; color: var(--athera-charcoal-light); }

.kb-empty { padding: var(--space-6) 0; text-align: center; color: var(--athera-grey); }

/* ============================================================================
   INSIGHTS DASHBOARD (Screen 6) — KPI tiles + brand-themed charts.
   ========================================================================== */
.insights__window { margin-bottom: var(--space-5); }

/* KPI tiles */
.kpi-grid {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: var(--space-6);
}
.kpi {
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kpi__label { display: block; }
.kpi__value {
  font-family: var(--athera-mono);
  font-size: 30px;
  font-weight: var(--fw-regular);
  color: var(--athera-charcoal);
  line-height: 1;
  letter-spacing: -0.01em;
}
.kpi__value .kpi__unit { font-size: 14px; color: var(--athera-grey); margin-left: 3px; }
.kpi__meta { font-size: 12px; color: var(--athera-grey-light); margin: 0; }
.kpi--accent { border-top: 2px solid var(--athera-blue); }

/* Chart grid + cards */
.chart-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chart-card {
  background: var(--athera-white);
  border: 1px solid var(--athera-line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chart-card--wide { grid-column: 1 / -1; }
.chart-card__head { margin-bottom: var(--space-3); }
.chart-card__title { font-family: var(--athera-display); font-size: 22px; font-weight: var(--fw-regular); color: var(--athera-charcoal); margin: 6px 0 0; line-height: var(--lh-snug); }
.chart-card__canvas {
  position: relative;
  height: 300px;
  width: 100%;
}
.chart-card--wide .chart-card__canvas { height: 320px; }
.chart-caption {
  margin: var(--space-3) 0 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--athera-line-light);
  font-size: 13px;
  line-height: 1.6;
  color: var(--athera-grey);
}
.chart-caption strong { color: var(--athera-charcoal); font-weight: var(--fw-medium); }

.insights__foot { margin-top: var(--space-6); }

@media (max-width: 760px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card__canvas { height: 260px; }
}

/* --------------------------------------------------------- Animations ----- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes view-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.view-enter { animation: view-fade 0.3s ease; }

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

/* --------------------------------------------------------- Print ---------- */
@media print {
  .app-header,
  .app-footer,
  .app-nav,
  .app-nav__toggle,
  .toast-region,
  .skip-link,
  .brief__actions,
  .brief__note { display: none !important; }
  body { background: #fff; color: #000; }
  .view-root { padding: 0; max-width: none; }
  .brief-doc { border: 0; padding: 0; }
  .brief-row { break-inside: avoid; }
}

/* --------------------------------------------------------- Responsive ----- */
@media (max-width: 900px) {
  .app-nav { display: none; }
  .app-nav.is-open {
    display: block;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--athera-off-white);
    border-bottom: 1px solid var(--athera-line);
    padding: var(--space-2) var(--page-pad-x);
  }
  .app-nav.is-open .app-nav__list { flex-direction: column; gap: 0; }
  .app-nav.is-open .app-nav__link { display: block; padding: 12px 8px; border-bottom: 1px solid var(--athera-line-light); }
  .app-nav.is-open .app-nav__link.is-active::after { display: none; }
  .app-nav.is-open .app-nav__link.is-active { color: var(--athera-blue-deep); }
  .app-nav__toggle { display: flex; }
  .brand__product-tag { display: none; }
}

@media (max-width: 640px) {
  .view-root { padding-top: var(--space-5); padding-bottom: var(--space-6); }
  .form-grid { grid-template-columns: 1fr; }
  .brand__divider, .brand__product { display: none; }
  .toast-region { right: 16px; left: 16px; bottom: 16px; max-width: none; }

  /* Chat on a phone: the thread keeps the full column, cards stack. */
  body.is-chat .view-root { padding-top: 0; padding-bottom: 0; }
  .chat__header { padding-top: var(--space-3); }
  .chat__header-actions { width: 100%; }
  .chat__thread { padding-top: var(--space-4); gap: var(--space-4); }
  .msg--user .msg__body { max-width: 92%; }
  .msg__text { font-size: var(--fs-body); }
  .product-list { grid-template-columns: 1fr; }
  .toast-region { bottom: 96px; }
}
