/* AI Insurance Agent chat. Reuses app tokens; dark-mode via body.dark-mode. */

.ag-header { padding: 16px 20px 0; }
.ag-main { padding: 12px 20px 24px; }

.ag-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 1px 4px var(--shadow); }
.ag-chat-card { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; }

.ag-card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ag-card-icon { font-size: 18px; }
.ag-card-title { font-weight: 700; }
.ag-status { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }
.ag-clear { margin-left: auto; }

.ag-btn {
    background: var(--bg-input); color: var(--text); border: 1px solid var(--border-strong);
    border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.ag-btn:hover { border-color: var(--apple-blue); }

/* Messages */
.ag-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.ag-msg { max-width: 80%; padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.ag-msg-user { align-self: flex-end; background: var(--accent-on-fill); color: #fff; border-bottom-right-radius: 4px; }
.ag-msg-ai { align-self: flex-start; background: var(--bg-input); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ag-msg code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.ag-code { background: rgba(127,127,127,.14); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; white-space: pre-wrap; }

/* Typing indicator — reuses the shared vmDotPulse keyframe (css/animations.css) */
.ag-typing { display: flex; gap: 5px; align-items: center; }
.ag-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-secondary); animation: vmDotPulse 1.2s infinite both; }
.ag-dot:nth-child(2) { animation-delay: .2s; }
.ag-dot:nth-child(3) { animation-delay: .4s; }

/* Citations */
.ag-citations { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.ag-cite-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); margin-bottom: 4px; }
.ag-citations ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ag-citations li { font-size: 12.5px; display: flex; gap: 6px; align-items: baseline; }
.ag-cite-n { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.ag-citations button { background: none; border: none; padding: 0; font: inherit; color: var(--text); text-align: left; cursor: default; }
.ag-cite-link { color: var(--apple-blue-hover) !important; cursor: pointer !important; text-decoration: underline; }

/* Email draft card */
.ag-email-card { margin-top: 10px; background: var(--bg-card); border: 1px solid var(--apple-blue); border-radius: 12px; padding: 12px; }
.ag-email-head { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.ag-email-note { font-weight: 400; font-size: 11px; color: var(--warning-text); margin-left: 6px; }
.ag-email-row { display: flex; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.ag-email-row span:first-child { color: var(--text-secondary); min-width: 56px; }
.ag-email-body { font-size: 13px; line-height: 1.5; margin: 8px 0; padding: 10px; background: var(--bg-input); border-radius: 8px; white-space: normal; }
.ag-email-actions { display: flex; gap: 8px; }

/* Confirmation-gated action card (Phase 2 — writes never auto-run) */
.ag-action-card { margin-top: 10px; background: var(--bg-card); border: 1px solid var(--warning, #ff9f0a); border-radius: 12px; padding: 12px; }
.ag-action-card.is-done { border-color: var(--success, #32d74b); color: var(--text-secondary); font-size: 13px; }
.ag-action-check { color: var(--success, #32d74b); font-weight: 700; }
.ag-action-label { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.ag-action-note { font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; }
.ag-action-actions { display: flex; gap: 8px; }
.ag-btn-primary { background: var(--accent-on-fill); color: #fff; border-color: var(--accent-on-fill); }

/* Input */
.ag-context { margin: 0 16px; background: var(--bg-input); color: var(--text); border: 1px solid var(--apple-blue); border-radius: 10px; padding: 10px; font-size: 13px; resize: vertical; }
.ag-input-row { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.ag-context-toggle { white-space: nowrap; }
.ag-context-toggle[aria-pressed="true"] { background: var(--accent-on-fill); color: #fff; border-color: var(--accent-on-fill); }
.ag-input {
    flex: 1; resize: none; background: var(--bg-input); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px;
    font-family: inherit; line-height: 1.4; max-height: 140px;
}
.ag-input:focus { border-color: var(--apple-blue); }
/* Visible keyboard focus on every control (WCAG 2.4.7/2.4.11) — house pattern. */
.ag-input:focus-visible,
.ag-send-btn:focus-visible,
.ag-btn:focus-visible,
.ag-starter:focus-visible,
.ag-sess-btn:focus-visible,
.ag-context-toggle:focus-visible,
.ag-cite-link:focus-visible,
.ag-msg-copy:focus-visible,
.ag-msg-retry:focus-visible,
.ag-select:focus-visible {
    outline: 2px solid var(--apple-blue);
    outline-offset: 2px;
}
.ag-send-btn {
    flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
    background: var(--accent-on-fill); color: #fff; border: none; display: flex; align-items: center; justify-content: center;
}
.ag-send-btn:disabled { opacity: .5; cursor: default; }
.ag-disclaimer { padding: 0 16px 12px; font-size: 11px; color: var(--text-secondary); }

/* Starter prompts (empty state) */
.ag-starters { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; margin-top: 4px; }
.ag-starter {
    background: var(--bg-input); color: var(--text); border: 1px solid var(--border-strong);
    border-radius: 14px; padding: 8px 12px; font-size: 13px; cursor: pointer; text-align: left;
}
.ag-starter:hover { border-color: var(--apple-blue); }

/* Ref-less citation (no false affordance) */
.ag-cite-static { color: var(--text); }

/* Copy-on-answer */
.ag-msg-actions { margin-top: 8px; display: flex; justify-content: flex-end; }
.ag-msg-copy {
    background: none; border: 1px solid var(--border); color: var(--text-secondary);
    border-radius: 8px; padding: 3px 10px; font-size: 11px; cursor: pointer;
}
.ag-msg-copy:hover { border-color: var(--apple-blue); color: var(--text); }
.ag-msg-retry {
    background: none; border: 1px solid var(--border-strong); color: var(--apple-blue-hover);
    border-radius: 8px; padding: 3px 10px; font-size: 12px; cursor: pointer;
}
.ag-msg-retry:hover { border-color: var(--apple-blue); }

/* Send button flips to Stop while a turn runs */
.ag-send-btn.is-stop { background: var(--danger, #ff453a); border-color: var(--danger, #ff453a); color: #fff; }

/* In-DOM confirm/prompt (keeps focus inside the modal) */
.ag-dialog-overlay {
    position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .45); padding: 20px;
}
.ag-dialog {
    width: min(360px, 100%); background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px; box-shadow: 0 16px 48px var(--shadow);
}
.ag-dialog-title { font-weight: 700; font-size: 15px; color: var(--text); }
.ag-dialog-msg { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.ag-dialog-input {
    width: 100%; margin-top: 12px; padding: 8px 10px; font-size: 14px; color: var(--text);
    background: var(--bg-input); border: 1px solid var(--border-strong); border-radius: 8px;
}
.ag-dialog-input:focus-visible { outline: 2px solid var(--apple-blue); outline-offset: 2px; }
.ag-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Attachment chips */
.ag-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.ag-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text);
    background: var(--bg-input); border: 1px solid var(--border-strong); border-radius: 14px; padding: 4px 8px 4px 10px;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ag-chip-x {
    background: none; border: none; color: var(--text-secondary); cursor: pointer;
    font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.ag-chip-x:hover { color: var(--danger); }
.ag-chip-x:focus-visible { outline: 2px solid var(--apple-blue); outline-offset: 2px; }

/* States & trust */
.ag-notice {
    align-self: stretch; margin: 0 0 4px; padding: 8px 12px; font-size: 12px; line-height: 1.4;
    color: var(--text); background: var(--bg-input);
    border: 1px solid var(--warning-text); border-radius: 10px;
}
.ag-msg-time { margin-top: 4px; font-size: 10px; color: var(--text-tertiary); text-align: right; }
.ag-msg-user .ag-msg-time { color: rgba(255, 255, 255, .7); }
.ag-cite-type { font-size: 11px; }

/* Multi-session thread bar */
.ag-session-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.ag-select {
    flex: 1 1 auto; min-width: 0; background: var(--bg-input); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 8px; padding: 5px 8px; font-size: 12px;
}
.ag-sess-btn {
    flex: 0 0 auto; background: var(--bg-input); color: var(--text); border: 1px solid var(--border-strong);
    border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.ag-sess-btn:hover { border-color: var(--apple-blue); }
.ag-sess-icon { padding: 5px 8px; }

/* Microinteractions — state-change easing + press feedback (motion-safe only). */
@media (prefers-reduced-motion: no-preference) {
    .ag-btn, .ag-starter, .ag-sess-btn, .ag-select, .ag-msg-copy, .ag-msg-retry,
    .ag-context-toggle, .ag-send-btn, .ag-cite-link {
        transition: background-color .15s var(--transition-smooth),
                    border-color .15s var(--transition-smooth),
                    color .15s var(--transition-smooth);
    }
    .ag-send-btn { transition-duration: .18s; } /* covers the Send→Stop fill swap */
    .ag-btn:active, .ag-starter:active, .ag-sess-btn:active,
    .ag-msg-copy:active, .ag-msg-retry:active, .ag-context-toggle:active { transform: scale(.96); }
    .ag-send-btn:active { transform: scale(.94); }
}
