/* Conversation layout shared by web/PWA/native shells. Keep controls at least
   44px; recover space by removing duplicate rows, not shrinking reading text. */
:root { --chat-viewport: 100vh; }
@supports (height: 100dvh) { :root { --chat-viewport: 100dvh; } }
.chat-panel { isolation: isolate; }
.chat-panel > :not(.chat-messages) { flex-shrink: 0; }
.chat-header { position: relative; z-index: 3; gap: 10px; padding: 12px 14px; }
.chat-heading { flex: 1; min-width: 0; }
.chat-heading h2 { font-size: 16px; margin-bottom: 3px; }
.chat-header #aiState { max-width: 100%; color: #687967; }
.chat-header .icon-button { width: 44px; height: 44px; flex: 0 0 44px; margin: 0; color: #607666; }
.chat-header .assistant-avatar { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 12px; }
.chat-header .assistant-avatar img { width: 28px; height: 28px; }
.chat-context { padding: 6px 14px; color: #687967; font-size: 12px; }
.chat-messages { padding: 16px 14px; gap: 16px; overflow-x: hidden; overscroll-behavior-y: contain; }
.chat-messages > * { flex-shrink: 0; min-width: 0; }
.bubble { font-size: 16px; line-height: 1.75; padding: 12px 14px; }
.message-label { color: #72816d; font-size: 11px; margin-bottom: 5px; }
.message .primary, .message .feedback { font-size: 14px; }
.message .question-title { font-size: 16px; }
.message .quiz-option { min-height: 52px; }
.starter-card { padding: 16px; }
.starter-card img { width: 32px; margin-bottom: 8px; }
.starter-card h3 { font-size: 17px; }
.starter-card p { font-size: 14px; color: #6f7c65; line-height: 1.7; }
.starter-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.starter-actions button { min-height: 44px; padding: 10px; font-size: 13px; line-height: 1.5; }

/* Secondary actions are always reachable without taking a permanent row. */
.chat-tools { flex: 0 0 44px; }
.chat-tools > summary { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; font-size: 25px; font-weight: 700; letter-spacing: 2px; cursor: pointer; list-style: none; color: var(--green); }
.chat-tools > summary::-webkit-details-marker { display: none; }
.chat-tools > summary:hover, .chat-tools[open] > summary { background: var(--sage); }
.chat-tools > summary:focus-visible { outline: 3px solid #b8652e; outline-offset: 2px; }
.chat-tools-body { position: absolute; top: calc(100% - 4px); right: 10px; width: min(330px, calc(100% - 20px)); padding: 16px; border: 1px solid #dce5d4; border-radius: 16px; background: #fff; box-shadow: 0 12px 32px #263d3524; max-height: calc(var(--chat-viewport) - 180px); overflow-y: auto; overscroll-behavior: contain; }
.chat-tools-body > label { display: block; font-size: 13px; color: #596d5e; margin-bottom: 8px; }
.chat-tools-body .model-select { display: block; width: 100%; max-width: 100%; min-width: 0; height: 44px; border: 1px solid #dce5d4; border-radius: 10px; padding: 0 8px; background: #f7f9f3; color: var(--ink); font-size: 16px; text-overflow: ellipsis; }
.chat-tools-body .chat-shortcuts { display: grid; grid-template-columns: 1fr 1fr; padding: 12px 0; gap: 8px; overflow: visible; }
.chat-tools-body .chat-shortcuts button, .chat-new { min-height: 44px; font-size: 13px; padding: 8px; color: var(--green); border: 1px solid var(--line); border-radius: 10px; }
.chat-new { width: 100%; text-align: left; padding-inline: 12px; }
.chat-tools-body .privacy-actions { gap: 6px 14px; margin-top: 10px; }
.chat-tools-body .privacy-actions .text-link { display: inline-flex; align-items: center; min-height: 44px; font-size: 12px; }
.chat-tools-body .chat-footnote { font-size: 12px; text-align: left; line-height: 1.6; color: #6e7d64; padding: 8px 0 0; }

/* Text and hold-to-talk share the same input row. A draft is never discarded. */
.chat-form { --control-row: 1; display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; grid-auto-rows: max-content; align-content: start; align-items: end; gap: 6px 8px; margin: 0 10px 10px; padding: 8px; flex-shrink: 0; max-height: 48%; overflow-y: auto; overscroll-behavior: contain; border-radius: 16px; }
.chat-form #speechToggle, .chat-form #sendChat { grid-row: var(--control-row); width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; }
.chat-form #speechToggle { grid-column: 1; padding: 0; font-size: 13px; background: #edf2e6; color: var(--green); }
.chat-form #speechToggle[aria-expanded="true"] { background: #dce7ce; }
.chat-form #sendChat { grid-column: 3; background: var(--green); color: #fff; font-size: 27px; }
.chat-form #sendChat:disabled { opacity: .45; }
.chat-form textarea { grid-row: 1; grid-column: 2; display: block; height: 44px; min-height: 44px; max-height: 100px; padding: 10px 2px; font-size: 16px; line-height: 24px; resize: none; overflow-y: auto; }
.chat-form.is-voice-mode textarea { display: none; }
.chat-form.is-voice-mode.has-draft { --control-row: 2; }
.chat-form.is-voice-mode.has-draft textarea { display: block; grid-column: 1 / -1; padding-inline: 6px; border-bottom: 1px solid var(--line); }
.chat-form .speech-panel { display: contents; }
.chat-form .speech-controls { grid-column: 2; grid-row: var(--control-row); position: relative; display: flex; gap: 4px; flex-wrap: nowrap; min-width: 0; }
.chat-form #speechHold { width: 100%; min-width: 0; min-height: 44px; font-size: 15px; padding: 8px 4px; line-height: 1.4; }
.chat-form #speechCancel { min-height: 44px; padding: 6px; font-size: 12px; }
.chat-form #speechTimer { position: absolute; bottom: calc(100% + 3px); right: 4px; padding: 2px 6px; border-radius: 6px; background: #fff; color: var(--green); font-size: 11px; box-shadow: 0 0 0 1px var(--line); pointer-events: none; }
.chat-form .speech-status { grid-column: 1 / -1; grid-row: 3; font-size: 12px; line-height: 1.6; margin: 0; padding: 1px 4px; max-height: 80px; overflow-y: auto; }
.chat-form .speech-status[data-tone="error"] { color: #974b32; }
.chat-form .speech-consent, .chat-form .speech-pending { grid-column: 1 / -1; margin: 0; padding: 10px; max-height: 180px; overflow-y: auto; font-size: 13px; }
.chat-form .speech-consent { grid-row: 4; }
.chat-form .speech-pending { grid-row: 5; }
.chat-form .speech-small { min-height: 44px; }
.chat-form #speechRetry { grid-column: 1 / -1; grid-row: 6; min-height: 44px; text-align: left; padding: 4px; }

@media (min-width: 1001px) {
  .workspace { grid-template-columns: minmax(340px, 1.15fr) minmax(0, 1fr); }
  .chat-panel { height: calc(var(--chat-viewport) - 120px); min-height: 380px; max-height: 900px; }
}
@media (min-width: 651px) and (max-width: 1000px) {
  .chat-panel { height: max(360px, calc(var(--chat-viewport) - 120px)); min-height: 0; }
}
@media (max-width: 650px) {
  :root { --mobile-topbar: calc(48px + env(safe-area-inset-top)); --mobile-nav: calc(56px + env(safe-area-inset-bottom)); }
  html { scroll-padding-top: calc(var(--mobile-topbar) + 8px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { padding-bottom: 0; }
  .topbar { position: sticky; top: 0; z-index: 40; height: var(--mobile-topbar); padding: env(safe-area-inset-top) 12px 0; gap: 8px; }
  .topbar > .mobile-brand:first-of-type { font-size: 18px; letter-spacing: 2px; }
  .topbar-right { gap: 6px; }
  .chat-toggle { min-height: 44px; padding: 6px 8px; font-size: 13px; }
  .profile-link { min-height: 44px; min-width: 44px; gap: 6px; }
  .profile-name { font-size: 12px; max-width: 72px; }
  .profile-mark { width: 28px; height: 28px; font-size: 15px; }
  .workspace { padding: 6px 6px 24px; gap: 24px; }
  .chat-panel { height: max(240px, calc(var(--chat-viewport) - var(--mobile-topbar) - var(--mobile-nav) - 12px)); min-height: 0; max-height: none; border-radius: 16px; scroll-margin-top: 0; }
  .chat-header { padding: 6px 8px; gap: 6px; }
  .chat-heading h2 { font-size: 16px; line-height: 1.4; }
  .chat-header #aiState { font-size: 11px; max-width: 100%; }
  .chat-header .assistant-avatar { width: 32px; height: 32px; flex-basis: 32px; border-radius: 10px; }
  .chat-header .assistant-avatar img { width: 26px; height: 26px; }
  .chat-context { padding: 4px 12px; font-size: 11px; line-height: 1.6; }
  .chat-messages { padding: 12px 10px; gap: 14px; }
  .bubble { font-size: 16px; line-height: 1.75; padding: 10px 12px; }
  .starter-card { padding: 14px; }
  .starter-card img { display: none; }
  .starter-card h3 { font-size: 16px; text-align: left; }
  .starter-card p { font-size: 14px; }
  .starter-actions button { font-size: 13px; min-height: 44px; padding: 8px; }
  .chat-form { margin: 0 6px 6px; padding: 6px; gap: 4px 6px; }
  .chat-tools-body { right: 6px; width: min(330px, calc(100% - 12px)); max-height: calc(var(--chat-viewport) - var(--mobile-topbar) - var(--mobile-nav) - 82px); }
  .sidebar { height: var(--mobile-nav); padding-bottom: env(safe-area-inset-bottom); }
  .sidebar nav a { min-width: 0; font-size: 11px; line-height: 1.3; letter-spacing: 0; padding: 5px 2px; gap: 3px; }
  .nav-symbol { font-size: 20px; line-height: 22px; }
  .app-shell { padding-bottom: var(--mobile-nav); }
  .toast { bottom: calc(var(--mobile-nav) + 12px); max-width: calc(100% - 24px); font-size: 13px; }
  .greeting p, .hero p { font-size: 13px; line-height: 1.7; }
  .char-info-top { font-size: 13px; }
  .char-info-top .py, .char-info p, .stat span { font-size: 11px; }
  .theme-button, .progress-item > .text-link { font-size: 12px; }
  .char-info p { line-height: 1.6; }
  body.chat-keyboard-open { --mobile-topbar: 0px; --mobile-nav: 0px; }
  body.chat-keyboard-open .topbar, body.chat-keyboard-open .sidebar,
  body.chat-keyboard-open .chat-context { display: none; }
  body.chat-keyboard-open .chat-panel { height: max(200px, calc(var(--chat-viewport) - 12px)); }
  body.chat-keyboard-open .chat-header { padding-block: 2px; }
  body.chat-keyboard-open .toast { bottom: 12px; }
}
@media (max-width: 650px) and (max-height: 520px) {
  .chat-context { display: none; }
  .chat-header { padding-block: 2px; }
}
@media (prefers-reduced-motion: reduce) { .chat-messages { scroll-behavior: auto; } }
