/* Stable viewport: only the conversation scrolls on wide screens. */
html, body { height: 100%; }
button, input, textarea, a { -webkit-tap-highlight-color: transparent; }
button, input, textarea { font-family: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible, [role=button]:focus-visible { outline: 2px solid #e75d46; outline-offset: 3px; }
.app { height: calc(100dvh - 32px); min-height: 0; }
.sidebar, .workspace { min-height: 0; }
#chat { min-height: 0; overscroll-behavior: contain; scroll-padding: 20px; }
.chat-view { position: relative; min-height: 0; overflow: hidden; }
.chat-view #chat { height: 100%; }
#latest { position: absolute; bottom: 12px; right: 18px; width: 44px; height: 44px; border: 1px solid #bfd5cb; border-radius: 50%; background: #fff; color: #27645a; font-size: 24px; cursor: pointer; box-shadow: 0 3px 12px #143d3720; }
#latest[hidden] { display: none; }
.side-title { display: flex; align-items: center; justify-content: space-between; }
#clearChats { padding: 4px 8px; color: #d6e8df; background: transparent; border: 0; cursor: pointer; }
#conversationList { flex: 1; }
.conversation-row { display: flex; align-items: center; gap: 2px; }
.conversation { min-width: 0; flex: 1; }
.delete-chat { flex: 0 0 30px; height: 34px; border: 0; background: transparent; color: #c6ddd1; font-size: 22px; cursor: pointer; }
.delete-chat:hover { color: #ffb39a; }
.side-footer { display: flex; justify-content: space-between; }
.topbar > div { min-width: 0; }
.topbar h1 { overflow-wrap: anywhere; }
.access-field { width: 260px; flex: 0 1 260px; display: grid; gap: 4px; }
.access-field label { color: #315d52; font-size: 12px; }
.access-field .access { width: 100%; min-width: 0; }
.topbar .access-hint { display: block; margin: 0; color: #945126; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.access[aria-invalid="true"] { border-color: #b83d29; background: #fff4ef; }
[hidden] { display: none !important; }
#currentTitle { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message { overflow-wrap: anywhere; }
.message-body { overflow-wrap: anywhere; }
.message-actions { display: flex; gap: 10px; margin-top: 5px; }
.message-actions button { padding: 3px 5px; border: 0; background: transparent; color: #456a5c; cursor: pointer; font-size: 12px; }
.message-actions button:hover { color: #b84936; }
.failed .message-body { background: #fff0eb; color: #8c4637; border-color: #f2cec0; }
.waiting .message-body { color: #526e62; }
#previews { display: flex; gap: 8px; overflow: auto; }
.preview { position: relative; flex: 0 0 66px; width: 66px; height: 66px; margin-bottom: 10px; }
.preview img { width: 66px; height: 66px; object-fit: cover; border-radius: 5px; border: 1px solid #d8e4dd; }
.preview button { position: absolute; top: 0; right: 0; width: 24px; height: 24px; border: 0; border-radius: 3px; background: #143d37; color: white; font-size: 18px; cursor: pointer; }
.message-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.message-images img { width: 140px; height: 100px; max-width: 100%; object-fit: contain; background: #fff; border-radius: 5px; }
#send { min-height: 60px; }
textarea { resize: none; min-height: 60px; }
.composer-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 11px; color: #657d71; min-height: 16px; }
.composer-foot details { position: relative; flex-shrink: 0; }
.composer-foot summary { cursor: pointer; }
.composer-foot details p { position: absolute; bottom: 20px; right: 0; width: min(270px, 80vw); padding: 12px; margin: 0; border: 1px solid #d4e0d8; background: #fff; border-radius: 6px; line-height: 1.7; box-shadow: 0 6px 20px #143d3714; z-index: 2; }
button:disabled { opacity: .5; cursor: wait; }
@media (max-width: 780px), (max-height: 560px) and (pointer: coarse) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  body { min-height: 0; }
  .app { position: fixed; top: var(--app-top, 0px); left: 0; width: 100%; margin: 0; height: var(--app-height, 100dvh); min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); border: 0; border-radius: 0; box-shadow: none; }
  .sidebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: max(10px, env(safe-area-inset-top)) 14px 10px; }
  .brand { padding: 0; gap: 8px; }
  .brand b { font-size: 15px; }
  .brand span { display: none; }
  .brand-mark { width: 30px; height: 30px; font-size: 16px; flex-shrink: 0; }
  .new-chat { min-height: 40px; font-size: 13px; }
  .side-title { margin: 0; font-size: 11px; }
  .side-footer { display: block; padding: 0; margin: 0; text-align: right; grid-column: 2; grid-row: 2; }
  .manage-link { display: inline-flex; align-items: center; min-height: 40px; padding: 0 8px; }
  #clearChats { min-height: 40px; }
  #conversationList { grid-column: 1 / -1; min-height: 0; }
  .conversation-row { flex: 0 0 164px; min-width: 0; }
  .conversation { padding: 6px; }
  .conversation-title { font-size: 12px; }
  .conversation-time { margin-top: 2px; font-size: 10px; }
  .delete-chat { flex-basis: 36px; height: 44px; }
  .workspace { min-height: 0; }
  .topbar { min-height: 52px; padding: 8px 14px; gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .topbar > div:first-child { display: none; }
  .access-field { flex: 1; width: 100%; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; align-items: center; }
  .access-field label { font-size: 13px; }
  .access-field .access { height: 40px; }
  .topbar .access-hint { grid-column: 2; }
  .access { width: 100px; min-width: 80px; font-size: 16px; }
  #chat { min-height: 0; padding: 14px; }
  .composer { padding: 10px 14px max(10px, env(safe-area-inset-bottom)); }
  textarea { font-size: 16px; }
  .attachment-row { gap: 6px; margin-bottom: 7px; }
  .file-button, .tool-button, .message-actions button { min-height: 40px; }
  .preview button { width: 32px; height: 32px; }
  .message { max-width: 96%; }
  .compact-viewport #conversationList, .compact-viewport .side-title { display: none; }
  .compact-viewport .side-footer { grid-column: 1; grid-row: auto; text-align: left; }
  .compact-viewport .topbar { min-height: 44px; padding-top: 3px; padding-bottom: 3px; }
  .compact-viewport .sidebar { grid-template-columns: minmax(0, 1fr) auto auto; padding-top: 6px; padding-bottom: 6px; gap: 0 6px; }
  .compact-viewport .brand { grid-column: 1; grid-row: 1; min-width: 0; }
  .compact-viewport .brand b { font-size: 12px; }
  .compact-viewport .new-chat { grid-column: 2; grid-row: 1; padding: 0 10px; }
  .compact-viewport .side-footer { grid-column: 3; grid-row: 1; text-align: right; }
  .compact-viewport .composer { padding-top: 6px; }
  .compact-viewport textarea { max-height: 80px; }
  .compact-viewport .composer-foot #notice { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .compact-viewport .preview { flex-basis: 44px; width: 44px; height: 44px; margin-bottom: 4px; }
  .compact-viewport .preview img { width: 44px; height: 44px; }
  .tight-viewport .sidebar { padding-top: 3px; padding-bottom: 3px; }
  .tight-viewport .access-field .access { height: 36px; }
  .tight-viewport .topbar .access-hint, .tight-viewport #fileHint, .tight-viewport #locationHint { display: none; }
  .tight-viewport .preview { flex-basis: 36px; width: 36px; height: 36px; margin-bottom: 2px; }
  .tight-viewport .preview img { width: 36px; height: 36px; }
  .tight-viewport .attachment-row { margin-bottom: 4px; }
  .tight-viewport .file-button, .tight-viewport .tool-button { min-height: 36px; }
  .tight-viewport textarea { min-height: 44px; max-height: 60px; padding: 8px 10px; }
  .tight-viewport #send { min-height: 44px; }
  .tight-viewport .composer-foot { margin-top: 4px; }
  .tight-viewport .compose-row { grid-template-columns: minmax(0, 1fr) 76px; }
  .tight-viewport #latest { width: 32px; height: 32px; bottom: 4px; right: 12px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
