/* file: portal/app/static/css/island.css
 *
 * Island mode styles - persistent side panel for AI Assistant
 *
 * Table of Contents:
 * ------------------
 * 1. CSS Custom Properties
 * 2. Island Container
 * 3. Island Header
 * 4. Island Content
 * 5. Island Mode Layout Adjustments
 * 6. Transitions & Animations
 * 7. Responsive Adjustments
 * 8. Expanded Mode (Full Page View)
 */

/* ===========================================
   1. CSS Custom Properties
   =========================================== */

:root {
    --island-width: 420px;
    --island-min-width: 320px;
    --island-header-height: 48px;
    --island-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);  /* Material Design standard */
    --island-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] {
    --island-shadow: -4px 0 20px rgba(0, 0, 0, 0.25);
}

/* ===========================================
   2. Island Container
   =========================================== */

.island {
    position: absolute;  /* Relative to app-shell */
    top: 0;
    right: 0;
    width: var(--island-width);
    height: 100%;
    background-color: var(--page);
    border-left: 1px solid var(--border);
    box-shadow: var(--island-shadow);
    display: flex;
    flex-direction: column;
    z-index: 1040;  /* Below modals (1050), above most content */
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--island-transition), visibility var(--island-transition);
}

/* Island visible state */
.island.island-open {
    transform: translateX(0);
    visibility: visible;
}

/* ===========================================
   3. Island Header
   =========================================== */

.island-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--island-header-height);
    padding: 0 0.75rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--page);
    flex-shrink: 0;
}

.island-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-heading);
    margin: 0;
}

.island-title-icon {
    font-size: 1.125rem;  /* Match sidebar-icon */
    width: 1.5rem;        /* Match sidebar-icon */
    text-align: center;
    color: var(--text-heading);  /* Match sidebar nav color */
}

.island-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.island-control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 0.375rem;
    background-color: transparent;
    color: var(--text-light);
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
}

.island-control-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-heading);
}

.island-control-btn:focus {
    outline: none;
    box-shadow: 0 0 0 var(--bs-focus-ring-width) var(--focus-ring);
}

/* Close button subtle warning on hover */
.island-control-btn-close:hover {
    background-color: color-mix(in srgb, var(--danger) 10%, transparent);
    color: var(--danger);
}

/* ===========================================
   4. Island Content
   =========================================== */

.island-content {
    flex: 1;
    overflow: hidden;  /* Content (React app) handles its own scrolling */
    display: flex;
    flex-direction: column;
}

/* Placeholder content when React app not loaded */
.island-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
    color: var(--text-light);
}

.island-placeholder-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.island-placeholder-text {
    font-size: 0.875rem;
}

/* React app container - must be flex to allow child scrolling */
#island-assistant-root {
    flex: 1;
    min-height: 0;  /* Critical: allow flex child to shrink and trigger overflow */
    display: flex;
    flex-direction: column;
}

/* ===========================================
   5. Island Mode Layout Adjustments
   =========================================== */

/* When island is open, adjust the main layout */
body.island-mode .page-wrapper {
    margin-right: var(--island-width);
    transition: margin-right var(--island-transition);
}

/* Content area needs margin when sidebar is mini (island mode) */
body.island-mode .content-wrapper {
    margin-left: var(--sidebar-mini-width);
}

/* FAB visibility is managed via JS (d-none class) to override Bootstrap's d-flex !important */

/* ===========================================
   6. Transitions & Animations
   =========================================== */

/* Smooth layout transition */
.page-wrapper {
    transition: margin-right var(--island-transition);
}

/* ===========================================
   7. Responsive Adjustments
   =========================================== */

/* Smaller screens: island takes more space */
@media (max-width: 1440px) {
    :root {
        --island-width: 380px;
    }
}

/* Medium screens: island takes full width minus mini sidebar */
@media (max-width: 1024px) {
    :root {
        --island-width: calc(100% - var(--sidebar-mini-width) - 1rem);
    }

    body.island-mode .page-wrapper {
        margin-right: 0;  /* Content hidden behind island on small screens */
    }
}

/* Small screens: island covers everything */
@media (max-width: 768px) {
    .island {
        width: 100%;
    }

    body.island-mode .page-wrapper {
        margin-right: 0;
    }

    body.island-mode .sidebar {
        display: none;
    }

    body.island-mode .content-wrapper {
        margin-left: 0;
    }
}

/* ===========================================
   8. Expanded Mode (Full Page View)
   =========================================== */

/*
 * In expanded mode, the React container (#island-assistant-root) is moved
 * from the island to #page-content. The island shell is hidden.
 * These styles ensure the React app fills the page-content area properly.
 */

/* Remove content-wrapper padding/scrolling when hosting assistant (full bleed) */
.content-wrapper:has(#island-assistant-root) {
    padding: 0;
    overflow: hidden;  /* Prevent scrollbar - React app handles scrolling */
}

/* Page content needs flex layout when hosting the assistant */
#page-content:has(#island-assistant-root) {
    display: flex;
    flex-direction: column;
    height: 100%;       /* Fill content-wrapper */
    margin: 0;          /* Override mt-1 */
    padding: 0;
    max-width: 100%;
    overflow: hidden;   /* Constrain React app - matches .island-content pattern */
}

/* React app fills available space in page mode */
#page-content > #island-assistant-root {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
