.chat-page {
  --gutter: max(20px, calc((100% - 720px) / 2));
  --icon-lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E");
  --icon-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5M12 16.5h.01'/%3E%3C/svg%3E");
  display: flex; flex-direction: column; width: min(960px, 100%); height: calc(100dvh - 48px); overflow: hidden;
  border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text-main); box-shadow: 0 24px 80px var(--shadow);
  background: var(--panel-glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .chat-page { background: var(--bg-surface); } }
.chat-heading { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; column-gap: 12px; padding: 20px var(--gutter); border-bottom: 1px solid var(--border); }
.chat-title { display: contents; }
.chat-brand { position: relative; grid-row: 1 / 3; width: 36px; height: 36px; }
.chat-brand::after { content: ""; position: absolute; inset: -4px; }
.chat-logo { display: block; width: 36px; height: 36px; transition: filter .15s; }
.chat-brand:hover .chat-logo { filter: brightness(1.2); }
.chat-heading h1, .chat-heading p { grid-column: 2; }
.chat-tools { grid-column: 3; grid-row: 1 / 3; display: flex; align-items: center; gap: 8px; }
.chat-contact { display: flex; align-items: center; min-height: 34px; max-width: 16em; padding: 0 12px; border: 1px solid var(--accent-line); border-radius: 999px; color: var(--accent-light); font-size: var(--fs-sm); text-decoration: none; }
.chat-contact span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-contact:hover { background: var(--accent-soft); }
.chat-heading h1 { font-size: clamp(20px, 3vw, 26px); line-height: 1.4; }
.chat-heading p, .chat-speaker { font-size: var(--fs-xs); color: var(--text-muted); }
.chat-feed { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-messages { overflow-y: auto; min-height: 0; flex: 1; padding: 20px var(--gutter); display: flex; flex-direction: column; gap: 18px; overscroll-behavior: contain; }
.chat-jump { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--bg-card); color: var(--text-main); border-color: var(--accent-line); border-radius: 999px; padding: 6px 14px; font-size: var(--fs-sm); box-shadow: 0 6px 20px var(--shadow); }
.chat-typing { display: inline-flex; align-items: center; gap: 4px; height: 1.6em; }
.chat-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: chat-dot 1.2s ease-in-out infinite; }
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-thinking { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-left: 3px solid var(--accent-light); background: var(--accent-soft); border-radius: 6px; color: var(--accent-light); font-size: var(--fs-sm); font-style: italic; }
.chat-thinking::before { content: "⚡"; display: inline-flex; align-items: center; opacity: .7; }
.chat-thinking-dots { display: inline-flex; gap: 2px; }
.chat-thinking-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: chat-dot 1.2s ease-in-out infinite; }
.chat-thinking-dots i:nth-child(2) { animation-delay: .15s; }
.chat-thinking-dots i:nth-child(3) { animation-delay: .3s; }
.chat-message { max-width: 94%; }
.chat-message .markdown, .chat-message .plain-message { font-size: var(--fs-md); }
.chat-message-user { align-self: flex-end; background: var(--accent-bubble); border: 1px solid var(--accent-line); border-radius: 14px 14px 4px 14px; padding: 10px 14px; }
.chat-message-assistant { align-self: flex-start; display: grid; grid-template-columns: 28px minmax(0, 1fr); column-gap: 10px; }
.chat-message-assistant > :not(.chat-avatar) { grid-column: 2; }
.chat-avatar { width: 28px; height: 28px; margin-top: 4px; }
.chat-message-assistant .chat-typing { margin-block: 6px; }
.chat-starters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chat-starter { padding: 8px 14px; border-color: var(--accent-line); border-radius: 999px; background: var(--accent-soft); color: var(--text-main); font-size: var(--fs-sm); text-align: left; }
.chat-starter:hover:not(:disabled) { border-color: var(--accent-light); background: var(--accent-bubble); }
.chat-outcome { margin-top: 4px; color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-outcome[data-outcome=error] { color: var(--error-text); }
.chat-older { align-self: center; margin: 8px 0 0; }

.chat-statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; min-height: 30px; padding: 4px var(--gutter) 8px; font-size: var(--fs-xs); color: var(--text-muted); }
.chat-security, .chat-status { display: flex; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.chat-status:empty { display: none; }
.chat-security::before, .chat-status[data-kind=error]::before { content: ""; width: 14px; height: 14px; flex: none; background: var(--state, currentColor); -webkit-mask: var(--icon, var(--icon-lock)) center / contain no-repeat; mask: var(--icon, var(--icon-lock)) center / contain no-repeat; }
.chat-security[data-state=ok] { --state: var(--success); }
.chat-security[data-state=warn] { --state: var(--warning); color: var(--warning-text); }
.chat-security[data-state=error], .chat-status[data-kind=error] { --state: var(--error); --icon: var(--icon-alert); color: var(--error-text); }
.chat-statusbar .btn-quiet { font-size: var(--fs-xs); padding: 4px 10px; }
.chat-verification { padding: 0 var(--gutter); }

.chat-compose { padding: 12px var(--gutter); border-top: 1px solid var(--border); }
.chat-compose textarea { font-size: 16px; max-height: 160px; }
.chat-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.chat-actions .btn-primary { margin-left: auto; padding: 9px 14px; }
.chat-privacy { padding: 0 var(--gutter) 12px; font-size: var(--fs-xs); color: var(--text-muted); }
.chat-privacy summary { width: fit-content; padding: 4px 0; cursor: pointer; }
.chat-privacy p { margin-top: 6px; max-height: min(40dvh, 240px); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

.chat-qr { position: relative; font-size: var(--fs-xs); flex-shrink: 0; }
.chat-qr summary { cursor: pointer; color: var(--text-muted); padding: 6px; }
.chat-qr-box { position: absolute; right: 0; top: 100%; z-index: 3; width: 208px; background: var(--bg-surface); border: 1px solid var(--border); padding: 12px; }
.chat-qr img { width: 180px; height: 180px; display: block; }
.chat-qr a { overflow-wrap: anywhere; font-size: var(--fs-xs); color: var(--accent-light); }

@media (max-width: 600px) {
  .chat-page { --gutter: 16px; }
  .chat-heading h1 { grid-column: 2 / 4; }
  .chat-heading .chat-tools { grid-row: 2; }
  .chat-heading .chat-contact { min-height: 0; max-width: 11em; margin: -14px -8px; padding: 14px 8px; border: 0; font-size: var(--fs-xs); }
  .chat-heading .chat-contact:hover { background: none; text-decoration: underline; }
  .page-chat .moon { top: -110px; left: auto; right: -120px; width: 320px; }
}
@media (max-width: 600px), (max-height: 520px) {
  .page-chat .site-main { padding: 0; }
  .chat-page { width: 100%; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; }
  .chat-heading { padding: 6px var(--gutter); }
  .chat-heading h1 { font-size: 18px; line-height: 1.3; }
  .chat-heading p { line-height: 1.3; }
}
@media (max-height: 520px) {
  .chat-privacy { display: none; }
  .chat-compose { padding-block: 8px; }
  .chat-actions { margin-top: 6px; }
  .chat-statusbar { min-height: 24px; padding-block: 2px 4px; }
}
@media (pointer: coarse) {
  .btn-quiet, .chat-actions .btn-primary, .chat-contact { min-height: 44px; }
  .chat-privacy summary { min-height: 44px; display: flex; align-items: center; }
}
@media (hover: none) and (pointer: coarse) { .chat-qr { display: none; } }
@media (prefers-reduced-motion: reduce) { .chat-page * { transition: none; } .chat-typing i { animation: none; opacity: .6; } }
