/*
 * Jean the Komornik — app shell styles.
 *
 * Chat-only product: a single fixed-height app shell, full viewport height,
 * usable one-handed on a phone. #transcript is the only scrolling element;
 * everything else (header, chips, composer, footer) is a non-scrolling flex
 * row, matching the pre-redesign shell -- the Stitch export's own desktop
 * screen scrolls the whole page, but that model is incompatible with the
 * --kb/visualViewport keyboard-clearance machinery and the
 * overscroll-behavior: contain transcript this app already relies on, so
 * this redesign keeps the fixed-shell model and reflows the Stitch content
 * into it instead (see HANDOFF/differences_from_design).
 *
 * Design tokens below are read from the Stitch exports' own inline
 * `tailwind.config` (desktop.html/mobile.html/gatekeeper.html), which is what
 * the exports' screenshots actually render -- not from the accompanying
 * DESIGN.md, whose burgundy/ivory palette and font list do not match either
 * the config or the screenshots and is stale.
 */

:root {
  color-scheme: light dark;

  /* Type families: self-hosted, see ./assets/fonts/*.woff2 + LICENSES.md. */
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-sans:
    "Plus Jakarta Sans",
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;

  /* Colour tokens, named after the export's own Material-3-shaped config
     keys so a future re-export can be diffed key-for-key. */
  --color-bg: #f6f9ff;
  --color-surface-lowest: #ffffff;
  --color-surface-low: #ecf4fe;
  --color-surface: #e7eff8;
  --color-surface-high: #e1e9f2;
  --color-surface-highest: #dbe3ed;
  --color-text: #151c23;
  --color-text-muted: #4e4638;
  --color-outline: #7f7666;
  --color-outline-variant: #d1c5b3;
  --color-primary: #775a12;
  --color-on-primary: #ffffff;
  --color-primary-container: #c8a356;
  --color-secondary: #426278;
  --color-secondary-container-tint: rgb(66 98 120 / 12%);
  --color-success: #2e7d4f;
  --color-danger-bg: #ffdad6;
  --color-danger-border: #e8b0a9;
  --color-danger-text: #93000a;

  /* The export's own resting Send-button pairing (white on #c8a356) is
     2.38:1 -- fails WCAG AA (needs >= 4.5:1 for this text size). Dark ink
     (--color-text, #151c23) on the same gold is 7.22:1, comfortably AAA, so
     the fill colour ships unchanged and only the label ink changes. */
  --color-on-primary-container: var(--color-text);

  --radius-sm: 0.125rem;
  --radius-md: 0.25rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-pill: 999px;

  --space-xs: 0.375rem;
  --space-sm: 0.625rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2.5rem;

  /* Keyboard inset, maintained at runtime by app.js's visualViewport
     listener. 0px until that listener sets it. */
  --kb: 0px;
}

/* Registers --kb as a <length> so a malformed runtime value (e.g. NaNpx or a
   unitless number from a visualViewport calculation with no viewport) falls
   back to the initial value at computed-value time instead of making the
   whole `max()` in #composer-form's padding-block-end invalid (which would
   drop the safe-area/0.75rem clearance entirely — verified live: an
   unregistered --kb: oops zeroed padding-block-end and the composer sat
   under the home indicator). The --kb: 0px declaration above becomes
   redundant once this is registered, but is left in place as documentation. */
@property --kb {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14181d;
    --color-surface-lowest: #1b2027;
    --color-surface-low: #212832;
    --color-surface: #262e38;
    --color-surface-high: #2c343f;
    --color-surface-highest: #333c47;
    --color-text: #e9edf2;
    --color-text-muted: #b9c2cd;
    --color-outline: #9a917f;
    --color-outline-variant: #4d4534;
    --color-primary: #e9c171;
    --color-on-primary: #402d00;
    --color-primary-container: #5c4300;
    --color-secondary: #a9cbe5;
    --color-secondary-container-tint: rgb(169 203 229 / 14%);
    --color-success: #7fd6a0;
    --color-danger-bg: #3a1210;
    --color-danger-border: #6b3230;
    --color-danger-text: #ffb4a9;
    --color-on-primary-container: #ffdea1;
  }
}

@font-face {
  font-family: "Playfair Display";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/playfair-display-italic-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/playfair-display-italic-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/assets/fonts/playfair-display-400-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/assets/fonts/playfair-display-400-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "EB Garamond";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/assets/fonts/eb-garamond-400-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "EB Garamond";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/assets/fonts/eb-garamond-400-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("/assets/fonts/plus-jakarta-sans-500-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("/assets/fonts/plus-jakarta-sans-500-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute !important;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  margin: 0;
  /* dvh, not vh: iOS Safari's dynamic toolbar changes the viewport height
     as it collapses/expands, and vh does not track that. */
  block-size: 100dvh;
  overflow: clip;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
}

/* Centres the app shell and caps its width on a wide viewport; on a phone
   it simply fills the screen (100% is already narrower than the cap). */
#app {
  block-size: 100%;
  display: flex;
  justify-content: center;
}

#chat-shell {
  flex: 1 1 auto;
  inline-size: 100%;
  max-inline-size: 72rem;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------
 * Header
 * ------------------------------------------------------------------- */

#chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface-lowest);
  border-block-end: 1px solid var(--color-surface-high);
}

#brand {
  min-inline-size: 0;
}

#brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--color-primary);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-name-short {
  display: inline;
}

.brand-name-full {
  display: none;
}

#brand-subline {
  margin: 0;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

#guest-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  max-inline-size: 7rem;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--color-surface-low);
  border: 1px solid var(--color-surface-high);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#guest-pill-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

#notes-toggle span {
  white-space: nowrap;
}

#guest-pill[hidden] {
  display: none;
}

#notes-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-pill);
  background: var(--color-surface-low);
  border: 1px solid var(--color-surface-high);
  color: var(--color-primary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
}

#notes-toggle svg {
  inline-size: 15px;
  block-size: 15px;
}

#jean-header-portrait {
  inline-size: 2.25rem;
  block-size: 2.25rem;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--color-outline-variant);
}

/* Narrowest phones: the header has four competing elements (brand, guest
   pill, Notes toggle, portrait) in ~360-400px. The pill already truncates;
   past this point the Notes toggle also drops its text label (icon +
   aria-haspopup="dialog" already carries its purpose) so the brand name
   -- the one thing every other element in this row exists to support --
   keeps first claim on the remaining space. */
@media (max-width: 460px) {
  #notes-toggle span {
    display: none;
  }

  #notes-toggle {
    padding: 0.4rem;
  }

  #guest-pill {
    max-inline-size: 5rem;
  }
}

/* ---------------------------------------------------------------------
 * Layout: chat pane + guest notes
 * ------------------------------------------------------------------- */

#layout {
  flex: 1 1 auto;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
}

#chat-pane {
  flex: 1 1 auto;
  inline-size: 100%;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  container-type: inline-size;
  container-name: chat-pane;
}

/* ---------------------------------------------------------------------
 * Transcript
 * ------------------------------------------------------------------- */

#transcript {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  /* Model output is untrusted text and may contain a single long unbroken
     token (e.g. a URL); without this, overflow-x computes to `auto` (per
     the overflow shorthand's rule that a non-visible overflow-y forces
     overflow-x out of `visible`) and the transcript becomes horizontally
     scrollable, which the plan's page-scroll check does not catch because
     it only forbids scroll on the page, not inside the transcript. */
  overflow-wrap: anywhere;
  overflow-x: clip;
}

#transcript:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* Invite gate blocked state (personal-invite-links MVP) sets `hidden` on
   #transcript via app.js. #transcript's own `display: flex` above is
   author-origin and beats the UA `[hidden] { display: none }` rule
   regardless of source order (same gotcha as #error-toast's popover rule,
   further down) -- this attribute-qualified selector adds the specificity
   needed to actually hide it. */
#transcript[hidden] {
  display: none;
}

#session-divider {
  align-self: center;
  margin-block: var(--space-xs);
  padding: 0.2rem 0.9rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: center;
}

/* ---------------------------------------------------------------------
   Message bubbles and the jump-to-latest affordance (hooks for app.js).
   Class names are the contract; app.js adds/removes them. Long unbroken
   model output must wrap rather than widen the transcript.
   --------------------------------------------------------------------- */

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  max-inline-size: 100%;
}

.msg-row-user {
  flex-direction: row-reverse;
}

.msg-avatar {
  flex: 0 0 auto;
  inline-size: 2rem;
  block-size: 2rem;
  border-radius: 50%;
  object-fit: cover;
  margin-block-start: 1.1rem;
}

.msg-avatar-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-secondary-container-tint);
  color: var(--color-secondary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid var(--color-outline-variant);
}

.msg-col {
  min-inline-size: 0;
  max-inline-size: min(85%, 42rem);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.msg-row-user .msg-col {
  align-items: flex-end;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.7rem;
  padding-inline: 0.15rem;
}

.msg-name {
  font-weight: 600;
  color: var(--color-primary);
}

.msg-row-user .msg-name {
  color: var(--color-secondary);
}

.msg-time {
  color: var(--color-text-muted);
}

.msg {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--color-surface-lowest);
  border: 1px solid var(--color-surface-high);
  font-family: var(--font-serif);
  font-size: 0.95rem;
}

/* The two parties are told apart by colour, not only by side: Jean's bubble
   carries a gold leading edge, the guest's a blue-tinted fill and edge. On
   the dark palette both bubbles were the same near-black and read as one
   voice (owner feedback 2026-09-19). */
.msg-assistant {
  border-end-start-radius: var(--radius-sm);
  border-inline-start: 3px solid var(--color-primary);
}

.msg-user {
  border-end-end-radius: var(--radius-sm);
  background: var(--color-secondary-container-tint);
  border-color: var(--color-secondary);
  border-color: color-mix(in srgb, var(--color-secondary) 45%, transparent);
}

/* Tappable links (app.js's linkifyText) inside either party's bubble --
   existing colour tokens only, both palettes get this for free since the
   tokens themselves are redefined under prefers-color-scheme: dark.
   overflow-wrap:anywhere is inherited from .msg above, so a long pasted
   URL still wraps inside the bubble rather than forcing it wider. */
.msg a {
  color: var(--color-secondary);
  text-decoration: underline;
}

.msg a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.msg-incomplete::after {
  content: "\2026";
  opacity: 0.6;
}

/* "Writing" indicator: the streaming assistant bubble starts with empty
   text content (an empty string sets zero child nodes, so :empty matches)
   and loses the match the instant the first delta lands -- no extra class
   toggling needed either way. */
.msg-assistant:empty {
  inline-size: 3.25rem;
  block-size: 1.6rem;
  padding-block: 0.5rem;
  display: flex;
  align-items: center;
}

.msg-assistant:empty::before {
  content: "";
  display: inline-block;
  inline-size: 6px;
  block-size: 6px;
  margin-inline-start: 2px;
  border-radius: 50%;
  background: currentColor;
  color: var(--color-text-muted);
  box-shadow:
    12px 0 currentColor,
    24px 0 currentColor;
  animation: jean-writing-dots 1.1s ease-in-out infinite;
}

@keyframes jean-writing-dots {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg-assistant:empty::before {
    animation: none;
    opacity: 0.55;
  }
}

#jump-to-latest {
  position: sticky;
  inset-block-end: 0.5rem;
  align-self: center;
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-surface-high);
  background: var(--color-surface-lowest);
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
}

#jump-to-latest[hidden] {
  display: none;
}

@container chat-pane (inline-size < 420px) {
  .msg-col {
    max-inline-size: 92%;
  }
}

/* ---------------------------------------------------------------------
 * Quick inquiries
 * ------------------------------------------------------------------- */

#quick-inquiries {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: 0 var(--space-md);
}

#quick-inquiries[hidden] {
  display: none;
}

#quick-inquiries-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

#quick-inquiries-list {
  display: flex;
  gap: var(--space-xs);
  overflow-x: auto;
  padding-block-end: 0.2rem;
  scrollbar-width: thin;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-surface-high);
  background: var(--color-surface-lowest);
  color: var(--color-text);
  font: inherit;
  font-size: 0.78rem;
  white-space: nowrap;
}

.chip svg {
  inline-size: 15px;
  block-size: 15px;
  color: var(--color-primary);
  flex: 0 0 auto;
}

.chip:disabled {
  opacity: 0.5;
}

.chip:focus-visible,
#notes-toggle:focus-visible,
#jean-header-portrait:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
 * Composer status + composer
 * ------------------------------------------------------------------- */

#composer-status {
  flex: 0 0 auto;
  margin: 0;
  padding: var(--space-xs) var(--space-md) 0;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

#composer-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding-inline: var(--space-md);
  padding-block-start: var(--space-sm);
  /* Keyboard/home-indicator clearance: whichever of the values below is
     largest. --kb is set by app.js's visualViewport listener; env()
     alone is not enough because it only accounts for the hardware safe
     area, not an open on-screen keyboard. */
  padding-block-end: max(
    env(safe-area-inset-bottom, 0px),
    0.75rem,
    var(--kb, 0px)
  );
}

/* Same #transcript[hidden] gotcha: #composer-form sets `display: flex`
   unconditionally above. */
#composer-form[hidden] {
  display: none;
}

#message-input {
  flex: 1 1 auto;
  min-block-size: 48px;
  max-block-size: 30dvh;
  padding: var(--space-sm) var(--space-md);
  /* 1rem minimum stops iOS Safari auto-zooming into the field on focus. */
  font-size: 1rem;
  font-family: var(--font-serif);
  color: var(--color-text);
  background: var(--color-surface-lowest);
  border: 1px solid var(--color-surface-high);
  border-radius: var(--radius-lg);
  resize: vertical;
}

#message-input::placeholder {
  font-style: italic;
  color: var(--color-text-muted);
}

#message-input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

#message-input[aria-disabled="true"] {
  color: var(--color-text-muted);
}

#send-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-inline-size: 48px;
  min-block-size: 48px;
  padding-inline: var(--space-md);
  color: var(--color-on-primary-container);
  background: var(--color-primary-container);
  border: none;
  border-radius: var(--radius-lg);
  font: inherit;
  font-weight: 600;
}

#send-button svg {
  inline-size: 16px;
  block-size: 16px;
}

#new-conversation {
  flex: 0 0 auto;
  min-inline-size: 48px;
  min-block-size: 48px;
  margin-inline: var(--space-md);
  margin-block-end: var(--space-sm);
  padding-inline: var(--space-md);
  color: var(--color-on-primary);
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-lg);
  font: inherit;
}

#send-button:disabled {
  opacity: 0.5;
}

#send-button:focus-visible,
#new-conversation:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

#chat-footer {
  flex: 0 0 auto;
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.68rem;
  color: var(--color-text-muted);
  text-align: center;
}

@container chat-pane (inline-size > 700px) {
  #transcript {
    padding-inline: calc(var(--space-md) * 2);
  }

  #quick-inquiries,
  #composer-form {
    padding-inline: calc(var(--space-md) * 2);
  }
}

/* ---------------------------------------------------------------------
 * Error toast
 * ------------------------------------------------------------------- */

#error-toast {
  /* display: none in the base rule, not flex: the UA popover stylesheet's
     `[popover]:not(:popover-open) { display: none }` is a UA-level rule
     that this author-level rule would otherwise always beat, keeping the
     closed toast in the render and a11y tree permanently (verified: closed
     toast computed to display: flex, a real 343x60 box with a focusable,
     tab-reachable Dismiss button). The :popover-open/.toast-open rule below
     re-enables it only while shown. */
  display: none;
  position: fixed;
  inset-inline: var(--space-md);
  /* Anchored to the top (role="alert", matches the UA-typical toast
     position), clear of the header, which always sits at the very top of
     the chat column now. Both inset-block-start and inset-block-end are
     set explicitly (not left for the UA popover stylesheet's `inset: 0` to
     supply the other one): the UA rule's `bottom: 0` combined with our
     fit-content height and margin: 0 would otherwise make the box
     over-constrained per CSS 2.1 §10.6.4, and browsers resolve that by
     dropping our declared value instead of the UA default (verified live).
     A bottom-anchored offset was tried and measured live to overlap
     #message-input and #send-button, including hit-testing the Send
     button's own centre to the toast's Dismiss button instead of Send. */
  inset-block-start: calc(4.5rem + env(safe-area-inset-top, 0px));
  inset-block-end: auto;
  margin: 0;
  max-inline-size: 28rem;
  margin-inline: auto;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-danger-text);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-lg);
  opacity: 0;
  transform: translateY(0.5rem);
  transition:
    opacity 0.15s ease,
    transform 0.15s ease,
    overlay 0.15s ease allow-discrete,
    display 0.15s ease allow-discrete;
}

@media (prefers-reduced-motion: reduce) {
  /* Keep the discrete display/overlay steps so the popover still un-renders;
     drop the fade and the slide. */
  #error-toast {
    transition:
      overlay 0s allow-discrete,
      display 0s allow-discrete;
    transform: none;
  }
}

/* .toast-open is the no-`popover`-support fallback hook: without it, a
   browser lacking the Popover API would have no way to show the toast
   against the display: none base rule above. */
/* Two separate rules on purpose: a selector list is dropped whole when an
   engine does not recognise :popover-open, which would also kill the
   .toast-open fallback branch. */
#error-toast:popover-open {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

#error-toast.toast-open {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  #error-toast:popover-open {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

#error-toast-message {
  flex: 1 1 auto;
  margin: 0;
}

#error-toast button {
  font: inherit;
  color: inherit;
  background: none;
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.6rem;
}

/* ---------------------------------------------------------------------
 * Guest notes
 * ------------------------------------------------------------------- */

#guest-notes {
  padding: var(--space-md);
  border: 1px solid var(--color-surface-high);
  border-radius: var(--radius-xl);
  background: var(--color-surface-lowest);
  color: var(--color-text);
  max-inline-size: min(90vw, 26rem);
  inline-size: 100%;
}

#guest-notes::backdrop {
  background: rgb(21 28 35 / 45%);
  backdrop-filter: blur(2px);
}

#guest-notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding-block-end: var(--space-xs);
  border-block-end: 1px solid var(--color-surface-high);
  margin-block-end: var(--space-sm);
}

#guest-notes-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-text);
}

#guest-notes-close {
  flex: 0 0 auto;
  inline-size: 2rem;
  block-size: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--color-text-muted);
  border-radius: 50%;
}

#guest-notes-close svg {
  inline-size: 16px;
  block-size: 16px;
}

#guest-notes-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* Two labelled groups inside the one panel (owner request 2026-09-19/20):
   "The household needs" (attendance, food, drinks -- what the hosts are
   waiting on) and "If you like" (songs -- purely optional, never counted
   toward the done-count below and never styled as unfinished). */
.note-group + .note-group {
  padding-block-start: var(--space-sm);
  border-block-start: 1px solid var(--color-surface-high);
}

.note-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.note-group-title {
  margin: 0 0 var(--space-xs);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* "N of 3 done" / "All done — thank you", computed live in app.js from the
   household group's own row statuses. A polite live region (index.html's
   aria-live="polite") so a guest using a screen reader hears it update
   without it interrupting whatever Jean is saying. */
.note-group-progress {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.note-group-rows {
  display: flex;
  flex-direction: column;
}

.note-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding-block: var(--space-sm);
  border-block-end: 1px solid var(--color-surface-low);
}

.note-row:last-child {
  border-block-end: none;
}

.note-icon {
  flex: 0 0 auto;
  inline-size: 1.7rem;
  block-size: 1.7rem;
  padding: 0.3rem;
  border-radius: var(--radius-md);
  background: var(--color-surface-low);
  color: var(--color-primary);
}

.note-copy {
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.note-label {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.note-summary {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--color-text);
  /* The food row folds every per-item record with "; ".join(...), so a
     single unbroken token drawn from guest text (a URL, a long compound
     word) must still break rather than force the panel to scroll. */
  overflow-wrap: anywhere;
}

/* Tappable links (app.js's linkifyText) inside a note summary -- most
   often the song row, where a guest pastes a Spotify/Apple Music/YouTube
   link verbatim. Same tokens as a message bubble's own links. */
.note-summary a {
  color: var(--color-secondary);
  text-decoration: underline;
}

.note-summary a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* A settled point gets a green tick at the end of its row (owner feedback
   2026-09-19); open and in-progress rows get nothing, so the tick means
   exactly one thing. `data-status` is set on the row by renderGuestNotes. */
.note-row[data-status="settled"]::after {
  content: "\2713";
  flex: 0 0 auto;
  margin-inline-start: auto;
  align-self: center;
  inline-size: 1.35rem;
  block-size: 1.35rem;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-success);
  color: var(--color-success);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

/* Honest empty state, unless/until renderGuestNotes(payload.notes) has real
   data (see app.js): muted ink, no invented values. Scoped to the household
   group only -- an unanswered optional row (the "If you like" group, e.g.
   songs) is never styled as unfinished: it already reads as an invitation,
   not a pending item, per its own fallback text (app.js's
   OPTIONAL_ROW_FALLBACK_TEXT). */
.note-group[data-note-group="household"] .note-summary[data-status="open"] {
  color: var(--color-text-muted);
  font-style: italic;
}

#guest-notes-footer {
  margin: var(--space-sm) 0 0;
  padding-block-start: var(--space-sm);
  border-block-start: 1px solid var(--color-surface-high);
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

/* Second footer sentence, shipped only when the server says the Spotify
   playlist feature is on (app.js reads `config.spotify_playlist_enabled`
   and toggles the committed `hidden` attribute) -- no extra spacing rule of
   its own beyond a small gap from the sentence above, so showing or hiding
   it never shifts `#guest-notes-footer`'s own position. */
#guest-notes-spotify-notice {
  margin: var(--space-xs) 0 0;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

/* One song's own line inside the song row's summary (app.js's
   renderSongItems) -- inline, so several songs read as separate lines via
   the `<br>` between them without becoming a list or changing the row's
   own flex layout. */
.note-song-line {
  display: inline;
}

/* Muted mark next to a song already on the hosts' Spotify playlist
   (app.js's renderSongItems, fed by notes.project()'s per-song
   `on_playlist` boolean) -- text only, no icon, no link, and the same
   muted ink as every other secondary label in this panel
   (`.note-label`/`.note-group-title`), so it reads as a quiet aside next to
   the guest's own words rather than a second answer. */
.note-song-mark {
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-style: normal;
}

/* ---------------------------------------------------------------------
 * Invite gate: blocked state (personal-invite-links MVP, lane G2)
 *
 * Shown instead of the entire chat shell when app.js has no valid
 * session -- either no invite was ever redeemed, or the one in the URL
 * fragment was rejected. `#app[data-state="blocked"]` hides the whole
 * `#chat-shell` in one rule below, which is what keeps every gated element
 * -- header, footer, quick-inquiry chips, guest notes -- off the public
 * gatekeeper screen without maintaining a per-element hide-list (the
 * original five `el.hidden = true` assignments in app.js stay, for the
 * live-region/announcement reasons their own comments document, but they
 * are no longer what does the hiding on their own).
 * ------------------------------------------------------------------- */

#app[data-state="blocked"] #chat-shell {
  display: none;
}

#invite-notice {
  flex: 1 1 auto;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-text-muted);
}

/* Same hidden-attribute-vs-author-display gotcha as #transcript/
   #composer-form above. */
#invite-notice[hidden] {
  display: none;
}

#invite-notice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  max-inline-size: 30rem;
  padding: var(--space-xl) var(--space-lg) var(--space-lg);
  background: var(--color-surface-lowest);
  border: 1px solid var(--color-surface-high);
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 24px -4px rgb(21 28 35 / 12%);
}

#invite-notice-caption {
  margin: 0;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--color-text);
  color: var(--color-bg);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05rem;
}

/* The picture carries the message; the two text lines under it say what to
   do next. Deliberately carries no venue name, date or email -- this
   screen is public (task WHAT TO BUILD item 4). */
#invite-notice-image {
  inline-size: min(70vw, 16rem);
  block-size: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-lg);
  filter: grayscale(1) contrast(1.05);
  box-shadow: 0 4px 20px -2px rgb(21 28 35 / 12%);
}

#invite-notice-protocol-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-primary);
}

#invite-notice p {
  margin: 0;
  max-inline-size: 32rem;
}

#invite-notice-line-en {
  font-weight: 600;
  color: var(--color-text);
}

#invite-notice-wordmark {
  margin-block-start: var(--space-md);
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* ---------------------------------------------------------------------
 * Desktop: two columns (chat + guest notes), notes shown inline
 * ------------------------------------------------------------------- */

@media (min-width: 900px) {
  .brand-name-short {
    display: none;
  }

  .brand-name-full {
    display: inline;
  }

  #brand-name {
    font-size: 1.35rem;
  }

  #notes-toggle {
    display: none;
  }

  #layout {
    flex-direction: row;
    gap: var(--space-lg);
    padding: var(--space-lg);
    overflow: hidden;
  }

  #chat-pane {
    border: 1px solid var(--color-surface-high);
    border-radius: var(--radius-xl);
  }

  /* Forces the panel to render as an ordinary flex column regardless of
     the <dialog> element's `open` IDL attribute -- on desktop it is never
     opened via showModal(); it is simply always part of the layout. ID
     specificity alone already beats the UA `dialog:not([open])` rule (see
     #error-toast's own comment on this exact class of override), so no
     !important is needed. */
  #guest-notes {
    display: flex;
    flex-direction: column;
    position: static;
    inset: auto;
    margin: 0;
    max-inline-size: 20rem;
    inline-size: 20rem;
    flex: 0 0 20rem;
    max-block-size: 100%;
    overflow-y: auto;
  }

  #guest-notes::backdrop {
    display: none;
  }

  #guest-notes-close {
    display: none;
  }
}
