/* AI Assistant — used by both the dedicated page (Pages/AIAgent.html) and the
   floating widget (Site.html). Brand color sourced from css/themes/touch-accent.fleetsoft.json. */

:root {
    --ai-agent-brand: #004084;
    --ai-agent-brand-dark: #002d5c;
}

/* Floating launcher — see AIAgent.js's floating-widget bootstrap for the
   canUse/mount logic. Hidden by default; shown only once that check passes. */
.AIAgentLauncherButton {
    display: none;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    /* Bottom-right, above the bottom bar — the standard placement. Cleared further than just
       the tab bar (~68px) since a grid with totals adds its own fixed footer row above that. */
    bottom: calc(130px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--ai-agent-brand);
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(0,30,70,0.28);
    font-size: 24px;
    cursor: pointer;
    /* Below the touch UI's own overlays (popups/panels go up to z-index 1101 in touch-core.css)
       so idle, e.g. the "More" menu still shows above this button when it's not in use. */
    z-index: 500;
}

.AIAgentLauncherButton:hover {
    background: var(--ai-agent-brand-dark);
}

.AIAgentFloatingPanel {
    display: none;
    position: fixed;
    right: 16px;
    bottom: calc(194px + env(safe-area-inset-bottom, 0px));
    width: 380px;
    height: min(600px, calc(100vh - 230px));
    /* Above ordinary page chrome (e.g. a page's own sticky toolbar) once actually opened —
       unlike the launcher, this only exists while the user deliberately has it open. */
    z-index: 9999;
}

.AIAgentFloatingPanel.open {
    display: block;
}

.AIAgentFloatingContainer {
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    background: #fff;
    border: 1px solid #e1e3e8;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,30,70,0.24);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    color: #23262b;
}

/* Full-screen below 768px — there's no room to dock beside content, so it takes
   over the viewport the way WhatsApp/iMessage do, rather than staying cramped. */
@media (max-width: 768px) {
    .AIAgentFloatingPanel {
        top: 0;
        right: 0;
        bottom: 0;
        transform: none;
        width: 100%;
        height: 100%;
    }

    .AIAgentFloatingContainer {
        border-radius: 0;
    }
}

.AIAgentPageWrapper {
    padding: 16px;
}

/* Hides a stray injected <footer> (not Site.html's own page-footer),
   scoped to this page only — other pages still show it normally. */
body:has(.AIAgentPageContainer) footer:has(.container) {
    display: none !important;
}

.AIAgentPageWrapper .DataViewHeader {
    margin-bottom: 12px;
}

.AIAgentPageContainer {
    display: flex;
    flex-direction: column;
    position: relative;
    /* Fixed height, not dynamic — "fill available space" sizing kept overflowing. */
    height: 480px;
    background: #fff;
    border: 1px solid #e1e3e8;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,30,70,0.10);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    color: #23262b;
}

/* Header */

.AIAgentHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--ai-agent-brand), var(--ai-agent-brand-dark));
    color: #fff;
    padding: 12px 16px;
    flex-shrink: 0;
}

.AIAgentTitle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
}

.AIAgentTitleBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.AIAgentHeaderActions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.AIAgentHeaderActions button {
    background: rgba(255,255,255,0.14);
    border: 1px solid rgba(255,255,255,0.32);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.AIAgentHistoryButton,
.AIAgentPopOutButton,
.AIAgentCloseButton {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px !important;
}

.AIAgentHeaderActions button:hover {
    background: rgba(255,255,255,0.26);
}

/* Message list */

.AIAgentMessages {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
    background: #f6f7f9;
    gap: 12px;
}

.AIAgentEmptyState {
    margin: auto;
    text-align: center;
    color: #6b7280;
    padding: 24px;
    max-width: 300px;
}

.AIAgentEmptyIcon {
    width: 40px;
    height: 40px;
    line-height: 40px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: #e6edf5;
    color: var(--ai-agent-brand);
    font-size: 12px;
    font-weight: 700;
}

.AIAgentEmptyState p {
    margin: 4px 0;
}

.AIAgentEmptyHint {
    font-size: 12px;
    color: #9aa0a8;
}

.AIAgentRow {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: AIAgentFadeIn 0.18s ease-out;
}

.AIAgentRow.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.AIAgentRow.assistant {
    align-self: flex-start;
}

.AIAgentAvatar {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    border-radius: 50%;
    background: var(--ai-agent-brand);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}

.AIAgentBubbleWrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.AIAgentRow.user .AIAgentBubbleWrap {
    align-items: flex-end;
}

.AIAgentBubble {
    padding: 9px 12px;
    border-radius: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.45;
}

.AIAgentBubble code {
    background: rgba(0,0,0,0.06);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: Consolas, "SFMono-Regular", Menlo, monospace;
    font-size: 12.5px;
}

.AIAgentHeading {
    font-size: 12px;
    font-weight: 700;
    color: #4b5563;
    margin: 10px 0 2px;
}

.AIAgentHeading:first-child {
    margin-top: 0;
}

.AIAgentTableWrap {
    overflow-x: auto;
    margin: 6px 0;
    max-width: 100%;
}

.AIAgentTable {
    border-collapse: collapse;
    font-size: 12px;
}

.AIAgentTable th,
.AIAgentTable td {
    border: 1px solid #e5e7eb;
    padding: 4px 8px;
    text-align: left;
    white-space: nowrap;
}

.AIAgentTable th {
    background: #f6f7f9;
    font-weight: 600;
}

/* Generic "- " bullet list fallback (reference-lookup options now render as a table above). */

.AIAgentList {
    list-style: none;
    margin: 6px 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
}

.AIAgentList li {
    position: relative;
    padding: 5px 0 5px 14px;
    line-height: 1.4;
    /* Caps any one item to 2 lines so an unusually long value (bad data, a long
       name) can't visually dominate the list — normal-length items are unaffected. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.AIAgentList li:not(:last-child) {
    border-bottom: 1px solid #f0f1f3;
}

.AIAgentList li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ai-agent-brand);
}

/* Pending-action confirm card — a proposed write awaiting the user's click. */

.AIAgentRow.continuation {
    margin-top: -8px;
}

.AIAgentActionCard {
    background: #fff;
    border: 1px solid #e1e3e8;
    border-top: 3px solid var(--ai-agent-brand);
    border-radius: 10px;
    padding: 12px 14px;
    /* Fixed, not just capped — .AIAgentBubbleWrap (a column flex container) otherwise
       stretches this to whatever its shortest sibling line needs, shrinking it. */
    width: 360px;
    max-width: 100%;
    box-shadow: 0 1px 4px rgba(0,30,70,0.08);
}

.AIAgentActionCardTitle {
    font-weight: 700;
    font-size: 12.5px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    color: var(--ai-agent-brand);
    margin-bottom: 8px;
}

.AIAgentActionCardFields {
    margin-bottom: 12px;
}

.AIAgentActionCardSection {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #9ca3af;
    padding: 10px 0 4px;
}

.AIAgentActionCardSection:first-child {
    padding-top: 0;
}

.AIAgentActionCardField {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 12.5px;
}

.AIAgentActionCardField:last-child {
    border-bottom: none;
}

.AIAgentActionCardFieldLabel {
    color: #6b7280;
    white-space: nowrap;
}

.AIAgentActionCardFieldValue {
    font-weight: 600;
    color: #23262b;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.AIAgentActionCardButtons {
    display: flex;
    gap: 8px;
}

.AIAgentActionCardButtons button {
    flex: 1;
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 7px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.AIAgentActionCardButtons button:disabled {
    opacity: 0.55;
    cursor: default;
}

/* Extra .AIAgentActionCard qualifier boosts specificity so the site's own global
   button styling (loaded after this file) can't override our text color. */
.AIAgentActionCard .AIAgentActionCardConfirm {
    background: var(--ai-agent-brand);
    color: #fff !important;
}

.AIAgentActionCard .AIAgentActionCardConfirm:hover:not(:disabled) {
    background: var(--ai-agent-brand-dark);
    color: #fff !important;
}

.AIAgentActionCard .AIAgentActionCardCancel {
    background: #fff;
    color: #4b5563 !important;
    border-color: #c9ccd2;
}

.AIAgentActionCard .AIAgentActionCardCancel:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #9aa0a8;
    color: #4b5563 !important;
}

.AIAgentActionCardStatus {
    font-size: 12.5px;
    color: #6b7280;
}

.AIAgentRow.user .AIAgentBubble {
    background: var(--ai-agent-brand);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.AIAgentRow.user .AIAgentBubble code {
    background: rgba(255,255,255,0.18);
}

.AIAgentRow.assistant .AIAgentBubble {
    background: #fff;
    color: #23262b;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.AIAgentRow.assistant.error .AIAgentBubble {
    background: #fdf2f2;
    color: #b3261e;
    border-color: #f3c6c4;
}

.AIAgentTime {
    font-size: 10px;
    color: #9aa0a8;
    margin-top: 3px;
    padding: 0 2px;
}

.AIAgentTypingBubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
}

.AIAgentTypingBubble span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b6bac2;
    animation: AIAgentTypingBounce 1.1s infinite ease-in-out;
}

.AIAgentTypingBubble span:nth-child(2) {
    animation-delay: 0.15s;
}

.AIAgentTypingBubble span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes AIAgentTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes AIAgentFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Input row */

.AIAgentInputRow {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border-top: 1px solid #e5e7eb;
    padding: 10px 12px;
    background: #fff;
    flex-shrink: 0;
}

.AIAgentInput {
    flex: 1;
    box-sizing: border-box;
    resize: none;
    border: 1px solid #d7d9de;
    border-radius: 18px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    min-height: 36px;
    max-height: 80px;
    overflow-y: auto;
    transition: border-color 0.15s ease;
}

.AIAgentInput:disabled {
    background: #f6f7f9;
    color: #9aa0a8;
}

.AIAgentInput:focus {
    outline: none;
    border-color: var(--ai-agent-brand);
}

.AIAgentSend {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--ai-agent-brand);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s ease;
}

.AIAgentSend:hover:not(:disabled) {
    background: var(--ai-agent-brand-dark);
}

.AIAgentSend:disabled {
    background: #a9bdd6;
    cursor: default;
}

/* Conversation history drawer — slides in over the message list, per the
   in-panel "drawer" pattern used for compact/embedded chat widgets. */

.AIAgentDrawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 78%;
    max-width: 320px;
    background: #fff;
    border-left: 1px solid #e1e3e8;
    box-shadow: -4px 0 16px rgba(0,30,70,0.12);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.AIAgentDrawer.open {
    transform: translateX(0);
}

.AIAgentDrawerHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #f6f7f9;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.AIAgentDrawerClose {
    background: transparent;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
}

.AIAgentDrawerList {
    flex: 1;
    overflow-y: auto;
}

.AIAgentDrawerLoading {
    padding: 20px 14px;
    color: #9aa0a8;
    font-size: 12.5px;
    text-align: center;
}

.AIAgentDrawerItem {
    border-bottom: 1px solid #f0f1f3;
}

.AIAgentDrawerItemRow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.12s ease;
}

.AIAgentDrawerItemRow:hover {
    background: #f6f7f9;
}

.AIAgentDrawerConfirmRow {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #fdf2f2;
}

.AIAgentDrawerItem.confirming .AIAgentDrawerItemRow {
    display: none;
}

.AIAgentDrawerItem.confirming .AIAgentDrawerConfirmRow {
    display: flex;
}

.AIAgentDrawerConfirmText {
    flex: 1;
    font-size: 12.5px;
    color: #7a2620;
}

.AIAgentDrawerConfirmRow button {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
}

.AIAgentDrawerConfirmYes {
    background: #b3261e;
    color: #fff;
}

.AIAgentDrawerConfirmNo {
    background: #fff;
    color: #6b7280;
    border-color: #d7d9de;
}

.AIAgentDrawerItemText {
    min-width: 0;
    flex: 1;
}

.AIAgentDrawerItemTitle {
    font-size: 13px;
    color: #23262b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.AIAgentDrawerItemTime {
    font-size: 11px;
    color: #9aa0a8;
    margin-top: 2px;
}

.AIAgentDrawerItemDelete {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: #b3261e;
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.12s ease;
}

.AIAgentDrawerItemDelete:hover {
    opacity: 1;
}
