/*
 * public/styles.css
 *
 * Layout, type and spacing for the chat page. Phone first: the base rules are for
 * small screens, and one wider-screen block adds room on tablets and computers.
 *
 * Colours: this file uses ONLY the names defined in theme.css. It has no colour
 * values of its own. The only exceptions are the system colour names (CanvasText,
 * ButtonText, Highlight, GrayText) in the high-contrast block, which Windows requires there,
 * and "transparent" for invisible borders that become visible in high-contrast mode.
 *
 * Nothing is loaded from outside: no web fonts, no images, no @import.
 */

/* ===== Basics ===================================================== */

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

/* Anything marked "hidden" is always hidden, whatever display rule it also has. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--colour-page);
  color: var(--colour-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
}

h1,
p,
ol,
ul {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

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

/* Keyboard focus: a clear outline with a gap, so it never sits on a button's own colour. */
:focus-visible {
  outline: 3px solid var(--colour-focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.625rem 1rem;
  background: var(--colour-surface);
  color: var(--colour-text);
  border: 1px solid var(--colour-border-strong);
  border-radius: 4px;
}

.skip-link:focus {
  top: 1rem;
}

/* ===== Header and demo notice ===================================== */

.site-header {
  background: var(--colour-surface);
  border-bottom: 3px solid var(--colour-brand);
}

.site-header__inner,
.demo-notice__inner,
.main {
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

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

.brand__logo {
  flex: none;
  width: var(--brand-logo-width);
  height: var(--brand-logo-height);
  background: var(--brand-logo) center / contain no-repeat;
}

.brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand__name {
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere; /* a very long single word wraps instead of pushing the page wider */
}

/* Sign out keeps its full size and stays on one line; the company name wraps first. */
.site-header__inner > .button {
  flex: none;
  white-space: nowrap;
}

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

.demo-notice {
  background: var(--colour-demo-surface);
  border-bottom: 1px solid var(--colour-demo-edge);
}

.demo-notice__inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  padding-top: 0.625rem;
  padding-bottom: 0.625rem;
  font-size: 0.9375rem;
}

.demo-notice__label {
  font-weight: 600;
}

/* ===== Main area, panels and fields =============================== */

.main {
  flex: 1;
  padding-top: 1.25rem;
  padding-bottom: 1.5rem;
}

.loading {
  padding: 2rem 0;
  color: var(--colour-text-muted);
}

.panel {
  background: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: 6px;
  padding: 1.5rem 1.25rem;
}

.panel__title {
  margin-bottom: 0.5rem;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.3;
}

.panel__lead {
  margin-bottom: 1.25rem;
  color: var(--colour-text-muted);
}

.signin {
  max-width: 26rem;
  margin: 1rem auto 0;
}

.signin__form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field__label {
  font-size: 0.9375rem;
  font-weight: 600;
}

/* Text no smaller than 16px in boxes people type into, so phones do not zoom in. */
.field__input,
.composer__input {
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 0.75rem;
  font-size: max(1rem, 16px);
  line-height: 1.45;
  background: var(--colour-surface);
  color: var(--colour-text);
  border: 1px solid var(--colour-border-strong);
  border-radius: 4px;
}

.form-error {
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  color: var(--colour-error);
  background: var(--colour-error-surface);
  border-left: 4px solid var(--colour-error);
}

/* A calmer version for "please wait" messages: the same pale green and edge as the
   AI notice instead of red. app.js adds this class when a message is only asking the
   customer to wait. */
.form-error--calm {
  color: var(--colour-text);
  background: var(--colour-ai-notice-surface);
  border-left-color: var(--colour-ai-notice-edge);
}

/* The failure notice above the message box (made by app.js) holds paragraphs and a
   "Try again" button. A little space between them, and none above the first. Only
   this notice has paragraphs, so short messages inside the message box are unchanged. */
.form-error > p + * {
  margin-top: 0.5rem;
}

/* ===== Buttons ==================================================== */

/* At least 44 by 44 pixels, so they are easy to tap. */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.625rem 1.25rem;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}

.button--primary {
  background: var(--colour-brand);
  color: var(--colour-on-brand);
}

.button--primary:hover {
  background: var(--colour-brand-hover);
}

.button--quiet {
  background: transparent;
  color: var(--colour-brand);
  border-color: var(--colour-border);
}

.button--quiet:hover {
  border-color: var(--colour-brand);
}

/* Switched off: white, with grey text and a grey edge, so it clearly looks unavailable.
   The same for the green and the quiet button, and it does not change on hover. */
.button:disabled,
.button:disabled:hover {
  background: var(--colour-surface);
  color: var(--colour-text-muted);
  border-color: var(--colour-border-strong);
  cursor: not-allowed;
}

.signin__form .button {
  margin-top: 0.5rem;
}

/* ===== Chat ======================================================= */

.chat {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ai-notice {
  padding: 0.875rem 1rem;
  background: var(--colour-ai-notice-surface);
  border-left: 4px solid var(--colour-ai-notice-edge);
  border-radius: 0 6px 6px 0;
}

.ai-notice__headline {
  font-weight: 600;
}

.ai-notice__detail {
  margin-top: 0.25rem;
  font-size: 0.9375rem;
}

.privacy {
  background: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: 6px;
}

.privacy__summary {
  min-height: 44px;
  padding: 0.75rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.privacy__list {
  display: grid;
  gap: 0.375rem;
  padding: 0 1rem 1rem 2.25rem;
  font-size: 0.9375rem;
}

/* The conversation. Customer and assistant differ by label, side and edge, not only colour. */
.transcript {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 0;
  list-style: none;
}

.message {
  max-width: 90%;
  padding: 0.75rem 1rem;
  border-radius: 6px;
}

.message--assistant {
  align-self: flex-start;
  background: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-left: 4px solid var(--colour-brand);
}

.message--customer {
  align-self: flex-end;
  background: var(--colour-customer-surface);
  border: 1px solid var(--colour-border);
  border-right: 4px solid var(--colour-border-strong);
}

.message__author {
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--colour-text-muted);
}

.message__body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message__note {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--colour-text-muted);
  border-top: 1px solid var(--colour-border);
}

/* Waiting indicator: three quiet dots and words. */
.waiting {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.9375rem;
  color: var(--colour-text-muted);
}

.waiting__dots {
  display: inline-flex;
  gap: 4px;
}

.waiting__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--colour-text-muted);
  animation: waiting-pulse 1.4s ease-in-out infinite;
}

.waiting__dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.waiting__dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes waiting-pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }

  40% {
    opacity: 1;
  }
}

/* The message box stays at the bottom of the screen while the conversation scrolls,
   including above the phone keyboard, with room for the iPhone home bar.
   On phones it is kept compact: the label, a two-line box, then one row holding the
   hint, the character count and the Send button. Any error shows above that row. */
.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label label"
    "input input"
    "error error"
    "meta send";
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.375rem;
  margin: 0 -1rem -1.5rem; /* bottom: covers the page's bottom margin, so no empty strip shows */
  padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  background: var(--colour-page);
  border-top: 1px solid var(--colour-border);
}

.composer > .field__label {
  grid-area: label;
}

/* Exactly two lines of text tall on phones. */
.composer__input {
  grid-area: input;
  height: calc(2 * 1.45em + 1.25rem + 2px);
  min-height: 0;
  max-height: 30vh;
  resize: none;
}

.composer > .form-error {
  grid-area: error;
}

.composer__meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--colour-text-muted);
}

.composer__count {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* app.js adds this near the 1,000-character limit. */
.composer__count--near-limit {
  font-weight: 600;
  color: var(--colour-error);
}

.composer .button {
  grid-area: send;
  justify-self: end;
}

/* ===== Phones with little height (usually the keyboard is open) ====== */
/* Keeps the message box to about a third of what is visible: Send moves beside
   the two-line box, the count moves beside the label, and the hint is kept for
   screen readers but not shown (the privacy notice above says the same). */
@media (max-width: 47.99em) and (max-height: 32.5em) {
  .composer {
    grid-template-areas:
      "label count"
      "input send"
      "error error";
    align-items: end;
    row-gap: 0.25rem;
  }

  .composer__meta {
    display: contents;
  }

  .composer__count {
    grid-area: count;
    justify-self: end;
    font-size: 0.8125rem;
    color: var(--colour-text-muted);
  }

  .composer__hint {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .composer .button {
    align-self: end;
  }
}

/* ===== Wider screens ============================================== */

@media (min-width: 48em) {
  .main {
    padding-top: 2rem;
  }

  .panel {
    padding: 2rem;
  }

  .message {
    max-width: 80%;
  }

  /* On larger screens the message box keeps its roomier layout: a three-line box,
     the hint and count on their own row, and Send on the right underneath. */
  .composer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    margin: 0;
    padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom, 0px));
  }

  .composer__input {
    height: auto;
    min-height: 5.5rem;
    max-height: 40vh;
    resize: vertical;
  }

  .composer__meta {
    align-items: flex-start;
    gap: 1rem;
    line-height: inherit;
  }

  .composer .button {
    align-self: flex-end;
  }
}

/* ===== People who prefer less movement: dots stay still ============== */

@media (prefers-reduced-motion: reduce) {
  .waiting__dots span {
    animation: none;
    opacity: 1;
  }
}

/* ===== People who ask for more contrast ============================== */

@media (prefers-contrast: more) {
  .brand__service,
  .panel__lead,
  .message__author,
  .message__note,
  .composer__meta,
  .waiting,
  .loading {
    color: var(--colour-text);
  }

  .panel,
  .privacy,
  .message,
  .composer,
  .message__note {
    border-color: var(--colour-border-strong);
  }
}

/* ===== Windows high-contrast mode ==================================== */

@media (forced-colors: active) {
  .panel,
  .privacy,
  .ai-notice,
  .demo-notice,
  .message,
  .form-error {
    border: 1px solid CanvasText;
  }

  .button {
    border-color: ButtonText;
  }

  /* Switched-off buttons use the system's own "unavailable" colour. */
  .button:disabled,
  .button:disabled:hover {
    color: GrayText;
    border-color: GrayText;
  }

  :focus-visible {
    outline-color: Highlight;
  }

  .waiting__dots span {
    forced-color-adjust: none;
    background: CanvasText;
  }
}

/* ===== Printing: the conversation only, in plain colours ============= */

@media print {
  body {
    display: block;
    background: var(--colour-surface);
  }

  .skip-link,
  #sign-out,
  .signin,
  .loading,
  .waiting,
  .composer {
    display: none !important;
  }

  .main {
    max-width: none;
    padding: 0;
  }

  .message {
    max-width: 100%;
    break-inside: avoid;
  }

  .ai-notice,
  .demo-notice,
  .message,
  .message--customer {
    background: var(--colour-surface);
  }
}
