/* The chat window in the corner of every page, opened by the page's own buttons: a terminal-like window of 800 x 480
   when open, only its bar when minimized, a full-height panel on the right when maximized. Labels in JetBrains Mono,
   text in Hanken Grotesk, colours from the tokens of site.css. assets/chat.js builds the markup and sets data-view on
   the root. */
:root {
  /* How far the window keeps from the edges of the screen. */
  --chat-edge: 16px;
  --chat-mono: var(--f-mono);
}
.chat-root {
  /* One width for the open window, its bar and the side panel; on a narrow screen it keeps 16 px from both edges.
     A percentage, not 100vw: a fixed box resolves it against the viewport without the scrollbar. */
  --chat-w: min(800px, 100% - 2 * var(--chat-edge));
}

/* The button beside Contact in the bar: the pill of Contact, outlined in brass, with the dot of the window's bar, as a
   tag. Its line is as tall as the line of Contact (.88rem × 1.2), so the two pills are of one height. */
.btn--chat {
  background: transparent; color: var(--brass-hi); border-color: var(--brass);
  font: 500 .74rem/1.43 var(--chat-mono); letter-spacing: .12em; text-transform: uppercase;
}
.btn--chat::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 8px var(--brass); }
.btn--chat:hover { background: color-mix(in srgb, var(--brass) 12%, transparent); border-color: var(--brass-hi); }
/* JetBrains Mono has no Arabic letters, and its spaces, as wide as a letter, would pull Arabic words apart: on an
   Arabic page the button takes the page's Arabic typeface. The window itself speaks English there. */
.btn--chat:lang(ar) { font-family: "IBM Plex Sans Arabic", var(--chat-mono); }
/* A narrower bar has no room for it beside Contact in every language (the German label needs 632 px). There the window
   opens only from the hero's first button of the landing pages. */
@media (max-width: 680px) { .btn--chat { display: none; } }

/* ---------- The window ---------- */
.chat {
  position: fixed; z-index: 50; inset-inline-end: var(--chat-edge); bottom: var(--chat-edge);
  width: var(--chat-w); height: 480px; max-height: calc(100% - 2 * var(--chat-edge));
  display: flex; flex-direction: column;
  background: var(--hull); color: var(--bone); font-family: var(--f-sans);
  border: 1px solid var(--rule); border-top: 2px solid var(--brass);
  box-shadow: 0 24px 60px rgb(0 0 0 / .55);
}
.chat-root[data-view="minimized"] .chat { bottom: 0; height: auto; border-bottom: 0; box-shadow: 0 -8px 30px rgb(0 0 0 / .45); }
.chat-root[data-view="maximized"] .chat {
  top: 0; inset-inline-end: 0; bottom: 0; height: auto; max-height: none;
  border-inline-end: 0; border-bottom: 0; box-shadow: -14px 0 40px rgb(0 0 0 / .5);
}

/* The bar: status on the right, as in the approved mockup, then the three controls. */
.chat__bar {
  flex: none; display: flex; align-items: center; justify-content: flex-end; gap: .6rem;
  padding: .7rem 1.2rem; border-bottom: 1px solid var(--rule);
  font: 500 .72rem/1 var(--chat-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mist);
}
.chat-root[data-view="minimized"] .chat__bar { border-bottom: 0; padding-bottom: calc(.7rem + env(safe-area-inset-bottom, 0px)); cursor: pointer; }
.chat__status { display: flex; align-items: center; gap: .55rem; min-width: 0; margin: 0; white-space: nowrap; }
.chat__status b { font-weight: 500; color: var(--bone); }
.chat__dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 8px var(--brass); }
.chat__clock { font-variant-numeric: tabular-nums; }
.chat__controls { flex: none; display: flex; gap: .55rem; }
.chat__ctl {
  width: 26px; height: 26px; display: grid; place-items: center; padding: 0;
  border: 1px solid var(--rule); border-radius: 0; background: transparent; color: var(--mist);
  font: 500 .85rem/1 var(--chat-mono); cursor: pointer;
  transition: color .2s ease, border-color .2s ease;
}
.chat__ctl:hover { color: var(--bone); border-color: var(--rule-strong); }
.chat__ctl:focus-visible { outline-offset: 2px; }

/* The conversation above, the box to write in below. */
.chat__body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat__log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 1.4rem 1.2rem; }
.chat__who { margin: 0 0 .8rem; font: 500 .74rem/1 var(--chat-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--brass); }
.chat__num { color: var(--mist); }
/* Plain text: blank lines in a message make its paragraphs, a single line break stays a line break. A paragraph
   written right to left (chat.js gives each the direction of its text) stands against the edge it starts from. */
.chat__text { max-width: 34em; margin: 0; margin-inline-end: auto; font-size: 1.05rem; line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; }
.chat__text + .chat__text { margin-top: .8rem; }
.chat__starters { margin-top: 1.4rem; }
.chat__label { margin: 0 0 .7rem; font: 500 .68rem/1 var(--chat-mono); letter-spacing: .16em; text-transform: uppercase; color: var(--mist); }
.chat__chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chat__chip {
  padding: .6rem .9rem; border: 1px solid var(--rule-strong); border-radius: 0;
  background: color-mix(in srgb, var(--bone) 2%, transparent); color: var(--bone);
  font: inherit; font-size: .9rem; line-height: 1.3; text-align: start; cursor: pointer;
  transition: border-color .2s ease, color .2s ease;
}
.chat__chip:hover { border-color: var(--brass); color: var(--brass-hi); }
.chat__chip:focus-visible { outline-offset: 2px; }
.chat__entries > * { margin-top: 1.4rem; }
/* The visitor's messages sit on the right, filled and with the brass edge of the box they were written in, so they
   read apart from the examples, which are outlined only. */
.chat__entry--visitor {
  width: fit-content; max-width: min(34em, 85%); margin-inline-start: auto; padding: .7rem .9rem;
  border: 1px solid var(--rule); border-inline-end: 2px solid var(--brass); background: var(--hull-2);
}
.chat__entry--visitor .chat__text { font-size: 1rem; }
/* A fixed text of the window: why it did not answer, or why the conversation takes no more messages, with what the
   visitor can do next. */
.chat__notice {
  max-width: 40em; padding: .85rem 1rem; border-inline-start: 2px solid var(--brass);
  background: color-mix(in srgb, var(--brass) 6%, transparent);
}
.chat__notice .chat__text { font-size: .95rem; line-height: 1.55; }
.chat__notice--error { border-inline-start-color: var(--alert); background: color-mix(in srgb, var(--alert) 6%, transparent); }
.chat__action {
  display: inline-flex; align-items: center; gap: .5rem; margin-top: .75rem; padding: .6rem .85rem;
  border: 1px solid color-mix(in srgb, var(--brass) 45%, transparent); border-radius: 0; background: transparent;
  color: var(--brass); font: 500 .7rem/1 var(--chat-mono); letter-spacing: .16em; text-transform: uppercase;
  text-decoration: none; cursor: pointer; transition: color .2s ease, border-color .2s ease;
}
.chat__action:hover { color: var(--brass-hi); border-color: var(--brass); }
.chat__action:focus-visible { outline-offset: 2px; }
.chat__action--solid { margin-top: 0; border-color: var(--brass); background: var(--brass); color: var(--abyss); }
.chat__action--solid:hover { border-color: var(--brass-hi); background: var(--brass-hi); color: var(--abyss); }
.chat__action[aria-disabled="true"] { opacity: .5; cursor: progress; }

/* ---------- The contact card and the offer of a call ---------- */
.chat__card {
  max-width: 34em; display: flex; flex-direction: column; gap: .85rem; padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--brass) 50%, transparent); background: color-mix(in srgb, var(--brass) 5%, transparent);
}
.chat__card .chat__who { margin: 0; }
.chat__field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem .6rem; }
.chat__field { display: grid; gap: .3rem; min-width: 0; }
.chat__field-label { font: 500 .62rem/1.2 var(--chat-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--mist); }
/* 16 px keeps iOS from zooming in when a field takes focus. */
.chat__field-input {
  width: 100%; min-width: 0; margin: 0; padding: .55rem .65rem; border: 1px solid var(--rule-strong); border-radius: 0;
  background: color-mix(in srgb, var(--bone) 4%, var(--abyss)); color: var(--bone); font: inherit; font-size: 1rem; line-height: 1.4;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.chat__field-input--area { resize: vertical; min-height: 4.6rem; }
.chat__field-input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brass) 28%, transparent); }
.chat__field-input[aria-invalid="true"] { border-color: var(--alert); }
.chat__field-err { margin: 0; font-size: .85rem; line-height: 1.4; color: var(--alert); }
.chat__field-err:empty { display: none; }
.chat__consent { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .6rem; align-items: start; font-size: .85rem; line-height: 1.4; color: var(--mist); cursor: pointer; }
.chat__consent input { width: 1.1rem; height: 1.1rem; margin: .1rem 0 0; accent-color: var(--brass); }
.chat__consent input[aria-invalid="true"] { outline: 2px solid var(--alert); outline-offset: 2px; }
/* The height of Google's checkbox is held from the start, so nothing below it moves when it is drawn. */
.chat__captcha { display: grid; gap: .4rem; }
.chat__captcha-slot { min-height: 78px; }
.chat__captcha[data-size="compact"] .chat__captcha-slot { min-height: 144px; }
.chat__card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; }
.chat__card-status { margin: 0; font-size: .88rem; line-height: 1.4; color: var(--mist); }
.chat__card-status:empty { display: none; }
.chat__card-status--error { color: var(--alert); }
.chat__offer .chat__who { margin: 0; }

/* ---------- The calendar ---------- */
/* In the maximized window it takes the place of the conversation and of the box to write in. */
.chat__calendar { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat__calendar-bar { flex: none; padding: .6rem 1.2rem; border-bottom: 1px solid var(--rule); }
.chat__back { margin-top: 0; }
.chat__frame { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--hull); }

/* While an answer is on its way: the label it will carry, pulsing. */
.chat__typing { margin: 1.4rem 0 0; animation: chat-pulse 1.1s ease-in-out infinite alternate; }
@keyframes chat-pulse { from { opacity: .4; } }

.chat__foot { flex: none; padding: 1rem 1.2rem calc(1rem + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--rule); }
.chat__form { display: flex; align-items: stretch; border: 1px solid color-mix(in srgb, var(--brass) 45%, transparent); transition: border-color .2s ease; }
.chat__form:focus-within { border-color: var(--brass); }
/* The box grows with the text where the browser can size it to its content, up to five lines. 16 px keeps iOS from
   zooming in when the box takes focus. */
.chat__input {
  flex: 1; min-width: 0; min-height: calc(1.5em + 1.9rem); max-height: calc(5 * 1.5em + 1.9rem); field-sizing: content;
  margin: 0; padding: .95rem 1rem; border: 0; border-radius: 0; background: transparent; color: var(--bone);
  font: inherit; font-size: 1rem; line-height: 1.5; resize: none;
}
.chat__input::placeholder { color: var(--mist); opacity: 1; }
.chat__input:focus { outline: none; }
.chat__input:disabled { cursor: not-allowed; }
.chat__send {
  flex: none; display: inline-flex; align-items: center; gap: .5rem; padding: 0 1rem;
  border: 0; border-radius: 0; background: transparent; color: var(--mist);
  font: 500 .7rem/1 var(--chat-mono); letter-spacing: .16em; text-transform: uppercase; cursor: pointer;
  transition: color .2s ease;
}
.chat__send:hover { color: var(--brass-hi); }
.chat__send:focus-visible { outline-offset: -4px; }
.chat__send:disabled { opacity: .5; cursor: not-allowed; }
/* Waiting for an answer: the button keeps its focus, so it is only marked, not switched off. */
.chat__send[aria-disabled="true"] { opacity: .5; cursor: progress; }
.chat__send[aria-disabled="true"]:hover { color: var(--mist); }

/* ---------- Between the states ---------- */
/* Set by the script once the visitor first changes the state, so a page that restores the window does not animate it. */
.chat-root[data-motion][data-view="open"] .chat { animation: chat-rise .24s var(--ease); }
.chat-root[data-motion][data-view="maximized"] .chat { animation: chat-slide .28s var(--ease); }
.chat-root[data-motion][data-view="minimized"] .chat { animation: chat-dock .22s var(--ease); }
@keyframes chat-rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes chat-slide { from { opacity: 0; transform: translateX(40px); } }
@keyframes chat-dock { from { transform: translateY(100%); } }

/* ---------- Phone ---------- */
/* The open window takes the whole screen, and there is nothing to maximize to. The bar of the minimized window spans
   the screen as the window does. */
@media (max-width: 640px) {
  .chat-root[data-view="open"] .chat, .chat-root[data-view="maximized"] .chat {
    inset: 0; width: auto; height: auto; max-height: none; border: 0; border-top: 2px solid var(--brass); box-shadow: none;
  }
  .chat-root[data-view="minimized"] .chat { right: 0; left: 0; width: auto; border-right: 0; border-left: 0; }
  .chat-root[data-view="open"] .chat__size, .chat-root[data-view="maximized"] .chat__size { display: none; }
  .chat__bar { padding-top: calc(.7rem + env(safe-area-inset-top, 0px)); padding-inline: calc(1rem + env(safe-area-inset-left, 0px)) calc(1rem + env(safe-area-inset-right, 0px)); }
  .chat-root[data-view="minimized"] .chat__bar { padding-top: .7rem; }
  .chat__log { padding: 1.2rem 1rem; }
  .chat__calendar-bar { padding-inline: 1rem; }
  .chat__foot { padding-inline: 1rem; }
}
@media (max-width: 360px) {
  .chat__field-row { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .chat-root .chat, .chat__typing { animation: none !important; }
  .chat__ctl, .chat__chip, .chat__form, .chat__send, .chat__action, .chat__field-input { transition: none; }
}
