/* AI Chat Side Panel */
:root {
    --chat-panel-width: 640px;
}

.fi-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--chat-panel-width);
    height: 100vh;
    height: 100dvh;
    z-index: 30;
    background: white;
    border-left: 1px solid var(--color-gray-200);
}

:is(.dark .fi-chat-panel) {
    background: var(--color-gray-950);
    border-left-color: var(--color-gray-700);
}


.fi-chat-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.fi-chat-panel-resize {
    position: absolute;
    top: 0;
    left: -3px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 31;
}

.fi-chat-panel-resize:hover,
.fi-chat-panel-resize:active {
    background: var(--color-primary-500);
    opacity: 0.4;
}

/* When panel is open: lock body scroll, app content scrolls independently */
body.fi-chat-panel-open {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    padding-right: var(--chat-panel-width);
    transition: padding-right 300ms ease;
}

body:not(.fi-chat-panel-open) {
    transition: padding-right 200ms ease;
}

body.fi-chat-panel-open .fi-main-ctn {
    overflow-y: auto;
    height: calc(100vh - 4rem);
    height: calc(100dvh - 4rem);
}

/* Mobile: full-screen overlay */
@media (max-width: 767px) {
    .fi-chat-panel {
        width: 100% !important;
        border-left: none;
        box-shadow: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .fi-chat-panel-resize {
        display: none;
    }

    body.fi-chat-panel-open {
        padding-right: 0;
    }
}

/* Code block copy button */
.code-block-wrapper {
    position: relative;
    margin: 1em 0;
}

.code-block-wrapper pre {
    margin: 0 !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    background: rgba(0, 0, 0, 0.06);
    border-top-left-radius: 0.5rem;
    border-top-right-radius: 0.5rem;
    font-size: 0.7rem;
}

:is(.dark .code-block-header) {
    background: rgba(255, 255, 255, 0.06);
}

.code-block-lang {
    color: var(--color-gray-500);
    font-family: var(--font-mono);
    text-transform: lowercase;
}

.code-copy-btn {
    color: var(--color-gray-500);
    font-size: 0.7rem;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    transition: color 0.15s, background 0.15s;
    margin-left: auto;
}

.code-copy-btn:hover {
    color: var(--color-gray-800);
    background: rgba(0, 0, 0, 0.06);
}

:is(.dark .code-copy-btn:hover) {
    color: var(--color-gray-200);
    background: rgba(255, 255, 255, 0.08);
}

/* Minimal scrollbars */
.fi-main-ctn,
.fi-chat-panel-inner,
.fi-chat-panel-inner * {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

:is(.dark .fi-main-ctn),
:is(.dark .fi-chat-panel-inner),
:is(.dark .fi-chat-panel-inner *) {
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.fi-main-ctn::-webkit-scrollbar,
.fi-chat-panel-inner ::-webkit-scrollbar {
    width: 6px;
}

.fi-main-ctn::-webkit-scrollbar-track,
.fi-chat-panel-inner ::-webkit-scrollbar-track {
    background: transparent;
}

.fi-main-ctn::-webkit-scrollbar-thumb,
.fi-chat-panel-inner ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.fi-main-ctn::-webkit-scrollbar-thumb:hover,
.fi-chat-panel-inner ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

:is(.dark .fi-main-ctn)::-webkit-scrollbar-thumb,
:is(.dark .fi-chat-panel-inner) ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

:is(.dark .fi-main-ctn)::-webkit-scrollbar-thumb:hover,
:is(.dark .fi-chat-panel-inner) ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ARP loader: Sierpinski step-0 → step-1 → staged-spin → step-0 for AI waiting state.
   Each cycle:
     1. Three triangles separate from full overlap (step-0) to their outer corners
        revealing the inverted center hole (step-1). Held briefly so step-1 reads.
     2. Each triangle enlarges in place (less negative space, more presence).
     3. Top, right, then left each spin 360° in turn (staggered, never simultaneous).
     4. Settle back to step-1 size, then merge into a single solid triangle (step-0).
   Color cycles independently for chromatic shimmer. */

@keyframes arp-sierpinski-color {
    0%, 100% { color: #f59e0b; } /* amber */
    25%      { color: #14b8a6; } /* teal */
    50%      { color: #8b5cf6; } /* violet */
    75%      { color: #ec4899; } /* pink */
}

/* Top triangle — separates first, rotates first (35→50%) */
@keyframes arp-sierpinski-top {
    0%   { transform: scale(1)    rotate(0deg);   }   /* step-0 (full overlap) */
    18%  { transform: scale(0.45) rotate(0deg);   }   /* step-1 reached */
    25%  { transform: scale(0.45) rotate(0deg);   }   /* hold — let the eye see it */
    35%  { transform: scale(0.75) rotate(0deg);   }   /* enlarge */
    50%  { transform: scale(0.75) rotate(360deg); }   /* its rotation window */
    82%  { transform: scale(0.75) rotate(360deg); }   /* hold while others rotate */
    92%  { transform: scale(0.45) rotate(360deg); }   /* shrink back toward step-1 */
    100% { transform: scale(1)    rotate(360deg); }   /* merge back to step-0 */
}

/* Right triangle — separates same, rotates second (50→65%) */
@keyframes arp-sierpinski-right {
    0%   { transform: scale(1)    rotate(0deg);   }
    18%  { transform: scale(0.45) rotate(0deg);   }
    25%  { transform: scale(0.45) rotate(0deg);   }
    35%  { transform: scale(0.75) rotate(0deg);   }
    50%  { transform: scale(0.75) rotate(0deg);   }   /* waits for top to finish */
    65%  { transform: scale(0.75) rotate(360deg); }   /* its rotation window */
    82%  { transform: scale(0.75) rotate(360deg); }   /* hold while left rotates */
    92%  { transform: scale(0.45) rotate(360deg); }
    100% { transform: scale(1)    rotate(360deg); }
}

/* Left triangle — separates same, rotates last (65→82%) */
@keyframes arp-sierpinski-left {
    0%   { transform: scale(1)    rotate(0deg);   }
    18%  { transform: scale(0.45) rotate(0deg);   }
    25%  { transform: scale(0.45) rotate(0deg);   }
    35%  { transform: scale(0.75) rotate(0deg);   }
    65%  { transform: scale(0.75) rotate(0deg);   }   /* waits for top + right */
    82%  { transform: scale(0.75) rotate(360deg); }   /* its rotation window */
    92%  { transform: scale(0.45) rotate(360deg); }
    100% { transform: scale(1)    rotate(360deg); }
}

.arp-sierpinski {
    animation: arp-sierpinski-color 6s ease-in-out infinite;
    will-change: color;
}

.arp-sierpinski-tri {
    will-change: transform;
    /* Translucent fill so triple-overlap at step-0 reads as depth, not a flat glyph. */
    fill-opacity: 0.78;
}

.arp-sierpinski-tri--top {
    transform-origin: 12px 6px;
    animation: arp-sierpinski-top 4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

.arp-sierpinski-tri--right {
    transform-origin: 18.5px 18.5px;
    animation: arp-sierpinski-right 4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

.arp-sierpinski-tri--left {
    transform-origin: 5.5px 18.5px;
    animation: arp-sierpinski-left 4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@media (prefers-reduced-motion: reduce) {
    .arp-sierpinski-tri {
        animation: none;
        transform: scale(0.6); /* freeze at clear step-1 — recognizable, motionless */
    }
}
