/*!
 |------------------------------------------------------------------
 | Friday — floating CRM assistant widget (tenant panel only).
 |------------------------------------------------------------------
 |
 | Loaded from resources/views/filament/friday-widget.blade.php.
 | Design: deep-space navy (#0A1E46 family) with the ZodiacTech
 | blue/green accents — a distinct premium surface floating above the
 | CRM. Panel is dark navy in both light and dark CRM themes.
 |
 | z-index 35: above Filament chrome (sidebar 30, dropdowns 20) and
 | the mobile bottom nav (40 is spatial-offset, not layered over),
 | below Filament modals (40+).
 |
 | CSS motion is fully disabled under prefers-reduced-motion. The orb's
 | JS particle canvas (fr-orb-fx) degrades to one static frame under the
 | same media query and pauses while the tab is hidden.
 */

#friday-root {
    --fr-navy: #0A1E46;
    --fr-navy-2: #0E2A5C;
    --fr-blue: #1F6FFF;
    --fr-blue-dark: #0F5CE8;
    --fr-blue-soft: #5FA8FF;
    --fr-green: #2BD576;
    --fr-ink: #EAF1FF;
    --fr-soft: #B9C9E6;
    --fr-muted: #9FB4DC;
    --fr-z: 35;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Nothing exists — not even a flash — until capabilities allow it. */
#friday-root:not(.fr-ready) {
    display: none;
}

#friday-root [hidden] {
    display: none !important;
}

/* ----------------------------------------------------------------
 | Orb (56 px, bottom-right, above the mobile bottom nav)
 ---------------------------------------------------------------- */
.fr-orb {
    position: fixed;
    right: 24px;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    z-index: var(--fr-z);
    width: 56px;
    height: 56px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.fr-orb:focus-visible {
    outline: 2px solid var(--fr-blue-soft);
    outline-offset: 3px;
}

.fr-orb-ring,
.fr-orb-visual,
.fr-core {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

/* Expanding ripple (listening / speaking). */
.fr-orb-ring {
    inset: -7px;
    border: 1px solid rgba(95, 168, 255, 0.35);
}

/* Conic gradient ring: the premium "alive" surface. */
.fr-orb-visual {
    inset: 0;
    background: conic-gradient(from 210deg,
        var(--fr-blue) 0%,
        var(--fr-blue-soft) 22%,
        var(--fr-green) 46%,
        var(--fr-blue-soft) 68%,
        var(--fr-blue) 100%);
    box-shadow:
        0 0 0 1px rgba(95, 168, 255, 0.28),
        0 10px 28px rgba(4, 12, 30, 0.55),
        0 0 22px rgba(31, 111, 255, 0.42);
    animation: fr-breathe 4s ease-in-out infinite;
}

/* Navy core disc => the gradient reads as a ring, not a flat disc. */
.fr-orb-visual::before {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 36%, #16386E 0%, var(--fr-navy) 58%, #071633 100%);
}

/* Particle canvas (JS-drawn pseudo-3D sphere). Positioned after the navy
   core disc (::before) so the additive particle glow reads on top of it,
   underneath the glowing centre; the JS renders a single static frame
   under prefers-reduced-motion instead of the rAF loop. */
.fr-orb-fx {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
}

/* Glowing centre. */
.fr-core {
    top: 50%;
    left: 50%;
    width: 15px;
    height: 15px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, #FFFFFF 0%, var(--fr-blue-soft) 42%, rgba(31, 111, 255, 0) 74%);
    animation: fr-core-pulse 4s ease-in-out infinite;
}

.fr-orb:hover .fr-orb-visual {
    filter: brightness(1.1);
}

/* --- state: LISTENING — ring ripples, faster breathing --------------- */
.fr-s-listening .fr-orb-visual {
    animation-duration: 1.5s;
}

.fr-s-listening .fr-core {
    animation-duration: 1.5s;
}

.fr-s-listening .fr-orb-ring {
    border-color: rgba(43, 213, 118, 0.55);
    animation: fr-ripple 1.8s ease-out infinite;
}

/* --- state: THINKING — slow rotation + shimmer ----------------------- */
.fr-s-thinking .fr-orb-visual {
    animation: fr-spin 2.8s linear infinite;
}

.fr-s-thinking .fr-core {
    animation-duration: 2.2s;
}

.fr-s-thinking .fr-orb-ring {
    border-style: dashed;
    border-color: rgba(95, 168, 255, 0.45);
    animation: fr-spin 6s linear infinite;
}

/* --- state: SPEAKING — strong pulse, radiating ring ------------------ */
.fr-s-speaking .fr-orb-visual {
    animation: fr-speak 1s ease-in-out infinite;
}

.fr-s-speaking .fr-core {
    animation-duration: 0.9s;
}

.fr-s-speaking .fr-orb-ring {
    border-color: rgba(95, 168, 255, 0.65);
    animation: fr-ripple 1s ease-out infinite;
}

/* ----------------------------------------------------------------
 | Status pill (visible while listening/thinking/speaking and the
 | panel is closed; the live region text is always present)
 ---------------------------------------------------------------- */
.fr-status {
    position: fixed;
    right: 24px;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    z-index: var(--fr-z);
    padding: 4px 11px;
    border-radius: 999px;
    border: 1px solid rgba(95, 168, 255, 0.3);
    background: rgba(10, 30, 70, 0.92);
    color: var(--fr-ink);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    box-shadow: 0 6px 18px rgba(4, 12, 30, 0.45);
    opacity: 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
}

.fr-s-listening .fr-status,
.fr-s-thinking .fr-status,
.fr-s-speaking .fr-status {
    opacity: 1;
}

/* Panel open: the orb animation carries the state; the pill would sit
   under the panel edge, so it yields to the panel (live region stays). */
.fr-open .fr-status {
    opacity: 0;
}

/* ----------------------------------------------------------------
 | Panel — 360x520 card, glass on navy; mobile: above the bottom nav
 ---------------------------------------------------------------- */
.fr-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: var(--fr-z);
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 150px);
    max-height: calc(100dvh - 150px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    border: 1px solid rgba(95, 168, 255, 0.22);
    background: linear-gradient(165deg, rgba(14, 42, 92, 0.94) 0%, rgba(8, 23, 54, 0.96) 100%);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    backdrop-filter: blur(18px) saturate(1.25);
    box-shadow:
        0 28px 64px rgba(3, 10, 26, 0.6),
        0 2px 8px rgba(3, 10, 26, 0.4),
        inset 0 1px 0 rgba(95, 168, 255, 0.16);
    color: var(--fr-ink);
}

.fr-panel.is-open {
    animation: fr-panel-in 0.18s ease-out;
}

/* --- header ---------------------------------------------------------- */
.fr-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 12px 12px 18px;
    border-bottom: 1px solid rgba(95, 168, 255, 0.14);
    background: linear-gradient(180deg, rgba(31, 111, 255, 0.12), rgba(31, 111, 255, 0));
}

.fr-head-id {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.fr-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #FFFFFF;
}

.fr-title::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: conic-gradient(from 120deg, var(--fr-blue-soft), var(--fr-green), var(--fr-blue-soft));
    box-shadow: 0 0 8px rgba(95, 168, 255, 0.7);
}

.fr-sub {
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--fr-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fr-head-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Live voice pill: one obvious start/stop for the streaming voice session,
   sitting next to Clear/Minimize. Active state echoes the composer mic. */
.fr-voice-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    padding: 0 11px;
    border: 1px solid rgba(95, 168, 255, 0.35);
    border-radius: 999px;
    background: rgba(95, 168, 255, 0.1);
    color: #CFE0FF;
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
    cursor: pointer;
}

.fr-voice-pill svg {
    width: 14px;
    height: 14px;
}

.fr-voice-pill:hover {
    background: rgba(95, 168, 255, 0.2);
    border-color: rgba(95, 168, 255, 0.5);
    color: #FFFFFF;
}

.fr-voice-pill.is-active {
    border-color: rgba(43, 213, 118, 0.55);
    background: rgba(43, 213, 118, 0.16);
    color: #7CE3A8;
}

.fr-voice-pill.is-pending {
    opacity: 0.6;
}

.fr-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--fr-soft);
    cursor: pointer;
}

.fr-icon-btn svg {
    width: 17px;
    height: 17px;
}

.fr-icon-btn:hover {
    background: rgba(95, 168, 255, 0.14);
    color: #FFFFFF;
}

.fr-icon-btn:focus-visible,
.fr-voice-pill:focus-visible,
.fr-chip:focus-visible,
.fr-send:focus-visible,
.fr-input:focus-visible {
    outline: 2px solid var(--fr-blue-soft);
    outline-offset: 2px;
}

/* --- messages -------------------------------------------------------- */
.fr-msgs {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(95, 168, 255, 0.3) transparent;
}

.fr-msgs::-webkit-scrollbar {
    width: 8px;
}

.fr-msgs::-webkit-scrollbar-thumb {
    background: rgba(95, 168, 255, 0.25);
    border-radius: 4px;
}

.fr-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    align-self: flex-start;
}

.fr-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.fr-who {
    margin-bottom: 3px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: rgba(185, 201, 230, 0.7);
}

.fr-bubble {
    padding: 9px 13px;
    border-radius: 14px 14px 14px 4px;
    background: rgba(95, 168, 255, 0.12);
    border: 1px solid rgba(95, 168, 255, 0.16);
    color: var(--fr-ink);
    font-size: 13.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.fr-msg-user .fr-bubble {
    border-radius: 14px 14px 4px 14px;
    border-color: transparent;
    background: linear-gradient(135deg, var(--fr-blue), var(--fr-blue-dark));
    color: #FFFFFF;
}

.fr-msg-error .fr-bubble {
    border-color: rgba(255, 122, 138, 0.4);
    background: rgba(255, 90, 110, 0.1);
}

.fr-time {
    margin-top: 4px;
    font-size: 10px;
    color: rgba(185, 201, 230, 0.55);
}

.fr-note {
    align-self: stretch;
    padding: 7px 10px;
    border-left: 2px solid rgba(95, 168, 255, 0.45);
    border-radius: 8px;
    background: rgba(95, 168, 255, 0.08);
    color: var(--fr-muted);
    font-size: 11.5px;
    line-height: 1.45;
}

.fr-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 86%;
    align-self: flex-start;
}

.fr-tool {
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid rgba(43, 213, 118, 0.28);
    background: rgba(43, 213, 118, 0.12);
    color: #7CE3A8;
    font-size: 10.5px;
    font-weight: 600;
}

.fr-typing {
    display: inline-flex;
    gap: 5px;
    align-self: flex-start;
    padding: 10px 13px;
    border-radius: 14px 14px 14px 4px;
    background: rgba(95, 168, 255, 0.12);
    border: 1px solid rgba(95, 168, 255, 0.16);
}

.fr-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--fr-blue-soft);
    animation: fr-dot 1.2s ease-in-out infinite;
}

.fr-dot:nth-child(2) { animation-delay: 0.15s; }
.fr-dot:nth-child(3) { animation-delay: 0.3s; }

/* --- suggested questions --------------------------------------------- */
.fr-suggest {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 12px;
}

.fr-chip {
    padding: 6px 11px;
    border-radius: 999px;
    border: 1px solid rgba(95, 168, 255, 0.3);
    background: rgba(95, 168, 255, 0.1);
    color: #CFE0FF;
    font-size: 11.5px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
}

.fr-chip:hover {
    background: rgba(95, 168, 255, 0.2);
    border-color: rgba(95, 168, 255, 0.5);
    color: #FFFFFF;
}

/* --- composer --------------------------------------------------------- */
.fr-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid rgba(95, 168, 255, 0.14);
    background: rgba(8, 23, 54, 0.4);
}

.fr-input {
    flex: 1;
    min-height: 38px;
    max-height: 84px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid rgba(95, 168, 255, 0.25);
    background: rgba(6, 17, 40, 0.75);
    color: var(--fr-ink);
    font-size: 13.5px;
    font-family: inherit;
    line-height: 1.45;
    resize: none;
    outline: none;
    scrollbar-width: thin;
}

.fr-input::placeholder {
    color: rgba(159, 180, 220, 0.75);
}

.fr-input:focus {
    border-color: rgba(31, 111, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(31, 111, 255, 0.22);
}

.fr-send,
.fr-mic,
.fr-stop {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.fr-send {
    border: 0;
    background: linear-gradient(135deg, var(--fr-blue), var(--fr-blue-dark));
    color: #FFFFFF;
    box-shadow: 0 4px 14px rgba(31, 111, 255, 0.4);
}

.fr-send:hover:not(:disabled) {
    filter: brightness(1.1);
}

.fr-send:disabled {
    opacity: 0.42;
    cursor: default;
    box-shadow: none;
}

.fr-mic {
    border: 1px solid rgba(95, 168, 255, 0.35);
    background: transparent;
    color: #CFE0FF;
}

.fr-mic:hover {
    background: rgba(95, 168, 255, 0.14);
    color: #FFFFFF;
}

.fr-mic.is-active {
    border-color: rgba(43, 213, 118, 0.55);
    background: rgba(43, 213, 118, 0.16);
    color: #7CE3A8;
}

.fr-mic.is-pending {
    opacity: 0.6;
}

.fr-stop {
    border: 1px solid rgba(255, 122, 138, 0.5);
    background: rgba(255, 90, 110, 0.12);
    color: #FFA7B6;
}

.fr-stop:hover {
    background: rgba(255, 90, 110, 0.22);
    color: #FFFFFF;
}

.fr-send svg,
.fr-mic svg,
.fr-stop svg {
    width: 17px;
    height: 17px;
}

/* ----------------------------------------------------------------
 | Mobile: sheet above the bottom nav; orb clears the nav via safe
 | area + nav offset. Nav itself is never covered.
 ---------------------------------------------------------------- */
@media (max-width: 767px) {
    .fr-orb {
        right: 16px;
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
    }

    .fr-status {
        right: 16px;
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px) + 64px);
    }

    .fr-panel {
        left: 8px;
        right: 8px;
        top: calc(10px + env(safe-area-inset-top, 0px));
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px) + 8px);
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 18px;
    }
}

/* ----------------------------------------------------------------
 | Keyframes — all CSS-only, all disabled under reduced motion
 ---------------------------------------------------------------- */
@keyframes fr-breathe {
    0%, 100% {
        transform: scale(1);
        box-shadow:
            0 0 0 1px rgba(95, 168, 255, 0.28),
            0 10px 28px rgba(4, 12, 30, 0.55),
            0 0 22px rgba(31, 111, 255, 0.42);
    }
    50% {
        transform: scale(1.035);
        box-shadow:
            0 0 0 1px rgba(95, 168, 255, 0.38),
            0 10px 28px rgba(4, 12, 30, 0.55),
            0 0 30px rgba(31, 111, 255, 0.6);
    }
}

@keyframes fr-core-pulse {
    0%, 100% { opacity: 0.75; transform: translate(-50%, -50%) scale(0.92); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
}

@keyframes fr-ripple {
    0% { transform: scale(0.92); opacity: 0.9; }
    100% { transform: scale(1.28); opacity: 0; }
}

@keyframes fr-spin {
    to { transform: rotate(360deg); }
}

@keyframes fr-speak {
    0%, 100% {
        transform: scale(1);
        box-shadow:
            0 0 0 1px rgba(95, 168, 255, 0.35),
            0 0 20px rgba(31, 111, 255, 0.5);
    }
    50% {
        transform: scale(1.06);
        box-shadow:
            0 0 0 1px rgba(43, 213, 118, 0.5),
            0 0 34px rgba(95, 168, 255, 0.75);
    }
}

@keyframes fr-dot {
    0%, 100% { transform: translateY(0); opacity: 0.55; }
    50% { transform: translateY(-3px); opacity: 1; }
}

@keyframes fr-panel-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ----------------------------------------------------------------
 | Reduced motion: static orb, simple status changes only
 ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    #friday-root *,
    #friday-root *::before,
    #friday-root *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ----------------------------------------------------------------
 | Print — never
 ---------------------------------------------------------------- */
@media print {
    #friday-root {
        display: none !important;
    }
}
