/* =====================================================
   client/css/anna.css
   Date created: 2026-03-09
   Last edited:  2026-03-20
   Summary: Aná AI Assistant — visual identity + tray UI.
            State-driven CSS animations for the Anna orb.
            Slide-up chat tray with backdrop.
            GPU-composited, iOS-safe.
   ===================================================== */

/* =======================================================
   CSS CUSTOM PROPERTIES
   ======================================================= */
:root {
    --anna-color-primary: #a78bfa;
    --anna-color-secondary: #f59e0b;
    --anna-color-glow: rgba(167, 139, 250, 0.25);
    --anna-color-core: radial-gradient(circle, #ffffff 0%, #a78bfa 40%, #7c3aed 100%);
}

/* =======================================================
   ANNA ORB — the visual trigger in the header
   ======================================================= */
#annaHeaderBtn {
    position: relative;
    background: transparent;
}

.anna-orb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* -------------------------------------------------------
   GLOW — ambient aura behind Anna
   ------------------------------------------------------- */
.anna-orb .anna-glow {
    position: absolute;
    top: -25%;
    right: -25%;
    bottom: -25%;
    left: -25%;
    border-radius: 50%;
    background: radial-gradient(circle, var(--anna-color-glow) 0%, transparent 70%);
    opacity: 0.4;
    animation: annaGlowPulse 4s ease-in-out infinite;
    -webkit-animation: annaGlowPulse 4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes annaGlowPulse {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50%      { transform: scale(1.15); opacity: 0.6; }
}

/* -------------------------------------------------------
   RING — orbit around the core
   ------------------------------------------------------- */
.anna-orb .anna-ring {
    position: absolute;
    top: -5%;
    right: -5%;
    bottom: -5%;
    left: -5%;
    border-radius: 50%;
    border: 1.5px solid var(--anna-color-primary);
    opacity: 0.3;
    animation: annaRingSpin 12s linear infinite;
    -webkit-animation: annaRingSpin 12s linear infinite;
    pointer-events: none;
}

@keyframes annaRingSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* -------------------------------------------------------
   CORE — Anna's heart
   ------------------------------------------------------- */
.anna-orb .anna-core {
    position: absolute;
    width: 50%;
    height: 50%;
    border-radius: 50%;
    background: var(--anna-color-core);
    box-shadow:
        0 0 15px rgba(167, 139, 250, 0.4),
        0 0 40px rgba(167, 139, 250, 0.15);
    animation: annaCorePulse 4s ease-in-out infinite;
    -webkit-animation: annaCorePulse 4s ease-in-out infinite;
    z-index: 2;
    transition: background 0.6s ease, box-shadow 0.6s ease;
}

.anna-orb .anna-core-inner {
    position: absolute;
    top: 20%;
    right: 20%;
    bottom: 20%;
    left: 20%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.1) 70%);
    animation: annaCoreInnerPulse 4s ease-in-out infinite;
    -webkit-animation: annaCoreInnerPulse 4s ease-in-out infinite;
    animation-delay: -0.5s;
}

@keyframes annaCorePulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

@keyframes annaCoreInnerPulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.1); }
}

/* =======================================================
   ORB STATES
   ======================================================= */

/* ------- IDLE — calm, breathing ------- */
.anna-orb.anna-idle .anna-glow {
    animation: annaGlowPulse 5s ease-in-out infinite;
}
.anna-orb.anna-idle .anna-ring {
    opacity: 0.2;
    animation: annaRingSpin 20s linear infinite;
}
.anna-orb.anna-idle .anna-core {
    animation: annaCorePulse 5s ease-in-out infinite;
}

/* ------- LISTENING — user is typing ------- */
.anna-orb.anna-listening .anna-glow {
    opacity: 0.55;
    animation: annaGlowPulse 2.5s ease-in-out infinite;
}
.anna-orb.anna-listening .anna-ring {
    opacity: 0.45;
    animation: annaRingSpin 6s linear infinite;
}
.anna-orb.anna-listening .anna-core {
    animation: annaCorePulse 2.5s ease-in-out infinite;
}

/* ------- THINKING — waiting for AI ------- */
.anna-orb.anna-thinking .anna-glow {
    opacity: 0.7;
    animation: annaGlowPulse 1.5s ease-in-out infinite;
}
.anna-orb.anna-thinking .anna-ring {
    opacity: 0.6;
    border-color: #f59e0b;
    animation: annaRingSpin 3s linear infinite;
}
.anna-orb.anna-thinking .anna-core {
    background: radial-gradient(circle, #ffffff 0%, #fbbf24 40%, #f59e0b 100%);
    box-shadow:
        0 0 25px rgba(245, 158, 11, 0.5),
        0 0 60px rgba(245, 158, 11, 0.2);
    animation: annaCorePulse 1.5s ease-in-out infinite;
}

/* ------- SPEAKING — response streaming ------- */
.anna-orb.anna-speaking .anna-glow {
    opacity: 0.5;
    animation: annaGlowPulse 3s ease-in-out infinite;
}
.anna-orb.anna-speaking .anna-ring {
    opacity: 0.35;
    animation: annaRingSpin 10s linear infinite;
}
.anna-orb.anna-speaking .anna-core {
    animation: annaCorePulse 3s ease-in-out infinite;
}

/* ------- EXCITED — discovery, milestone ------- */
.anna-orb.anna-excited .anna-glow {
    opacity: 0.85;
    animation: annaGlowPulse 1.2s ease-in-out infinite;
}
.anna-orb.anna-excited .anna-ring {
    opacity: 0.65;
    border-color: #34d399;
    animation: annaRingSpin 2s linear infinite;
}
.anna-orb.anna-excited .anna-core {
    background: radial-gradient(circle, #ffffff 0%, #6ee7b7 30%, #10b981 100%);
    box-shadow:
        0 0 30px rgba(16, 185, 129, 0.5),
        0 0 80px rgba(16, 185, 129, 0.2);
    animation: annaExcitedBurst 1s ease-in-out infinite;
}

@keyframes annaExcitedBurst {
    0%, 100% { transform: scale(1); }
    25%      { transform: scale(1.12); }
    50%      { transform: scale(0.95); }
    75%      { transform: scale(1.06); }
}

/* ------- ERROR — something went wrong ------- */
.anna-orb.anna-error .anna-glow {
    opacity: 0.4;
    animation: annaGlowPulse 3s ease-in-out infinite;
}
.anna-orb.anna-error .anna-ring {
    opacity: 0.3;
    border-color: #ef4444;
}
.anna-orb.anna-error .anna-core {
    background: radial-gradient(circle, #ffffff 0%, #fca5a5 40%, #ef4444 100%);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
    animation: annaCorePulse 3s ease-in-out infinite;
}

/* =======================================================
   NOTIFICATION DOT (pulsing dot on the orb)
   ======================================================= */
.anna-dot {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
    z-index: 10;
}

.anna-dot.active {
    display: block;
    animation: annaDotPulse 2s ease-in-out infinite;
}

@keyframes annaDotPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.4); opacity: 0.6; }
}

/* =======================================================
   BACKDROP — dim overlay behind the tray
   ======================================================= */
.anna-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.anna-backdrop.open {
    opacity: 1;
}

/* =======================================================
   TRAY — slide-up chat panel
   ======================================================= */
.anna-tray {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 85vh;
    min-height: 400px;
    background: var(--bg-primary, #0f0f0f);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.4);
}

.anna-tray.open {
    transform: translateY(0);
}

.anna-tray.closing {
    transform: translateY(100%);
}

/* ------- HANDLE (drag to dismiss) ------- */
.anna-tray-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 4px;
    cursor: grab;
}

.anna-tray-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--text-tertiary, #555);
}

/* ------- HEADER ------- */
.anna-tray-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px 12px;
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
}

.anna-tray-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.anna-tray-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.anna-tray-version {
    font-size: 11px;
    color: var(--text-tertiary, #666);
    opacity: 0.5;
}

.anna-tray-close {
    background: none;
    border: none;
    color: var(--text-secondary, #999);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    line-height: 1;
}

.anna-tray-close:hover {
    background: var(--bg-secondary, #1a1a1a);
}

/* ------- HEADER ORB (in-tray) ------- */
.anna-tray-orb {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* ------- BODY (chat messages + chips) ------- */
.anna-tray-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ------- MESSAGES ------- */
.anna-msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: annaFadeIn 0.25s ease-out;
}

.anna-msg-user {
    align-self: flex-end;
    background: var(--accent-primary, #8b5cf6);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.anna-msg-assistant {
    align-self: flex-start;
    background: var(--bg-secondary, #1a1a1a);
    color: var(--text-primary, #fff);
    border-bottom-left-radius: 4px;
}

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

/* ------- TYPING INDICATOR ------- */
.anna-typing {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
}

.anna-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--anna-color-primary);
    animation: annaTypingDot 1.2s steps(4, end) infinite;
}

.anna-typing span:nth-child(2) { animation-delay: 0.2s; }
.anna-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes annaTypingDot {
    0%, 20% { opacity: 0.3; transform: scale(0.8); }
    50%     { opacity: 1;   transform: scale(1); }
    80%, 100% { opacity: 0.3; transform: scale(0.8); }
}

/* ------- CHIPS (suggestion buttons) ------- */
.anna-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.anna-chip {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    color: var(--text-primary, #fff);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.anna-chip:hover {
    background: var(--bg-tertiary, #252525);
    border-color: var(--anna-color-primary);
}

/* ------- DISCLAIMER ------- */
.anna-disclaimer {
    padding: 6px 16px;
    font-size: 10px;
    color: var(--text-tertiary, #666);
    text-align: center;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.05));
}

/* ------- INPUT ------- */
.anna-tray-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.08));
}

.anna-tray-input textarea {
    flex: 1;
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: 20px;
    color: var(--text-primary, #fff);
    font-size: 14px;
    padding: 10px 16px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
}

.anna-tray-input textarea:focus {
    border-color: var(--anna-color-primary);
}

.anna-tray-input textarea::placeholder {
    color: var(--text-tertiary, #666);
}

.anna-tray-input button {
    background: var(--accent-primary, #8b5cf6);
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    flex-shrink: 0;
    transition: background 0.2s;
}

.anna-tray-input button:hover {
    background: var(--accent-hover, #7c3aed);
}

/* =======================================================
   DESKTOP — wider tray, centered
   ======================================================= */
@media (min-width: 768px) {
    .anna-tray {
        left: 50%;
        right: auto;
        width: 420px;
        margin-left: -210px;
        max-height: 70vh;
        border-radius: 20px 20px 0 0;
    }
}

/* =======================================================
   iOS SAFE AREA — pad the input for home indicator
   ======================================================= */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .anna-tray-input {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
}
