@import './components/fonts.css';
@import './components/button.css';

:root {
  color-scheme: light dark;
  --ink: light-dark(#171511, #f0f3ec);
  --muted: light-dark(#60665f, #b4c0b7);
  --green: #004c37;
  --accent: light-dark(#004c37, #b4efc2);
  --focus: light-dark(#00805c, #9ce4ae);
  --paper: light-dark(#f8faf5, #151c18);
  --white: light-dark(#fff, #1e2923);
  --soft: light-dark(#edf2ea, #25372d);
  --mine: light-dark(#e5f3dc, #294334);
  --line: light-dark(#d7e0d4, #43574a);
  --error: light-dark(#9b2b24, #ffb4a9);
  --mono: 'Roboto Mono', monospace;
  font-family: 'Plus Jakarta Sans', Arial, sans-serif;
  font-synthesis: none;
  color: var(--ink);
  background: var(--paper);
}
:root[data-appearance="light"] { color-scheme: light; }
:root[data-appearance="dark"] { color-scheme: dark; }
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, p { margin: 0; }
body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#app { flex: 1; min-height: 0; }
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: 3px; }
button, textarea, select, input { font: inherit; color: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: default; }
button, summary, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
img { display: block; max-width: 100%; }
.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.skip-link:focus { position: fixed; z-index: 8; top: 10px; left: 10px; padding: 12px; background: var(--white); }
.cta { margin: 0 4px 4px 0; }
.cta:not(:disabled):hover { --cta-face: #006247; }
.cta:disabled { --cta-face: light-dark(#e1ebe1, #33463a); --cta-side: var(--line); --cta-bottom: var(--line); color: var(--muted); }
.quiet-button, .text-button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-height: 36px; padding: 6px 11px; font-weight: 650; font-size: .875rem; line-height: 1.25;
  color: var(--accent); text-decoration: none;
}
.quiet-button { background: var(--white); border: 1px solid var(--line); border-radius: 3px; }
.quiet-button:where(button, a):not(:disabled):hover { background: var(--soft); }
.quiet-button[aria-pressed="true"] { background: var(--mine); border-color: var(--accent); }
.quiet-button:not([aria-pressed]):disabled { color: var(--muted); }
.text-button { background: transparent; border: 0; text-decoration: underline; text-underline-offset: 3px; }
.icon-button { width: 36px; min-width: 36px; padding: 0; border: 0; background: transparent; border-radius: 3px; }
.icon-button:hover { background: var(--soft); }
.wordmark { width: 126px; height: auto; }

.gate-page {
  height: 100%; padding: 20px 14px 28px;
  display: grid; place-items: safe center; overflow: auto;
}
.gate-card {
  width: min(100%, 506px); margin: auto; padding: 27px 22px 29px;
  background: var(--white); border: 1px solid var(--line); box-shadow: 0 4px 0 var(--line);
  text-align: center;
}
.gate-card .wordmark { margin: 0 auto 29px; }
.gate-card h1 { font-size: clamp(1.6rem, 5vw, 2.1rem); font-weight: 650; letter-spacing: -.045em; line-height: 1.15; }
.gate-hint { max-width: 340px; margin: 11px auto 20px; color: var(--muted); line-height: 1.5; }
.gate-card > .cta + .text-button { display: flex; margin: 8px auto 0; }
.gate-form { max-width: 374px; margin: 22px auto 0; }
.field { display: block; text-align: left; margin-bottom: 14px; font-size: .875rem; font-weight: 650; }
.field label, .field > span:first-child { display: block; margin-bottom: 6px; }
.field :is(input:not([type="checkbox"]), select), .menu-content select, .preview-content select {
  width: 100%; min-width: 0; min-height: 43px; padding: 8px 10px;
  background: var(--white); border: 1px solid var(--line); border-radius: 0;
  color: var(--ink); font-size: 1rem;
}
.field [aria-invalid="true"] { border-color: var(--error); }
.field [type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.field.option-check, .field.check-field { display: grid; grid-template-columns: 18px 1fr; gap: 6px 9px; align-items: center; }
.field.check-field label, .field.option-check span:first-child { grid-column: 2; grid-row: 1; margin: 0; }
.field.check-field input, .field.option-check input { grid-column: 1; grid-row: 1; }
.field.check-field .notice, .field.option-check .notice { grid-column: 2; }
.phone-fields { display: grid; grid-template-columns: minmax(100px, 44%) minmax(0, 1fr); gap: 8px; }
.phone-fields select { font-size: .8125rem; }
.notice { color: var(--error); font-size: .8125rem; line-height: 1.45; font-weight: 600; margin-block: 6px; overflow-wrap: anywhere; }
.notice:empty { display: none; }
.gate-form > .cta { min-width: min(155px, 100%); }
.code-panel { padding: 12px; margin: 0 auto 16px; max-width: 300px; background: var(--soft); border: 1px solid var(--line); }
.login-code { display: block; margin-bottom: 10px; font: 700 1.9rem/1.25 var(--mono); word-break: break-all; user-select: all; }
.login-qr { display: none; }
.countdown { margin: 10px 0; color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }

.chat-page { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.chat-head { flex: none; border-bottom: 1px solid var(--line); background: var(--white); z-index: 3; }
.chat-head-inner { display: flex; align-items: center; gap: 12px; padding: 9px 14px; max-width: 800px; margin: 0 auto; }
.site-label { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.site-label h1 { font-size: 1rem; line-height: 1.2; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; }
.site-initial { display: inline-grid; place-items: center; background: var(--green); color: white; font-weight: 800; }
.chat-head .wordmark { display: none; }
.chat-menu { position: relative; }
.chat-menu summary, .preview-tools summary { list-style: none; }
.chat-menu summary::-webkit-details-marker, .preview-tools summary::-webkit-details-marker { display: none; }
.chat-menu summary { display: grid; width: 38px; height: 36px; place-items: center; font-size: 1.4rem; border-radius: 3px; background: var(--soft); }
.menu-content { position: absolute; right: 0; top: calc(100% + 7px); width: 178px; display: grid; gap: 8px; padding: 10px;
  background: var(--white); border: 1px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.menu-content label { color: var(--muted); font-size: .8125rem; font-weight: 650; }
.menu-content select { font-size: .875rem; min-height: 36px; }
.connection-state { text-align: center; font-size: .8125rem; color: var(--accent); background: var(--soft); padding: 6px; }
.chat-scroll { min-height: 0; flex: 1; overflow: auto; overscroll-behavior: contain; overflow-anchor: none; }
.chat-scroll:focus-visible { outline-offset: -4px; }
.chat-column { width: min(100% - 28px, 760px); margin: 0 auto; padding: 13px 0 23px; min-height: 100%; display: flex; flex-direction: column; }
.start-history { text-align: center; margin: 3px auto 19px; color: var(--muted); font: .75rem/1.4 var(--mono); }
.start-history button { font-family: inherit; }
.welcome-chat { margin: auto; padding: 45px 0; text-align: center; font-size: 1.25rem; font-weight: 650; letter-spacing: -.025em; }
.welcome-chat .site-avatar { width: 60px; height: 60px; margin: 0 auto 13px; font-size: 1.55rem; }
.thread-list { display: flex; flex-direction: column; gap: 17px; min-width: 0; }
.message { align-self: flex-start; display: grid; gap: 6px; max-width: 94%; width: fit-content; min-width: 0; overflow-wrap: anywhere; touch-action: pan-y; }
.message.from-user { align-self: flex-end; }
.message:has(.carousel) { width: 100%; max-width: 100%; }
.message-name { display: flex; gap: 7px; align-items: baseline; font-size: .75rem; color: var(--muted); font-weight: 650; }
.from-user .message-name { justify-content: flex-end; }
.message-name time { font: .6875rem/1.4 var(--mono); }
.bubble { background: var(--white); color: var(--ink); border: 1px solid var(--line); border-radius: 4px 4px 4px 0; padding: 10px 13px;
  font-size: 1rem; line-height: 1.52; min-width: 0; }
.from-user .bubble { background: var(--mine); border-radius: 4px 4px 0 4px; white-space: pre-wrap; }
.prose :is(p, ul, ol, blockquote, pre, h2, h3, h4, h5, h6, .table-scroll) { margin: 0; }
.prose > :is(p, ul, ol, blockquote, pre, h2, h3, h4, h5, h6, .table-scroll) + * { margin-top: .65em; }
.prose :is(ul, ol) { padding-left: 1.25rem; }
.prose :is(h2, h3, h4, h5, h6) { line-height: 1.3; font-size: 1.05em; }
.prose pre, .prose blockquote { padding: 8px 10px; background: var(--soft); }
.prose pre, .table-scroll { overflow: auto; max-width: 100%; }
.prose code { font: .9em/1.5 var(--mono); white-space: pre-wrap; }
.prose table { border-collapse: collapse; }
.prose th, .prose td { padding: 6px 9px; border: 1px solid var(--line); text-align: start; white-space: normal; }
.table-scroll { display: grid; grid-template-columns: max-content; }
.quoted-message, .reply-chip { display: grid; gap: 2px; line-height: 1.35; border: 0; border-left: 3px solid var(--accent);
  background: var(--soft); padding: 7px 9px; text-align: left; font-size: .8125rem; }
.quoted-message span, .reply-chip span { display: block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quoted-message strong, .reply-chip strong { color: var(--accent); }
.message-actions { display: flex; gap: 2px; }
.message-actions .text-button { padding: 3px 6px; min-height: 29px; font-size: .75rem; color: var(--muted); }
.from-user .message-actions { justify-content: flex-end; }
.message-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; color: var(--muted); font-size: .75rem; }
.from-user .message-foot { justify-content: flex-end; }
.receipt { color: var(--accent); font-weight: 700; }
.reactions { display: flex; flex-wrap: wrap; gap: 5px; }
.reactions span { border: 1px solid var(--line); border-radius: 12px; background: var(--white); padding: 2px 6px; }
.typing-state { color: var(--muted); font: .8125rem/1.4 var(--mono); margin-top: 14px; }
.new-messages { position: absolute; z-index: 2; bottom: 93px; left: 50%; transform: translateX(-50%); box-shadow: 0 3px 0 var(--line); white-space: nowrap; }
.message-sticker { width: min(160px, 100%); aspect-ratio: 1; object-fit: contain; }

.composer-dock { flex: none; background: var(--paper); padding: 0 14px max(13px, env(safe-area-inset-bottom)); }
.composer { width: min(100%, 760px); margin: auto; border: 1px solid var(--line); box-shadow: 0 2px 0 var(--line);
  padding: 8px; background: var(--white); border-radius: 4px; }
.composer:focus-within { border-color: var(--focus); box-shadow: 0 0 0 2px var(--focus); }
.chat-notice { width: min(100%, 760px); margin-inline: auto; }
.reply-chip { grid-template-columns: minmax(0, 1fr) auto; margin-bottom: 6px; align-items: center; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-width: 0; min-height: 41px; min-block-size: 41px; max-height: 120px; outline: 0; border: 0;
  padding: 8px 4px; line-height: 24px; background: transparent; resize: none; font-size: 1rem; }
.composer textarea::placeholder { color: var(--muted); }
.send-button { font-size: 1.25rem; width: 40px; min-height: 36px; padding: 0; }
.character-counter { display: block; margin-top: 3px; text-align: end; color: var(--muted); font: .75rem/1.5 var(--mono); }

.component { display: grid; gap: 9px; }
.component h3, .carousel h3 { font-size: .9375rem; font-weight: 750; }
.action-row { display: flex; flex-wrap: wrap; gap: 6px; }
.action-button { width: fit-content; min-width: 0; white-space: normal; }
.form-result, .selected-choice { color: var(--accent); font-size: .875rem; }
.agent-form .field { margin-bottom: 2px; }
.agent-form .cta { justify-self: start; }
.carousel { min-width: 0; }
.carousel-controls { display: none; }
.carousel-track { display: flex; gap: 12px; overflow-x: auto; padding: 4px; scroll-snap-type: x mandatory; touch-action: pan-x pan-y; }
.carousel-card { flex: 0 0 clamp(178px, 74%, 234px); min-width: 0; scroll-snap-align: start; border: 1px solid var(--line);
  border-radius: 4px; background: var(--white); overflow: hidden; }
.card-media { display: block; width: 100%; max-height: 177px; aspect-ratio: 4 / 3; object-fit: contain; background: var(--soft); }
.card-copy { padding: 10px; display: grid; gap: 4px; }
.card-copy p { font-size: .8125rem; line-height: 1.4; color: var(--muted); }
.card-copy .action-row { margin-top: 5px; }

.sheet { position: fixed; inset: auto 0 0; width: min(100%, 445px); max-width: 100%; max-height: 80vh; margin: 0 auto;
  padding: 14px; background: var(--white); border: 1px solid var(--line); color: var(--ink); }
.sheet::backdrop { background: #101a16aa; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.sheet-head h2 { font-size: 1.1rem; letter-spacing: -.025em; }
.choice-list { display: grid; gap: 7px; }
.choice-list .action-button { display: grid; justify-content: stretch; text-align: start; width: 100%; }
.choice-list small { color: var(--muted); }
.emoji-list { display: flex; flex-wrap: wrap; gap: 7px; }
.emoji-button { min-width: 39px; min-height: 39px; font-size: 1.25rem; border: 1px solid var(--line); background: var(--soft); border-radius: 4px; }

.preview-tools { position: relative; z-index: 4; flex: none; background: var(--soft); border-top: 1px solid var(--line); }
.preview-tools summary { display: inline-block; padding: 5px 13px; color: var(--accent); font: .75rem/1.25 var(--mono); }
.preview-content { position: absolute; bottom: 100%; left: 0; width: min(335px, 100vw); max-height: 70vh; overflow: auto; display: grid; gap: 7px;
  background: var(--white); border: 1px solid var(--line); padding: 12px; font-size: .875rem; }
.preview-content select { font-size: .85rem; min-height: 33px; }
.preview-links { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 5px; }

@media (min-width: 701px) {
  .gate-page { padding: 36px; }
  .gate-card { padding: 35px; }
  .login-qr { display: block; width: 153px; height: 153px; margin: 13px auto 6px; image-rendering: pixelated; }
  .chat-head-inner { min-height: 62px; padding-inline: 20px; }
  .chat-head .wordmark { display: block; width: 96px; margin-right: 6px; }
  .chat-column { width: min(100% - 40px, 760px); padding-top: 20px; }
  .message { max-width: 80%; }
  .sheet { inset: 0; margin: auto; }
  .carousel-controls { display: flex; justify-content: flex-end; gap: 3px; }
  .carousel-controls .icon-button { font-size: 1.25rem; background: var(--soft); }
}
@media (hover: hover) {
  .message-actions { opacity: 0; }
  .message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .cta { transition: none; }
}
