.portfolio-chat { text-align: left; }
.portfolio-chat, .portfolio-chat * { box-sizing: border-box; }
.portfolio-chat [hidden] { display: none !important; }
.chat-panel {
  position: fixed; inset: auto max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) auto;
  margin: 0; padding: 0; width: min(420px, calc(100vw - 40px)); max-width: none;
  height: min(640px, calc(100dvh - 40px)); max-height: calc(100dvh - 40px);
  overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); font: inherit; z-index: 100;
}
.chat-panel[open] { display: flex; flex-direction: column; }
.chat-panel::backdrop { background: color-mix(in srgb, var(--bg) 72%, transparent); }
.chat-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.chat-heading h2 { font-family: var(--font-display, inherit); font-weight: 600; margin: 0; font-size: 1.2rem; color: var(--ink); }
.chat-heading p { margin: 2px 0 0; color: var(--mu); font-size: .8rem; }
.chat-close { border: 1px solid var(--line); border-radius: 50%; width: 44px; height: 44px; flex: 0 0 44px; background: var(--card); color: var(--ink); font: inherit; font-size: 1.6rem; cursor: pointer; }
.chat-log { flex: 1; min-height: 70px; overflow-y: auto; overscroll-behavior: contain; padding: 16px; scroll-behavior: auto; }
.chat-message { margin: 0 22px 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); overflow-wrap: anywhere; }
.chat-message--visitor { margin: 0 0 14px 22px; background: var(--bg2); }
.chat-speaker { color: var(--mu); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.chat-message p { margin: 4px 0 0; font: inherit; line-height: 1.5; }
.chat-message a { display: inline-block; color: var(--cy); margin: 8px 16px 0 0; text-decoration: underline; text-underline-offset: 3px; }
.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 8px; }
.chat-chips button { min-height: 44px; max-width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); font: inherit; font-size: .8rem; background: var(--bg2); color: var(--ink); cursor: pointer; text-align: left; }
.chat-form { display: flex; align-items: stretch; gap: 8px; padding: 8px 16px 12px; border-top: 1px solid var(--line); }
.chat-form input { width: 100%; min-width: 0; min-height: 46px; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: var(--card); color: var(--ink); font: inherit; font-size: 16px; }
.chat-form input::placeholder { color: var(--mu); opacity: 1; }
.chat-form button { min-height: 46px; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: var(--cy); color: var(--on-cy); font: inherit; font-weight: 600; cursor: pointer; }
.chat-form button:disabled, .chat-chips button:disabled { opacity: .65; cursor: wait; }
.chat-status { min-height: 1.2em; margin: 0; padding: 0 16px 4px; color: var(--mu); font-size: .75rem; }
.chat-note { margin: 0; padding: 0 16px 12px; color: var(--mu); font-size: .72rem; }
.portfolio-chat :focus-visible { outline: 3px solid var(--cy); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (max-width: 600px) {
  .chat-panel { inset: auto 0 0; width: 100%; height: min(760px, 94dvh); max-height: 94dvh; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .chat-heading, .chat-log { padding: 12px; }
  .chat-form, .chat-chips { padding-inline: 12px; }
}
@media (max-height: 540px) {
  .chat-chips, .chat-note, .chat-heading p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-log { scroll-behavior: auto; }
}
