/* The assistant chat panel (views/chat-panel.js) and its header
   button. A panel down the right of the screen from 769px, the whole
   screen below. Sizes in rem; 44px targets on touch screens. */

.chat-btn {
  width: 2rem; height: 2rem; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ai-cyan-text); background: var(--surface2);
  border: 1px solid var(--color-accent-border);
}
.chat-btn svg { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-btn:hover { background: var(--ai-cyan-soft); }
@media (pointer: coarse) { .chat-btn { min-width: 44px; min-height: 44px; } }

.assistant-chat-open { margin-top: 10px; }

.chat-layer[hidden] { display: none; }
.chat-layer { position: fixed; inset: 0; z-index: 900; }
.chat-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 16, 0.55); }
.chat-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(28rem, 100%); max-width: 100%;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 14px max(14px, env(safe-area-inset-bottom));
  background: var(--surface-card); color: var(--text-primary);
  border-left: 1px solid var(--color-accent-border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.45);
  transform: translateX(100%); transition: transform 0.2s ease-out;
  box-sizing: border-box;
}
.chat-layer.chat-shown .chat-panel { transform: none; }
@media (prefers-reduced-motion: reduce) { .chat-panel { transition: none; } }
@media (max-width: 768px) {
  .chat-panel { width: 100%; border-left: 0; }
  .chat-backdrop { display: none; }
}

.chat-head { display: flex; align-items: center; gap: 8px; }
.chat-title { flex: 1; min-width: 0; margin: 0; font-size: 1rem; color: var(--ai-cyan-text); overflow-wrap: anywhere; }
.chat-new { font-size: 0.75rem; padding: 4px 10px; color: var(--text-primary); }
.chat-close {
  width: 2rem; height: 2rem; padding: 0; border-radius: 50%; font-size: 1.25rem; line-height: 1;
  color: var(--text-primary); background: var(--surface2); border: 1px solid var(--surface-border);
}
@media (pointer: coarse) { .chat-close, .chat-new { min-width: 44px; min-height: 44px; } }

.chat-notice { padding: 10px 12px; border-radius: var(--radius-md); background: var(--surface-muted); border: 1px solid var(--surface-border); font-size: 0.8125rem; }
.chat-notice p { margin: 0; }
.chat-notice .chat-hint { margin-top: 6px; color: var(--text-muted); font-size: 0.75rem; }
.chat-notice.chat-setup { border-color: var(--color-amber-border); background: var(--color-amber-bg); }

.chat-log { flex: 1; min-height: 6rem; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.chat-empty { margin: auto 0; color: var(--text-muted); font-size: 0.8125rem; line-height: 1.5; }
.chat-msg { max-width: 100%; padding: 8px 10px; border-radius: var(--radius-md); font-size: 0.875rem; line-height: 1.5; }
.chat-msg .chat-who { margin: 0 0 2px; font-size: 0.75rem; color: var(--text-muted); }
.chat-msg .chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-user { align-self: flex-end; background: var(--surface-elev); }
.chat-assistant { align-self: stretch; background: var(--surface-muted); border: 1px solid var(--surface-border); }
.chat-assistant.chat-pending .chat-text { color: var(--text-muted); }
.chat-assistant.chat-error { border-color: var(--color-red-border); }

.chat-card { margin-top: 8px; padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--color-accent-border); background: var(--surface-card); }
.chat-card p { margin: 0; overflow-wrap: anywhere; }
.chat-card-title { font-size: 0.75rem; font-weight: 700; color: var(--color-accent-text); text-transform: uppercase; letter-spacing: 0.04em; }
.chat-card-line { font-size: 0.8125rem; margin-top: 2px; white-space: pre-wrap; }
.chat-card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.chat-card-q { font-size: 0.8125rem; font-weight: 600; margin-right: auto; }
.chat-card-foot .fpill { font-size: 0.8125rem; padding: 4px 12px; }
.chat-card-foot .fpill:not(.fpill-primary) { color: var(--text-primary); }
.chat-card-state { font-size: 0.8125rem; color: var(--color-accent-text); }
@media (pointer: coarse) { .chat-card-foot .fpill { min-height: 44px; } }

.chat-sent summary { cursor: pointer; font-size: 0.75rem; line-height: 1.5; color: var(--text-muted); padding: 0.25rem 0; }
@media (pointer: coarse) { .chat-sent summary { padding: 0.75rem 0; } }
.chat-sent p { margin: 6px 0 0; font-size: 0.75rem; color: var(--text-muted); line-height: 1.5; }

.chat-form { display: flex; align-items: flex-end; gap: 6px; }
.chat-input {
  flex: 1; min-width: 0; resize: none; max-height: 9rem;
  padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--surface-border);
  background: var(--surface2); color: var(--text-primary); font: inherit; font-size: 0.875rem;
}
@media (pointer: coarse) { .chat-input { font-size: 1rem; } }
.chat-mic {
  flex: none; width: 2.25rem; height: 2.25rem; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-primary); background: var(--surface2); border: 1px solid var(--surface-border);
}
.chat-mic svg { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.chat-mic.listening { color: var(--surface-bg); background: var(--ai-cyan); border-color: var(--ai-cyan); }
.chat-send { flex: none; padding: 7px 14px; }
.chat-send.chat-stop { background: var(--surface2); color: var(--text-primary); }
@media (pointer: coarse) { .chat-mic, .chat-send { min-width: 44px; min-height: 44px; } }

.chat-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.chat-speak { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-secondary); }
.chat-speak input { width: 1rem; height: 1rem; }
@media (pointer: coarse) { .chat-speak { min-height: 44px; } .chat-speak input { width: 22px; height: 22px; } }
.chat-usage { margin: 0; font-size: 0.75rem; color: var(--text-muted); }

body.chat-open { overflow: hidden; }

/* `hidden` wins over the display rules above (no feature, no mic in
   this browser, voice off). */
.chat-btn[hidden], .chat-mic[hidden], .chat-speak[hidden], .chat-notice[hidden] { display: none; }

/* No room in a phone's or narrow tablet's header: the account menu has
   "Ask the assistant" there (and Alt+A works everywhere). */
@media (max-width: 900px) { .chat-btn { display: none; } }

/* A dialog opened while the chat is open (a check-in, a notice) goes
   on top of it. */
body.chat-open .modal-overlay { z-index: 1000; }
