/**
 * AI Assistant Styles — JamWat AI
 *
 * Icon: Simple, outline-only circle with cyan accent.
 *       Intentionally still — all other icons animate.
 *       Stillness creates distinction.
 *
 * Chat Panel: Fixed bottom-right overlay.
 *             Jamaica brand (green/gold/black).
 *             Accessible: focus-trap, ARIA, 48px targets.
 *
 * Base icon size/shape from floating-icons-base.css.
 * This file: position, color, chat panel only.
 *
 * @author Yuuji Itadori (Implementation Specialist)
 * @reviewed Megumi Fushiguro (SEC-AI-001 to SEC-AI-006)
 * @version 1.0.0
 */

/* ============================================
   AI ASSISTANT ICON CONTAINER
   Positioned between profile-hub (445px) and support-us (370px).
   Sits at 445px; profile-hub shifts to 520px via body.has-ai-assistant.
   ============================================ */
.ai-assistant-container {
    bottom: 500px;
    z-index: 9850;
}

/* Icon — outline style, no fill, cyan accent */
/* Overrides the default green border from floating-icons-base.css */
.ai-assistant-icon {
    background: transparent;
    border-color: #00d9ff;
    box-shadow: none;
}

.ai-assistant-icon i {
    color: #00d9ff;
}

/* Hover: subtle fill, no motion — Nobara spec */
.ai-assistant-icon:hover {
    background: rgba(0, 217, 255, 0.12);
    border-color: #00d9ff;
    box-shadow: none;
    transform: none;
}

.ai-assistant-icon:hover i {
    color: #ffffff;
}

/* Focus: consistent with all other icons (WCAG 2.2 AA) */
.ai-assistant-icon:focus,
.ai-assistant-icon:focus-visible {
    outline: 3px solid #ffee00;
    outline-offset: 3px;
    background: rgba(0, 217, 255, 0.12);
}

/* Active state for click feedback */
.ai-assistant-icon:active {
    background: rgba(0, 217, 255, 0.25);
    transform: scale(0.95);
}

/* Mobile: same size rules handled by floating-icons-base.css */
@media (max-width: 768px) {
    .ai-assistant-container {
        bottom: 500px;
        right: 20px;
        z-index: 9850;
    }

    .ai-assistant-icon i {
        pointer-events: none;
    }
}

/* Ad-aware positioning (mirrors other icons) */
body.adsense-anchor-active .ai-assistant-container {
    bottom: calc(500px + var(--ad-offset, 0px));
}

@media (max-width: 768px) {
    body.adsense-anchor-active .ai-assistant-container {
        bottom: calc(500px + var(--ad-offset, 0px) + env(safe-area-inset-bottom, 0px));
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ai-assistant-icon {
        animation: none !important;
        transition: none !important;
    }
}

/* AI pill label — visible on all screen sizes for discoverability */
.ai-assistant-label {
    cursor: pointer;
}

/* Print: hide */
@media print {
    .ai-assistant-container,
    .ai-chat-panel,
    .ai-chat-backdrop {
        display: none !important;
    }
}


/* ============================================
   CHAT PANEL BACKDROP
   ============================================ */
.ai-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 8, 4, 0.65);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 10500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-chat-backdrop.ai-open {
    opacity: 1;
    pointer-events: auto;
}


/* ============================================
   CHAT PANEL
   ============================================ */
.ai-chat-panel {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 550px;
    height: 690px;
    background: linear-gradient(160deg, #0d1a12 0%, #0a1410 45%, #080e14 100%);
    border: 1px solid rgba(0, 217, 255, 0.18);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    z-index: 10501;
    box-shadow:
        0 0 0 1px rgba(0, 107, 42, 0.12),
        0 24px 64px rgba(0, 0, 0, 0.75),
        0 0 40px rgba(0, 107, 42, 0.07),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    opacity: 0;
    transform: translateY(24px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.32s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

/* Ambient mesh overlay */
.ai-chat-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(ellipse at 15% 10%, rgba(0, 107, 42, 0.09) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 85%, rgba(0, 217, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
    border-radius: 20px;
}

.ai-chat-panel > * {
    position: relative;
    z-index: 1;
}

.ai-chat-panel.ai-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}


/* ============================================
   PANEL HEADER
   ============================================ */
.ai-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, #004d1e 0%, #006b2a 50%, #003d16 100%);
    border-radius: 20px 20px 0 0;
    border-bottom: 2px solid #ffb400;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Header shimmer sweep */
.ai-chat-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: -120%;
    width: 60%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    animation: aiHeaderShimmer 5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes aiHeaderShimmer {
    0%   { left: -120%; }
    45%  { left: 160%;  }
    100% { left: 160%;  }
}

.ai-chat-header-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1.5px solid rgba(0, 217, 255, 0.45);
    background: rgba(0, 217, 255, 0.07);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 14px rgba(0, 217, 255, 0.12), inset 0 0 8px rgba(0, 217, 255, 0.04);
    position: relative;
    z-index: 1;
}

.ai-chat-header-icon i {
    font-size: 16px;
    color: #00d9ff;
}

.ai-chat-title {
    flex: 1;
    position: relative;
    z-index: 1;
}

.ai-chat-title h3 {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

/* Pulsing online dot before title */
.ai-chat-title h3::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #00ff6a;
    border-radius: 50%;
    margin-right: 7px;
    vertical-align: middle;
    box-shadow: 0 0 6px rgba(0, 255, 106, 0.8);
    animation: aiOnlinePulse 2.2s ease-in-out infinite;
}

@keyframes aiOnlinePulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(0, 255, 106, 0.8); }
    50%       { opacity: 0.6; box-shadow: 0 0 12px rgba(0, 255, 106, 0.3); }
}

.ai-chat-title span {
    font-size: 11px;
    color: rgba(255, 180, 0, 0.82);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.ai-chat-close {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.65);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
    line-height: 1;
    position: relative;
    z-index: 1;
}

.ai-chat-close:hover {
    background: rgba(255, 70, 70, 0.14);
    border-color: rgba(255, 80, 80, 0.28);
    color: #ff9090;
}

.ai-chat-close:focus-visible {
    outline: 3px solid #ffee00;
    outline-offset: 2px;
}


/* ============================================
   MESSAGE AREA
   ============================================ */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 3px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 107, 42, 0.35);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 155, 58, 0.55);
}

/* Message bubbles */
.ai-msg {
    max-width: 86%;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: aiMsgIn 0.22s ease-out;
}

/* AI msg inside row: row handles max-width and animation */
.ai-msg-row .ai-msg {
    max-width: none;
    animation: none;
}

@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.ai-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #ffb400 0%, #ffc933 100%);
    color: #1a0e00;
    border-radius: 16px 16px 4px 16px;
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(255, 180, 0, 0.22);
}

.ai-msg-ai {
    align-self: flex-start;
    background: rgba(20, 30, 22, 0.85);
    color: #ddeedd;
    border: 1px solid rgba(0, 107, 42, 0.22);
    border-left: 3px solid #00d9ff;
    border-radius: 4px 16px 16px 16px;
}

.ai-msg-ai strong {
    color: #00d9ff;
    font-weight: 600;
}

.ai-msg-ai ol,
.ai-msg-ai ul {
    margin: 6px 0;
    padding-left: 22px;
}

.ai-msg-ai li {
    margin-bottom: 3px;
}

.ai-msg-ai em {
    color: #a8d8a8;
}

/* Error state (SEC-AI-011: style via CSS, not inline JS) */
.ai-msg-error {
    color: #ff6b6b;
    border-color: #5a1a1a;
}

/* Inline code in AI messages (SEC-AI-011: style via CSS, not inline attr) */
.ai-msg-ai code {
    background: rgba(0, 217, 255, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}

/* Links in AI messages (SEC-AI-011: style via CSS, not inline attr) */
.ai-msg-ai a {
    color: #00d9ff;
    text-decoration: underline;
    word-break: break-all;
}
.ai-msg-ai a:hover {
    color: #66e8ff;
}

/* AI message row — naturally sized to bubble, copy button overlaid (not in flow) */
.ai-msg-row {
    position: relative;
    display: inline-flex;
    align-self: flex-start;
    max-width: 88%;
    animation: aiMsgIn 0.22s ease-out;
}

/* Bubble fills the row; padding-right reserves space under the copy overlay */
.ai-msg-row .ai-msg-ai {
    flex: 1;
    min-width: 0;
    padding-right: 26px;
    animation: none;
}

/* Copy icon — small overlay at top-right of bubble, no layout impact */
.ai-copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 10px;
    background: rgba(10, 20, 12, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: rgba(0, 217, 255, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
    line-height: 1;
}

.ai-msg-row:hover .ai-copy-btn {
    opacity: 1;
}

/* Touch devices: always show at reduced opacity (no hover available) */
@media (pointer: coarse) {
    .ai-copy-btn {
        opacity: 0.6;
    }
}

.ai-copy-btn:hover {
    color: #00d9ff;
    background: rgba(0, 217, 255, 0.12);
}

.ai-copy-btn:focus-visible {
    outline: 2px solid #ffb400;
    outline-offset: 2px;
    opacity: 1;
}

.ai-copy-btn.ai-copy-success {
    color: #00ff6a;
    opacity: 1;
}

/* Typing indicator */
.ai-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: rgba(20, 30, 22, 0.85);
    border: 1px solid rgba(0, 107, 42, 0.22);
    border-left: 3px solid #00d9ff;
    border-radius: 4px 16px 16px 16px;
    animation: aiMsgIn 0.22s ease-out;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    animation: aiTypingBounce 1.4s ease-in-out infinite;
}

.ai-typing span:nth-child(1) { background: #009b3a; }
.ai-typing span:nth-child(2) { background: #00c44a; animation-delay: 0.18s; }
.ai-typing span:nth-child(3) { background: #00d9ff; animation-delay: 0.36s; }

@keyframes aiTypingBounce {
    0%, 70%, 100% { transform: translateY(0) scale(1);    opacity: 0.45; }
    35%            { transform: translateY(-8px) scale(1.15); opacity: 1;    }
}

/* Welcome message */
.ai-welcome {
    text-align: center;
    padding: 22px 12px 10px;
    color: #6a8a6a;
    font-size: 13px;
    line-height: 1.6;
}

.ai-welcome i {
    font-size: 34px;
    color: #00d9ff;
    display: block;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 10px rgba(0, 217, 255, 0.55));
    animation: aiWelcomePulse 3.5s ease-in-out infinite;
}

@keyframes aiWelcomePulse {
    0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 10px rgba(0, 217, 255, 0.55)); }
    50%       { transform: scale(1.06); filter: drop-shadow(0 0 18px rgba(0, 217, 255, 0.85)); }
}

.ai-welcome p {
    margin: 0 0 5px;
}

.ai-welcome p:first-of-type {
    color: #c0e8c0;
    font-weight: 600;
    font-size: 14px;
}

.ai-disclaimer {
    margin-top: 10px !important;
    font-size: 11px;
    color: #888;
    font-style: italic;
    opacity: 0.85;
}


/* ============================================
   QUICK PROMPT CHIPS
   ============================================ */
.ai-quick-prompts {
    padding: 0 14px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    flex-shrink: 0;
}

.ai-chip {
    padding: 6px 13px;
    border: 1px solid rgba(0, 155, 58, 0.38);
    border-radius: 20px;
    background: rgba(0, 107, 42, 0.14);
    color: #98cc98;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.16s ease;
    white-space: nowrap;
    font-weight: 500;
}

.ai-chip:hover {
    background: rgba(0, 155, 58, 0.28);
    border-color: #009b3a;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0, 107, 42, 0.28);
}

.ai-chip:active {
    transform: translateY(0);
}

.ai-chip:focus-visible {
    outline: 2px solid #ffee00;
    outline-offset: 2px;
}


/* ============================================
   INPUT AREA
   ============================================ */
.ai-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px 14px;
    border-top: 1px solid rgba(0, 107, 42, 0.18);
    background: rgba(6, 12, 8, 0.55);
    flex-shrink: 0;
    border-radius: 0 0 20px 20px;
}

.ai-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 107, 42, 0.28);
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 13.5px;
    color: #e4ede4;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 90px;
    overflow-y: auto;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input::placeholder {
    color: rgba(100, 145, 100, 0.45);
}

.ai-chat-input:focus {
    border-color: #00d9ff;
    background: rgba(0, 217, 255, 0.04);
    box-shadow: 0 0 0 3px rgba(0, 217, 255, 0.07);
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #006b2a, #009b3a);
    color: #ffffff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 3px 12px rgba(0, 107, 42, 0.38);
}

.ai-chat-send:hover {
    background: linear-gradient(135deg, #008535, #00c44a);
    transform: translateY(-1px);
    box-shadow: 0 5px 18px rgba(0, 155, 58, 0.48);
}

.ai-chat-send:active {
    transform: scale(0.93) translateY(0);
    box-shadow: 0 2px 8px rgba(0, 107, 42, 0.28);
}

.ai-chat-send:disabled {
    background: rgba(25, 45, 30, 0.55);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ai-chat-send:focus-visible {
    outline: 3px solid #ffee00;
    outline-offset: 2px;
}

/* Character counter */
.ai-char-count {
    font-size: 10.5px;
    color: rgba(90, 130, 90, 0.5);
    text-align: right;
    padding: 0 14px 6px;
    flex-shrink: 0;
}

.ai-char-count.ai-near-limit {
    color: #ffb400;
}


/* ============================================
   MOBILE — Full screen panel
   ============================================ */
@media (max-width: 768px) {
    .ai-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        border-radius: 0;
        border-bottom: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

}

@media (prefers-reduced-motion: reduce) {
    .ai-chat-panel,
    .ai-chat-backdrop,
    .ai-typing span,
    .ai-chat-header::after,
    .ai-chat-title h3::before,
    .ai-welcome i,
    .ai-msg {
        transition: none !important;
        animation: none !important;
    }
}
