/*
 * Kitchen Helper web chat: the style.
 *
 * A calm, light page: deep royal blue for navigation and the main actions, a saturated
 * deep green for supporting actions and accents, pale blue surfaces on a light neutral
 * ground, and red for errors. The colours are tokens (the :root block); the text colours
 * on their grounds are all at least 4.5:1 and the edges of controls at least 3:1
 * (tests/test_web_ui_assets.py computes them from this file, so a changed token that
 * breaks a pair fails a test). System fonts only; nothing is loaded from anywhere else.
 * Touch targets are at least 44 x 44 CSS pixels.
 */

:root {
  color-scheme: light;

  --bg: #f4f7fc;
  --surface: #ffffff;
  --pale: #e8effb;
  --pale-strong: #d3e1f7;
  --line: #b9c9e4;
  --field-edge: #62748f;
  --text: #162033;
  --muted: #44546a;

  --blue: #1c3f94;
  --blue-dark: #142f73;
  --green: #0b6b39;
  --green-dark: #08522b;
  --green-pale: #e2f3e9;
  --red: #b3261e;
  --red-dark: #8f1d17;
  --red-pale: #fdeceb;
  --on-color: #ffffff;

  --radius: 0.75rem;
  --shadow: 0 1px 3px rgba(22, 32, 51, 0.12);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[hidden] {
  display: none !important;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
  line-height: 1.25;
}

p {
  margin: 0 0 0.75rem;
}

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

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

h1:focus {
  outline: none;
}

.topbar :focus-visible {
  outline-color: var(--on-color);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.lead {
  margin-bottom: 1.1rem;
  color: var(--muted);
}

/* --- buttons ------------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.55rem 1.1rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background: var(--blue);
  color: var(--on-color);
}

.btn-primary:hover {
  background: var(--blue-dark);
}

.btn-secondary {
  background: var(--green);
  color: var(--on-color);
}

.btn-secondary:hover {
  background: var(--green-dark);
}

.btn-quiet {
  background: var(--surface);
  border-color: var(--field-edge);
  color: var(--blue);
}

.btn-quiet:hover {
  background: var(--pale);
}

.btn-onblue {
  background: transparent;
  border-color: var(--on-color);
  color: var(--on-color);
}

.btn-onblue:hover {
  background: var(--blue-dark);
}

.btn[aria-disabled="true"],
.btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#new-conversation[aria-current="true"] {
  background: var(--green-dark);
}

/* --- the first screens: loading, unavailable, sign-in -------------------------------- */

.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-center {
  max-width: 28rem;
  margin: 0 auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

label {
  font-weight: 600;
}

input[type="email"],
textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--field-edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  display: block;
  flex: 1;
  max-height: 14rem;
  overflow-y: hidden;
  resize: none;
  line-height: 1.45;
}

textarea[readonly] {
  background: var(--pale);
}

textarea[aria-invalid="true"] {
  border-color: var(--red);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0;
  color: var(--muted);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.notice {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--pale-strong);
  border-radius: var(--radius);
  background: var(--pale);
}

.notice-error {
  border-color: var(--red);
  background: var(--red-pale);
  color: var(--red-dark);
}

.notice-ok {
  border-color: var(--green);
  background: var(--green-pale);
  color: var(--green-dark);
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  color: var(--muted);
}

.spinner {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  border: 3px solid var(--pale-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 4s;
  }

  .sidebar {
    transition: none !important;
  }
}

/* --- the application ------------------------------------------------------------------ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  background: var(--blue);
  color: var(--on-color);
}

.brand {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.burger {
  position: relative;
  display: inline-block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
}

.burger::before,
.burger::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
}

.burger::before {
  top: -6px;
}

.burger::after {
  top: 6px;
}

.workspace {
  display: grid;
  flex: 1;
  grid-template-columns: 19rem minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  padding: 1rem;
  overflow-y: auto;
  background: var(--pale);
  border-right: 1px solid var(--line);
}

.sidebar .hint {
  margin-top: 0.6rem;
}

.conv-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.conv-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  min-height: 3rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.conv-item:hover {
  background: var(--bg);
}

.conv-item[aria-current="true"] {
  border-color: var(--blue);
  box-shadow: inset 5px 0 0 var(--blue);
  font-weight: 600;
}

.conv-label {
  overflow-wrap: anywhere;
}

.conv-meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.backdrop {
  display: none;
}

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

.chat-title {
  margin: 0;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.05rem;
}

.banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--pale);
  border-bottom: 1px solid var(--pale-strong);
}

.banner p {
  flex: 1;
  margin: 0;
}

.banner-error {
  background: var(--red-pale);
  color: var(--red-dark);
  border-bottom-color: var(--red);
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 0;
  padding: 1rem;
  overflow-y: auto;
}

.empty {
  max-width: 34rem;
  margin: 1rem auto;
  text-align: center;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.chip {
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 2px solid var(--green);
  border-radius: 999px;
  background: var(--surface);
  color: var(--green-dark);
  font: inherit;
  cursor: pointer;
}

.chip:hover {
  background: var(--green-pale);
}

/* The button and its "loading" replacement are the same height, so the messages below do not jump
   when the person asks for older ones. */
.older {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
}

.older .loading {
  justify-content: center;
}

.msg {
  max-width: min(46rem, 94%);
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  overflow-wrap: anywhere;
}

.msg-user {
  align-self: flex-end;
  border-color: var(--pale-strong);
  border-bottom-right-radius: 0.3rem;
  background: var(--pale);
}

.msg-assistant {
  align-self: flex-start;
  border-left: 5px solid var(--green);
  border-bottom-left-radius: 0.3rem;
}

.msg-failed {
  border-color: var(--red);
}

.msg-text p {
  margin: 0 0 0.65em;
  white-space: pre-wrap;
}

.msg-text p:last-child {
  margin-bottom: 0;
}

.msg-meta {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.msg-note {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.msg-note-error {
  color: var(--red-dark);
  font-weight: 500;
}

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

/* --- the composer ---------------------------------------------------------------------- */

.composer {
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
}

.btn-send {
  flex: none;
  min-width: 7rem;
}

.field-error {
  margin: 0.5rem 0 0;
  color: var(--red-dark);
  font-weight: 500;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.35rem 0 0;
}

.counter-over {
  color: var(--red-dark);
  font-weight: 700;
}

/* --- narrow screens: the conversations are a drawer ---------------------------------------- */

.drawer-toggle {
  display: none;
}

@media (max-width: 52rem) {
  .drawer-toggle {
    display: inline-flex;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(88vw, 22rem);
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  .app[data-drawer="open"] .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(22, 32, 51, 0.5);
  }

  .brand {
    font-size: 1rem;
  }

  .btn-send {
    min-width: 5.5rem;
  }
}

@media (hover: none) {
  .hint-keys {
    display: none;
  }
}

@media (max-width: 26rem) {
  .btn {
    padding-right: 0.8rem;
    padding-left: 0.8rem;
  }

  .messages {
    padding: 0.75rem;
  }

  .msg {
    max-width: 100%;
  }
}
