/* ===== AMRA VOICE AGENT (Layla) ===== */
/* Floating gold FAB + a compact bottom-center mini panel with watercolor orb */

/* ===== Layla FAB — watercolor orb pill at top-center =====
   Prominent, draws the eye, matches the orb aesthetic */
#layla-fab {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 22px 8px 8px;
    border-radius: 100px;
    background: rgba(8, 6, 12, 0.7);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border: 1px solid rgba(180, 220, 255, 0.18);
    box-shadow:
        0 8px 32px rgba(80, 150, 240, 0.25),
        0 0 0 0 rgba(120, 180, 255, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    color: #fff;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s, border-color 0.3s;
    animation: fabBreath 3s ease-in-out infinite;
}
#layla-fab:hover {
    transform: translateX(-50%) translateY(-2px);
    border-color: rgba(180, 220, 255, 0.4);
    box-shadow:
        0 12px 40px rgba(80, 150, 240, 0.45),
        0 0 0 6px rgba(120, 180, 255, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
#layla-fab.hidden { display: none; }

/* The mini watercolor orb inside the FAB */
#layla-fab .fab-orb {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(180, 220, 255, 0.85) 20%,
        rgba(80, 150, 240, 0.75) 55%,
        rgba(30, 90, 200, 0.5) 90%
    );
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.2), 0 0 16px rgba(120, 180, 255, 0.4);
}
#layla-fab .fab-orb::before {
    content: '';
    position: absolute;
    inset: -25%;
    background:
        radial-gradient(circle at 35% 40%, rgba(255, 255, 255, 0.7) 0%, transparent 32%),
        radial-gradient(circle at 70% 65%, rgba(200, 230, 255, 0.5) 0%, transparent 35%);
    mix-blend-mode: screen;
    animation: cloudDrift 7s ease-in-out infinite alternate;
}

/* Labels — bilingual */
#layla-fab .fab-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-align: left;
    line-height: 1.2;
}
#layla-fab .fab-ar {
    font-family: 'Cairo', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.96);
    direction: rtl;
}
#layla-fab .fab-en {
    font-size: 9px;
    font-weight: 500;
    color: rgba(180, 220, 255, 0.8);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

@keyframes fabBreath {
    0%, 100% {
        box-shadow:
            0 8px 32px rgba(80, 150, 240, 0.25),
            0 0 0 0 rgba(120, 180, 255, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.05);
    }
    50% {
        box-shadow:
            0 10px 36px rgba(80, 150, 240, 0.4),
            0 0 0 10px rgba(120, 180, 255, 0),
            inset 0 1px 0 rgba(255, 255, 255, 0.08);
    }
}

/* One-shot attention pulse when the FAB first reveals after amra:started */
#layla-fab.attn {
    animation: fabBreath 3s ease-in-out infinite, fabAttention 1.2s ease-out;
    transform-origin: center;
}
@keyframes fabAttention {
    0%   { transform: translateX(-50%) scale(0.92); opacity: 0; }
    20%  { transform: translateX(-50%) scale(1.06); opacity: 1; }
    60%  { transform: translateX(-50%) scale(1.00); }
    100% { transform: translateX(-50%) scale(1.00); }
}
@media (max-width: 640px) {
    @keyframes fabAttention {
        0%   { transform: translateX(-50%) scale(0.92); opacity: 0; }
        20%  { transform: translateX(-50%) scale(1.04); opacity: 1; }
        100% { transform: translateX(-50%) scale(1.00); }
    }
}

@media (max-width: 640px) {
    #layla-fab { top: 80px; padding: 6px 16px 6px 6px; }
    #layla-fab .fab-orb { width: 34px; height: 34px; }
    #layla-fab .fab-ar { font-size: 12px; }
    #layla-fab .fab-en { font-size: 8px; }
}

/* ===== Floating mini-panel — draggable, minimizable ===== */
#layla-mini {
    position: fixed;
    bottom: 100px;
    left: 50%;
    z-index: 9999;
    width: 280px;
    padding: 22px 20px 16px;
    background: rgba(8, 6, 12, 0.78);
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    opacity: 0;
    pointer-events: none;
    /* Initial transform = centered horizontally; JS overrides on drag */
    transform: translateX(-50%) translateY(20px);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), width 0.3s ease, height 0.3s ease, padding 0.3s ease;
    font-family: 'Inter', sans-serif;
    user-select: none;
}
#layla-mini.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
#layla-mini.dragging {
    transition: opacity 0.35s ease;
    cursor: grabbing !important;
}
#layla-mini.dragged {
    /* Once user drags, we set left/top directly; remove center-translate */
    transform: translateY(0);
}
#layla-mini.dragged.active { transform: translateY(0); }

/* ===== Minimized state — collapsed to just the orb ===== */
#layla-mini.minimized {
    width: 80px;
    padding: 12px;
    cursor: pointer;
}
#layla-mini.minimized .layla-mini-head,
#layla-mini.minimized .layla-mini-status,
#layla-mini.minimized .layla-mini-transcript,
#layla-mini.minimized .layla-mini-controls {
    display: none;
}
#layla-mini.minimized .layla-orb-wrap {
    width: 56px;
    height: 56px;
    margin: 0 auto;
}

/* Header row: grip + name + drag handle + minimize/close */
.layla-mini-head {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    cursor: grab;
    touch-action: none;
    gap: 8px;
}
.layla-mini-head:active { cursor: grabbing; }
.layla-mini-head-actions {
    display: flex;
    gap: 4px;
}

/* Grip-dots icon — visible affordance that the panel is draggable.
   Two columns × three rows of 3px dots, watercolor-blue tone. */
.layla-grip {
    display: grid;
    grid-template-columns: 3px 3px;
    grid-auto-rows: 3px;
    gap: 3px;
    flex: 0 0 9px;
    opacity: 0.45;
    transition: opacity 0.2s ease;
    margin-right: 2px;
}
.layla-grip span {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: linear-gradient(135deg, #b8d8ff 0%, #6da9ff 100%);
}
.layla-mini-head:hover .layla-grip { opacity: 0.85; }
.layla-mini-head.dragging .layla-grip { opacity: 1; }

/* First-time drag tip — shown for 4 seconds the first time the panel
   becomes active, then dismissed permanently via localStorage. */
.layla-drag-tip {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translate(-50%, -100%);
    background: rgba(8, 14, 28, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(160, 210, 255, 0.35);
    border-radius: 8px;
    padding: 6px 12px;
    font-family: 'Cairo', 'Inter', sans-serif;
    font-size: 11px;
    color: rgba(220, 235, 255, 0.95);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    box-shadow: 0 6px 18px rgba(60, 130, 220, 0.3);
}
.layla-drag-tip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(8, 14, 28, 0.92);
}
.layla-drag-tip.show {
    opacity: 1;
    transform: translate(-50%, -110%);
}
.layla-mini-name {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.layla-mini-name .en {
    color: rgba(255, 255, 255, 0.92);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.layla-mini-name .ar {
    font-family: 'Cairo', sans-serif;
    color: #c68a34;
    font-size: 14px;
    font-weight: 700;
    direction: rtl;
}
.layla-mini-close {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.layla-mini-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
}
.layla-mini-close svg { width: 12px; height: 12px; }

/* ===== Watercolor cloud orb ===== */
.layla-orb-wrap {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.layla-orb {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(180, 220, 255, 0.85) 20%,
        rgba(80, 150, 240, 0.7) 50%,
        rgba(30, 90, 200, 0.5) 75%,
        rgba(10, 30, 80, 0.2) 100%
    );
    box-shadow:
        0 0 40px 8px rgba(80, 150, 240, 0.3),
        inset 0 0 30px rgba(255, 255, 255, 0.15);
    transform: scale(var(--layla-scale, 1));
    transition: transform 0.1s ease-out, box-shadow 0.3s ease;
    filter: blur(0.3px);
}

/* Wispy cloud layers (animated) */
.layla-orb::before,
.layla-orb::after {
    content: '';
    position: absolute;
    inset: -20%;
    border-radius: 50%;
    background:
        radial-gradient(circle at 30% 40%, rgba(255, 255, 255, 0.7) 0%, transparent 30%),
        radial-gradient(circle at 70% 60%, rgba(200, 230, 255, 0.5) 0%, transparent 35%),
        radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.4) 0%, transparent 25%);
    mix-blend-mode: screen;
    animation: cloudDrift 8s ease-in-out infinite alternate;
    pointer-events: none;
}
.layla-orb::after {
    background:
        radial-gradient(circle at 60% 30%, rgba(255, 255, 255, 0.6) 0%, transparent 28%),
        radial-gradient(circle at 30% 70%, rgba(150, 200, 255, 0.5) 0%, transparent 35%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.45) 0%, transparent 30%);
    animation: cloudDrift2 11s ease-in-out infinite alternate;
}

@keyframes cloudDrift {
    0% { transform: translate(0, 0) rotate(0deg) scale(1); opacity: 0.85; }
    50% { transform: translate(8%, -6%) rotate(180deg) scale(1.05); opacity: 1; }
    100% { transform: translate(-6%, 8%) rotate(360deg) scale(0.95); opacity: 0.8; }
}
@keyframes cloudDrift2 {
    0% { transform: translate(0, 0) rotate(0deg) scale(0.95); opacity: 0.7; }
    50% { transform: translate(-7%, 5%) rotate(-180deg) scale(1.08); opacity: 0.9; }
    100% { transform: translate(5%, -8%) rotate(-360deg) scale(1); opacity: 0.75; }
}

/* States: speaking gets brighter + pulsier; listening more subtle */
.layla-orb.speaking {
    box-shadow:
        0 0 60px 14px rgba(120, 180, 255, 0.5),
        0 0 100px 24px rgba(80, 150, 240, 0.25),
        inset 0 0 40px rgba(255, 255, 255, 0.25);
    animation: orbSpeakingPulse 1.1s ease-in-out infinite;
}
.layla-orb.speaking::before { animation-duration: 4s; }
.layla-orb.speaking::after { animation-duration: 5.5s; }
@keyframes orbSpeakingPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}

.layla-orb.listening {
    box-shadow:
        0 0 35px 6px rgba(80, 150, 240, 0.2),
        inset 0 0 30px rgba(255, 255, 255, 0.12);
}
.layla-orb.listening::before { animation-duration: 12s; }
.layla-orb.listening::after { animation-duration: 16s; }

/* Muted state — desaturated, visibly off. Wins over listening/speaking shadows. */
.layla-orb.muted {
    filter: saturate(0.15) brightness(0.55);
    box-shadow:
        0 0 12px 2px rgba(120, 130, 145, 0.18),
        inset 0 0 16px rgba(255, 255, 255, 0.06) !important;
}
.layla-orb.muted::before,
.layla-orb.muted::after {
    opacity: 0.25;
    animation-duration: 30s !important;
}
/* Muted mic button — slashed icon visual */
.layla-mini-btn[data-action="mute"][data-state="muted"] {
    background: rgba(255, 90, 90, 0.18);
    border-color: rgba(255, 90, 90, 0.55);
    color: #ffd0d0;
    position: relative;
}
.layla-mini-btn[data-action="mute"][data-state="muted"]::after {
    content: '';
    position: absolute;
    inset: 12% 50%;
    border-left: 2px solid currentColor;
    transform: rotate(45deg);
    pointer-events: none;
}

/* Status text */
.layla-mini-status {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-weight: 500;
    min-height: 14px;
    margin-bottom: 8px;
}
.layla-mini-status .dot {
    display: inline-block;
    width: 4px;
    height: 4px;
    background: #6ab0ff;
    border-radius: 50%;
    margin: 0 2px;
    animation: statusDot 1.4s ease-in-out infinite;
    vertical-align: middle;
}
.layla-mini-status .dot:nth-child(2) { animation-delay: 0.2s; }
.layla-mini-status .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes statusDot {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* Transcript (compact, max 2 lines) */
.layla-mini-transcript {
    text-align: center;
    color: rgba(255, 255, 255, 0.55);
    font-size: 12px;
    line-height: 1.4;
    min-height: 32px;
    max-height: 48px;
    overflow: hidden;
    padding: 0 4px;
    margin-bottom: 12px;
    direction: rtl;
    font-family: 'Cairo', 'Inter', sans-serif;
}
.layla-mini-transcript.is-user {
    font-style: italic;
    color: rgba(255, 255, 255, 0.4);
}

/* Controls row */
.layla-mini-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
}
.layla-mini-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.layla-mini-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.95);
    transform: translateY(-1px);
}
.layla-mini-btn svg { width: 14px; height: 14px; }
.layla-mini-btn[data-state="muted"] {
    background: rgba(255, 80, 80, 0.15);
    border-color: rgba(255, 80, 80, 0.35);
    color: rgba(255, 180, 180, 0.95);
}
.layla-mini-btn.danger {
    background: rgba(80, 80, 80, 0.15);
}
.layla-mini-btn.danger:hover {
    background: rgba(220, 53, 69, 0.25);
    border-color: rgba(220, 53, 69, 0.45);
    color: #ff9aa3;
}

/* Error toast */
.layla-error {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(220, 53, 69, 0.92);
    color: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 11px;
    white-space: nowrap;
    display: none;
}
.layla-error.show { display: block; }

/* Mobile */
@media (max-width: 480px) {
    #layla-mini { width: 250px; bottom: 90px; padding: 18px 16px 14px; }
    .layla-orb-wrap { width: 120px; height: 120px; margin-bottom: 10px; }
    #layla-fab { bottom: 76px; right: 16px; width: 50px; height: 50px; }
}

/* ===== AI Intent visualization =====
   When Layla calls a tool, this overlay surfaces what she's doing — a beam
   of light from her orb to a floating glass card at the top of the screen.
   This makes app control feel like Layla physically pointing at things. */
#layla-intent {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    pointer-events: none;
    z-index: 10000;
    opacity: 0;
    --orb-x: 50%;
    --orb-y: 90%;
}
#layla-intent.show { opacity: 1; transition: opacity 0.45s ease; }
#layla-intent.hide { opacity: 0; transition: opacity 0.8s ease; }

/* Sparkle field — particles travel from the orb's CURRENT position to the
   intent card. JS spawns each sparkle with absolute left/top and CSS vars
   --dx/--dy for the per-particle delta. Animation handles the flight + fade.
   The container itself is invisible — sparkles are the only thing rendered. */
.layla-sparkle-field {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.layla-sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: -4px;
    margin-top:  -4px;
    background: radial-gradient(circle, #f0f8ff 0%, #b8d8ff 35%, #6da9ff 70%, rgba(109,169,255,0) 100%);
    box-shadow:
        0 0 8px rgba(180, 220, 255, 0.95),
        0 0 16px rgba(120, 180, 255, 0.55);
    opacity: 0;
    animation: laylaSparkleFly 1s ease-out forwards;
    will-change: transform, opacity;
}

@keyframes laylaSparkleFly {
    0%   { opacity: 0;   transform: translate(0, 0) scale(0.4); }
    12%  { opacity: 1;   transform: translate(calc(var(--dx) * 0.10), calc(var(--dy) * 0.10)) scale(1); }
    65%  { opacity: 1;   transform: translate(calc(var(--dx) * 0.75), calc(var(--dy) * 0.75)) scale(0.95); }
    100% { opacity: 0;   transform: translate(var(--dx), var(--dy)) scale(0.5); }
}

/* The card — frosted glass floating at top */
.layla-intent-card {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 12px 22px 12px 14px;
    background: rgba(8, 14, 28, 0.78);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(160, 210, 255, 0.28);
    border-radius: 100px;
    box-shadow:
        0 12px 40px rgba(60, 130, 220, 0.35),
        0 0 0 1px rgba(160, 210, 255, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: #fff;
    font-family: 'Cairo', 'Inter', sans-serif;
    opacity: 0;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}
#layla-intent.show .layla-intent-card {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.layla-intent-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #d6ebff 0%, #6da9ff 55%, #1a3a7a 100%);
    box-shadow: 0 0 14px rgba(140, 200, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.95);
    animation: laylaIconSpin 4s linear infinite;
}
.layla-intent-icon svg { width: 16px; height: 16px; }
@keyframes laylaIconSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.layla-intent-text { display: flex; flex-direction: column; line-height: 1.2; }
.layla-intent-by {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(180, 215, 255, 0.85);
    direction: rtl;
}
.layla-intent-action {
    font-size: 15px;
    font-weight: 500;
    color: #fff;
    direction: rtl;
    margin-top: 2px;
}

/* ===== Smooth tour transition =====
   Brief soft fade applied to the React tour root when Layla mutates state. */
.layla-transition {
    transition: filter 0.35s ease, opacity 0.35s ease;
    filter: brightness(0.7) blur(2px);
    opacity: 0.85;
}

@media (max-width: 480px) {
    .layla-intent-card { top: 60px; padding: 10px 16px 10px 10px; gap: 10px; }
    .layla-intent-icon { width: 28px; height: 28px; }
    .layla-intent-action { font-size: 13px; }
}
