button, textarea { font:inherit; }
button { cursor:pointer; }
button:focus-visible, textarea:focus-visible { outline:3px solid #698326; outline-offset:3px; }
/* Only the two programmatic modal focus targets need this touch override. */
html[data-chat-focus=pointer] :is(#ask-george, #chat-close):focus { outline:none; }
.chat-dialog { padding:0; border:1px solid var(--line); border-radius:12px; width:min(520px,calc(100vw - 32px)); height:min(820px,calc(100vh - 32px)); height:min(820px,calc(100dvh - 32px)); max-height:calc(100vh - 32px); max-height:calc(100dvh - 32px); margin:16px 16px 16px auto; overflow:hidden; color:var(--ink); background:var(--paper); box-shadow:0 24px 90px #101e2940; }
.chat-dialog::backdrop { background:#101e2966; }
.chat-dialog[open] { animation:chat-enter 560ms cubic-bezier(.25,.1,.25,1) backwards; }
.chat-dialog[open]::backdrop { animation:chat-backdrop-enter 560ms ease backwards; }
@keyframes chat-enter { from { opacity:0; transform:translateY(18px); } to { opacity:1; transform:translateY(0); } }
@keyframes chat-backdrop-enter { from { opacity:0; } to { opacity:1; } }
@keyframes chat-mobile-backdrop-enter { from { background:var(--chat-backdrop-from,transparent); } to { background:var(--paper,#fafbf9); } }
@keyframes chat-mobile-backdrop-exit { from { background:var(--chat-backdrop-from,var(--paper,#fafbf9)); } to { background:transparent; } }
.chat-shell { height:100%; display:flex; flex-direction:column; }
.chat-shell > :not(.chat-scroll) { flex-shrink:0; }
.chat-header { padding:22px 24px; display:flex; gap:14px; align-items:center; border-bottom:1px solid var(--line); }
.chat-avatar { width:42px; height:42px; flex:none; display:block; object-fit:cover; border-radius:8px; }
.chat-title { flex:1; min-width:0; }
.chat-title h2 { font-size:1.2rem; letter-spacing:-.025em; }
.chat-title p { font-size:.875rem; color:var(--muted); margin:4px 0 0; }
.chat-close { display:inline-flex; align-items:center; justify-content:center; gap:6px; flex:none; border:0; background:transparent; color:var(--ink); min-width:44px; height:44px; padding:0 6px; font-size:.875rem; line-height:1; border-radius:6px; }
.chat-close svg { display:block; flex:none; }
.chat-close:hover,.chat-reset:hover { background:#eaf0e7; }
.chat-notice { padding:10px 24px; font-size:.875rem; color:#344416; background:#edf7d9; border-bottom:1px solid #d3e4b1; }
.chat-config-retry { min-height:44px; margin-left:6px; padding:6px 12px; border:1px solid currentColor; border-radius:8px; background:transparent; color:inherit; font-weight:600; }
.chat-scroll { flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain; -webkit-overflow-scrolling:touch; touch-action:pan-y; padding:24px; }
/* Keep a native scroll range even when the welcome fits a large phone. This
   enables the browser's edge bounce without moving the header or hijacking touch. */
.chat-welcome { min-height:calc(100% + 1px); margin:0; }
.chat-welcome h3 { margin:0 0 10px; font-family:var(--serif); font-weight:400; font-size:1.8rem; line-height:1.2; }
.chat-welcome p { color:var(--muted); margin:0 0 18px; }
.chat-suggestions { display:flex; flex-direction:column; align-items:flex-start; gap:9px; }
.chat-suggestion { text-align:left; color:var(--ink); background:white; border:1px solid #b7c3b3; border-radius:6px; padding:10px 13px; font-size:.9rem; line-height:1.5; min-height:44px; }
.chat-suggestion:hover { border-color:var(--ink); background:#f0f5e9; }
.chat-suggestion:disabled { opacity:.55; cursor:default; }
.chat-messages { list-style:none; padding:0; margin:0; overflow-anchor:none; }
.chat-message { margin:0 0 20px; overflow-wrap:anywhere; animation:message-enter 560ms cubic-bezier(.25,.1,.25,1) both; }
@keyframes message-enter { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }
.message-text-revealing::after { content:''; display:inline-block; height:1em; border-right:2px solid currentColor; margin-left:2px; vertical-align:-.1em; opacity:.6; }
@media(prefers-reduced-motion:reduce) { .chat-message, .chat-dialog[open], .chat-dialog[open]::backdrop { animation:none; } .message-text-revealing::after { display:none; } }
.chat-message .chat-speaker { display:block; font-size:.875rem; font-weight:650; margin-bottom:7px; }
.chat-message p { margin:0; white-space:pre-wrap; line-height:1.65; }
.chat-message.user { margin-left:28px; padding:14px 16px; background:var(--ink); color:white; border-radius:10px 10px 2px 10px; }
.chat-message.assistant { padding:4px 4px 4px 0; }
.chat-message.pending p { color:var(--muted); }
.chat-composer { padding:16px 24px 12px; border-top:1px solid var(--line); background:var(--paper); }
.chat-composer label { display:block; font-size:.9rem; font-weight:600; margin-bottom:8px; }
.chat-entry { display:flex; align-items:flex-end; gap:8px; }
.chat-entry textarea { flex:1; min-width:0; }
.chat-composer textarea { display:block; width:100%; resize:vertical; min-height:76px; max-height:180px; border:1px solid #a9b5a3; border-radius:6px; padding:11px 12px; color:var(--ink); background:white; font-size:1rem; line-height:1.5; }
.chat-composer textarea:disabled { background:#f1f3ee; }
.chat-controls { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:10px; }
.chat-counter { font-size:.875rem; color:var(--muted); }
.chat-welcome .chat-voice-help { font-size:.875rem; }
.chat-dialog.voice-active .chat-composer { display:none; }
.chat-dialog.voice-active .voice-description { display:none; }
.chat-send { background:var(--ink); color:white; padding:10px 20px; border:1px solid var(--ink); border-radius:5px; min-height:44px; font-weight:600; }
.chat-send:disabled { opacity:.45; cursor:default; }
.chat-feedback { margin:8px 0 0; font-size:.875rem; color:#81351e; }
.chat-bottom { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:8px 16px; padding:0 24px 16px; font-size:.875rem; color:var(--muted); }
.chat-reset { padding:8px 0; color:var(--muted); background:transparent; border:0; text-decoration:underline; text-underline-offset:3px; min-height:44px; }
.chat-reset.is-empty { visibility:hidden; pointer-events:none; }
body.chat-open { overflow:hidden; }
/* Keep the outer viewport from rubber-banding during a chat gesture. The
   transcript retains its own contained native scrolling and edge bounce. */
html:has(body.chat-open), body.chat-open { overscroll-behavior-y:none; }
.voice-panel { padding:14px 24px; border-bottom:1px solid var(--line); background:#f0f5e9; }
.voice-actions { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.voice-actions button { min-height:44px; padding:9px 12px; border:1px solid #b7c3b3; border-radius:6px; font-size:.9rem; }
.voice-start { display:inline-flex; align-items:center; gap:8px; background:var(--ink); color:white; }
.voice-icon { flex:none; }
#ask-george { gap:8px; }
.voice-secondary { background:white; color:var(--ink); }
.voice-stop { background:white; color:#81351e; }
.voice-actions button:disabled { opacity:.55; }
.voice-description { font-size:.875rem; color:var(--muted); margin:9px 0 0; }
.voice-feedback { display:flex; align-items:center; gap:12px; margin-top:10px; color:var(--ink); }
.voice-feedback > div { min-width:0; }
.voice-feedback[data-waiting=true] .voice-status { font-weight:700; }
.voice-status { font-size:1rem; line-height:1.45; font-weight:500; color:var(--ink); margin:0; }
.voice-retry { margin:6px 0 0; font-size:.875rem; color:var(--ink); font-variant-numeric:tabular-nums; }
.voice-progress { display:block; flex:none; width:26px; height:26px; border:3px solid var(--line); border-top-color:var(--ink); border-right-color:var(--ink); border-radius:50%; animation:voice-progress 900ms linear infinite; }
@keyframes voice-progress { to { transform:rotate(360deg); } }
@media(prefers-reduced-motion:reduce) { .voice-progress { animation:none; } }
.voice-status:empty { display:none; }
.voice-panel audio { width:100%; margin-top:8px; }
.voice-panel, .chat-bottom-wrap { display:grid; grid-template-rows:1fr; min-height:0; transition:grid-template-rows 360ms ease, opacity 280ms ease, padding-top 360ms ease, padding-bottom 360ms ease, border-bottom-width 360ms ease; }
.voice-panel-content, .chat-bottom { min-height:0; overflow:hidden; }
.chat-bottom { transition:padding-bottom 360ms ease; }
.chat-dialog.keyboard-compact .voice-panel, .chat-dialog.keyboard-compact .chat-bottom-wrap { grid-template-rows:0fr; opacity:0; pointer-events:none; padding-top:0; padding-bottom:0; border-bottom-width:0; }
.chat-dialog.keyboard-compact .chat-bottom { padding-bottom:0; }
@media(prefers-reduced-motion:reduce) { .voice-panel, .chat-bottom-wrap, .chat-bottom { transition:none; } }
.chat-speaker.voice-label::after { content:' · Voice'; font-weight:400; color:var(--muted); }
[hidden] { display:none !important; }
@media(max-width:550px), (max-height:500px) {
  /* Keep an opaque full-screen cover while the keyboard moves the inner viewport. */
  .chat-dialog { position:fixed; inset:0; width:100%; max-width:100%; height:100%; max-height:none; margin:0; border:0; border-radius:0; }
  /* Whole-panel motion is managed separately from keyboard height changes. */
  .chat-dialog[open], .chat-dialog[open]::backdrop { animation:none; }
  .chat-dialog.chat-entering::backdrop { animation:chat-mobile-backdrop-enter 560ms ease both; }
  .chat-dialog.chat-closing::backdrop { animation:chat-mobile-backdrop-exit 360ms ease both; }
  .chat-dialog.chat-closing .chat-shell { pointer-events:none; }
  .chat-dialog::backdrop { background:var(--paper,#fafbf9); }
  .chat-shell { position:absolute; left:0; right:0; top:clamp(0px,var(--chat-viewport-top,0px),100%); height:var(--chat-viewport-height,100%); background:var(--paper); }
  .chat-dialog[open] .chat-shell { animation:none; }
  /* Match the footer's timing on both opening and dismissal. Resizing only
     the shell instantly would make the composer overshoot the rising keyboard. */
  .chat-dialog.typing .chat-shell, .chat-dialog.keyboard-expanding .chat-shell { transition:height 360ms ease; }
  .chat-header { padding:8px 12px; gap:10px; }
  .chat-avatar { width:32px; height:32px; }
  .chat-title h2 { font-size:1rem; }
  .chat-title p { font-size:.875rem; margin:0; }
  .chat-close { flex:none; }
  .chat-scroll { padding:16px 12px; }
  .chat-welcome h3 { font-size:1.45rem; }
  .chat-composer { padding:8px 12px 4px; }
  .chat-composer label { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
  .chat-composer textarea { min-height:44px; height:44px; max-height:88px; resize:none; padding:9px 10px; }
  .chat-send { padding:9px 12px; }
  .chat-controls { margin-top:2px; }
  .chat-bottom { padding:0 12px max(4px,env(safe-area-inset-bottom)); gap:4px 8px; }
  .chat-bottom a { display:flex; align-items:center; min-height:44px; }
  .chat-notice { padding:6px 12px; }
  .voice-panel { padding:8px 12px; }
  .voice-actions button { padding:8px 10px; }
  .voice-description { margin-top:4px; }
  .voice-feedback { margin-top:8px; }
}
@media(prefers-reduced-motion:reduce) { .chat-dialog[open], .chat-dialog[open]::backdrop, .chat-dialog[open] .chat-shell { animation:none; } .chat-dialog.typing .chat-shell, .chat-dialog.keyboard-expanding .chat-shell { transition:none; } }
@media(max-height:420px) {
  /* Keep the header and AI disclosure steady when keyboard space shrinks. */
  .voice-description, .chat-counter { display:none; }
  .voice-panel { padding-block:4px; }
  .chat-scroll { padding-block:8px; }
  .chat-composer { padding-top:4px; }
  .chat-dialog.voice-active .chat-bottom { display:none; }
}

/* A visible edge and resting shadow distinguish actions from the flat content cards. */
.button, .chat-send, .chat-suggestion, .voice-actions button {
  border-radius:12px;
  transition:background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  box-shadow:0 2px 0 #101e2926, inset 0 1px 0 #ffffff80;
}
.button, .voice-actions .voice-start {
  background:var(--accent);
  color:var(--ink);
  border:2px solid #486123;
  font-weight:650;
  box-shadow:0 3px 0 #34481b, 0 5px 12px #101e291a, inset 0 1px 0 #ffffffa6;
}
.chat-send { border-color:#101e29; box-shadow:0 2px 0 #000000, inset 0 1px 0 #ffffff33; }
.chat-suggestion, .voice-actions .voice-secondary { border-color:#87977e; }
.voice-actions .voice-stop { border-color:#a86c59; }
.button:focus-visible, .voice-actions button:focus-visible, .chat-send:focus-visible, .chat-suggestion:focus-visible, .chat-close:focus-visible {
  outline:3px solid var(--ink);
  outline-offset:4px;
}
.invitation .button:focus-visible { outline-color:var(--paper); }
@media(hover:hover) {
  .button:not(:disabled):hover, .voice-actions .voice-start:not(:disabled):hover { background:#e2ff98; border-color:#34481b; }
  .chat-send:not(:disabled):hover { background:#293f4c; }
  .chat-suggestion:not(:disabled):hover, .voice-actions .voice-secondary:not(:disabled):hover, .chat-close:hover { background:#f0f5e9; border-color:#486123; }
  .voice-actions .voice-stop:not(:disabled):hover { background:#fff0e9; }
}
/* Press feedback changes the surface, never the button's position or hit area. */
.button:not(:disabled):active, .voice-actions .voice-start:not(:disabled):active { background:#c9ef5e; box-shadow:inset 0 2px 3px #34481b33, 0 1px 0 #34481b; }
.chat-send:not(:disabled):active, .chat-suggestion:not(:disabled):active, .voice-actions .voice-secondary:not(:disabled):active, .voice-actions .voice-stop:not(:disabled):active { box-shadow:inset 0 2px 3px #101e2926; }
.chat-close:active { background:#eaf0e7; }
.button:disabled, .chat-send:disabled, .chat-suggestion:disabled, .voice-actions button:disabled {
  opacity:1;
  background:#e6ebe2;
  color:var(--muted);
  border-color:#a9b5a3;
  box-shadow:none;
  cursor:default;
}
@media(prefers-reduced-motion:reduce) {
  .button, .chat-send, .chat-suggestion, .voice-actions button, .chat-close { transition:none; }
}
