/* public/css/layout.css - Light Theme Restoration */

:root {
    --sidebar-width: 400px;
    --nav-width: 60px;

    /* Brand Colors (Restored from console.css) */
    --km-teal: #2A4B59;
    --km-amber: #CF9003;
    --km-bg-main: #FFFFFF;
    --km-bg-sidebar: #FFFCF2;
    --km-border: #E0E0E0;
    --km-surface: #FFFFFF;
    --km-text: #2D3436;
    --km-text-light: #636E72;
    --km-accent-light: rgba(207, 144, 3, 0.1);

    --panel-bg: var(--km-bg-sidebar);
    --border-color: var(--km-border);
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--km-bg-main);
    font-family: 'Outfit', sans-serif;
    color: var(--km-text);
}

/* Mobile Header (Hidden on Desktop) */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--km-surface);
    border-bottom: 1px solid var(--km-border);
    z-index: 201;
    position: relative;
    height: 60px;
}

.mobile-menu-btn {
    font-size: 1.5rem;
    color: var(--km-teal);
    cursor: pointer;
    padding: 5px;
}

.mobile-profile-btn {
    font-size: 1.2rem;
    color: var(--km-teal);
    cursor: pointer;
    padding: 5px;
}

/* Mobile Nav Menu Overlay */
.mobile-nav-menu {
    position: fixed;
    /* Fixed to viewport to avoid clipping */
    top: 60px;
    /* Below header */
    right: 0;
    width: 250px;
    background: #fff;
    box-shadow: -5px 5px 20px rgba(0, 0, 0, 0.1);
    border-radius: 0 0 0 20px;
    display: none;
    /* Toggled via JS */
    flex-direction: column;
    z-index: 9999;
    /* Ensure topmost */
    overflow: hidden;
    animation: slideInRight 0.3s ease;
}

.mobile-nav-menu.open {
    display: flex;
}

.mobile-nav-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--km-teal);
    /* Theme Color */
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.mobile-nav-item i,
.mobile-nav-item span.material-icons-round {
    color: var(--km-amber);
    /* Icon Theme Color */
}

.mobile-nav-item:hover {
    background: var(--km-accent-light);
    color: var(--km-teal);
}

.mobile-nav-divider {
    height: 1px;
    background: var(--km-border);
    margin: 5px 0;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Dashboard Handle (Mobile) */
.dashboard-handle {
    position: fixed;
    top: 50%;
    left: 0;
    width: 8px;
    /* Thicker */
    height: 70px;
    /* Taller */
    background: var(--km-amber);
    /* Amber */
    border-radius: 0 6px 6px 0;
    transform: translateY(-50%);
    z-index: 250;
    cursor: pointer;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    display: none;
    /* Visible on Mobile */
}


/* --- MAIN GRID LAYOUT --- */
.app-container {
    display: grid;
    /* Fixed Sidebar (400px) | Content (Flex) | Nav (60px) */
    grid-template-columns: 400px minmax(0, 1fr) 60px;
    height: 100vh;
    width: 100vw;
    position: relative;
    background: var(--km-bg-main);
    overflow: hidden;
    /* Prevent body scrollbar */
}

/* --- 1. DASHBOARD PANEL (Left) --- */
.dashboard-panel {
    background: var(--km-bg-sidebar);
    border-right: 1px solid var(--km-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    /* Grid controls width, remove resize for stability */
    /* resize: horizontal; */
    z-index: 10;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
}

/* Dashboard Header */
.dash-header {
    padding: 15px;
    border-bottom: 1px solid var(--km-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--km-surface);
}

.dash-title {
    font-size: 1.3rem;
    /* Increased from 1.0rem */
    font-weight: 700;
    color: var(--km-teal);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dash-title i {
    font-size: 1.5rem;
    /* Larger Icon */
    color: var(--km-amber);
}

/* Tooltips for Desktop Nav */
.nav-icon {
    position: relative;
    /* For Tooltip positioning */
}

.nav-icon:hover::after {
    content: attr(title);
    position: absolute;
    right: 120%;
    /* Show to left of icon */
    top: 50%;
    transform: translateY(-50%);
    background: var(--km-teal);
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
    opacity: 0;
    animation: fadeInTooltip 0.2s forwards;
}

@keyframes fadeInTooltip {
    to {
        opacity: 1;
    }
}

/* Chart Text Toggle */
.chart-style-text-toggle {
    display: flex;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--km-text-light);
    cursor: pointer;
    background: var(--km-bg-main);
    padding: 4px 10px;
    border-radius: 15px;
    border: 1px solid var(--km-border);
}

.style-opt {
    transition: color 0.2s;
}

.style-opt.active {
    color: var(--km-gold);
    /* Or Teal based on preference, Gold fits mystical */
    font-weight: 700;
}

.style-opt:hover {
    color: var(--km-teal);
}

.separator {
    color: var(--km-border);
}

/* Tabs */
.dash-tabs {
    display: flex;
    background: var(--km-bg-sidebar);
    padding: 0 10px;
    border-bottom: 1px solid var(--km-border);
}

.dash-tab {
    padding: 12px 15px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--km-text-light);
    position: relative;
    transition: all 0.2s;
    font-weight: 500;
}

.dash-tab.active {
    color: var(--km-teal);
    font-weight: 600;
}

.dash-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--km-teal);
    border-radius: 3px 3px 0 0;
}

/* Content Area */
.dash-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: var(--km-bg-sidebar);
}

/* --- 2. STAGE PANEL (Center) --- */
.stage-panel {
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--km-bg-main);
    overflow: hidden;
    min-width: 0;
    /* Important for Grid */
}

.stage-view {
    flex: 1;
    display: none;
    overflow-y: auto;
    padding: 20px;
    position: relative;
    padding-bottom: 140px;
    /* Clear fixed input bar */
}

.stage-view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Manuscripts Floating Input Bar */
.input-stage-wrapper {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 80%;
    max-width: 800px;
    /* Clean Paper Style */
    background-color: #FFFFFF;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E");
    padding: 15px 25px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* Ancient Manuscript Shape: TR & BL Rounded */
    border-radius: 0 20px 0 20px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.05);
    /* Thin Amber Border */
    border: 1px solid rgba(207, 144, 3, 0.3);
}

.input-box-row {
    display: flex;
    align-items: center;
    background: transparent;
    border-bottom: 1px solid rgba(207, 144, 3, 0.2);
    /* faint amber line */
    padding: 5px 0;
}

.input-box-row input {
    flex: 1;
    border: none;
    padding: 10px;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    outline: none;
    background: transparent;
    color: var(--km-teal);
}

.input-box-row input::placeholder {
    color: #95a5a6;
    font-style: italic;
}

.input-box-row input {
    flex: 1;
    border: none;
    padding: 10px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
}

.send-btn,
.mic-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--km-teal);
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.send-btn:hover,
.mic-btn:hover {
    background: var(--km-accent-light);
}

.selectors-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.selector-container {
    position: relative;
    /* For Popup context */
}

/* --- 3. NAV RAIL (Right) --- */
.nav-rail {
    background: var(--km-bg-sidebar);
    border-left: 1px solid var(--km-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    gap: 20px;
    z-index: 30;
}

.nav-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--km-teal);
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
}

.nav-icon:hover {
    background: rgba(42, 75, 89, 0.1);
}

.nav-icon.active {
    background: var(--km-teal);
    color: #fff;
    box-shadow: 0 4px 12px rgba(42, 75, 89, 0.3);
}

/* --- SELECTORS (Restored Logic Style) --- */
.selectors-row {
    display: flex;
    gap: 15px;
    padding: 0 5px;
}

.selector-container {
    position: relative;
}

.selector-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Removed padding/border/radius that caused "circle" look */
    padding: 5px;
    background: transparent;
    border: none;
    border-radius: 0;
    font-size: 0.8rem;
    /* Reduced from 0.9rem to fit better */
    color: var(--km-teal);
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    /* Prevent wrapping */
    transition: all 0.2s;
    /* Optimize for Mobile Taps */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.selector-trigger span {
    display: inline-block;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.selector-trigger:hover {
    color: var(--km-amber);
    /* No bg change */
}

/* Hide the chevron arrow */
.selector-trigger .fa-chevron-down {
    display: none;
}

.selector-label {
    /* Recreating the text label "Mode: Open Learning" */
}

.selector-popup {
    position: absolute;
    bottom: 130%;
    /* Higher padding */
    left: 50%;
    transform: translateX(-50%);
    /* Center Horizontal */
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    min-width: 250px;
    /* Wider to avoid horizontal scroll */
    display: none;
    z-index: 100;
    padding: 5px 0;
    max-height: 300px;
    overflow-y: auto;

    /* Animation Origin */
    transform-origin: bottom center;
}

.popup-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--km-text-light);
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid var(--km-border);
    letter-spacing: 0.5px;
}

.selector-popup.show {
    display: block;
    animation: popUp 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes popUp {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.9) translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) scale(1) translateY(0);
    }
}

.popup-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--km-text);
    border-radius: 4px;
}

.popup-item:hover {
    background: var(--km-accent-light);
    color: var(--km-amber);
}

.popup-item.active {
    background: rgba(42, 75, 89, 0.1);
    font-weight: 600;
}

/* --- Voice Input Animation --- */
.input-actions i.recording {
    color: #ff4444 !important;
    animation: micPulse 1.5s infinite;
    transform-origin: center;
}

@keyframes micPulse {
    0% {
        transform: scale(1);
        text-shadow: 0 0 0 rgba(255, 68, 68, 0.7);
    }

    50% {
        transform: scale(1.2);
        text-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
    }

    100% {
        transform: scale(1);
        text-shadow: 0 0 0 rgba(255, 68, 68, 0.7);
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s;
}

.modal-card {
    background: #fff;
    width: 90%;
    max-width: 400px;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    margin: 0;
    font-family: 'Cinzel Decorative', serif;
    color: var(--km-teal);
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--km-text-light);
}

.balance-card {
    background: linear-gradient(135deg, var(--km-teal), #1a3a4a);
    color: #fff;
    padding: 20px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.balance-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
}

.redeem-input-row {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.redeem-input-row input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--km-border);
    border-radius: 8px;
    outline: none;
}

.redeem-input-row button {
    background: var(--km-amber);
    color: #fff;
    border: none;
    padding: 0 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.session-info {
    margin-top: 20px;
    text-align: center;
    color: var(--km-text-light);
    font-size: 0.8rem;
    border-top: 1px solid var(--km-border);
    padding-top: 10px;
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    .app-container {
        display: flex;
        /* Switch to Flex column for simpler Mobile stacking */
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .stage-panel {
        flex: 1;
        /* Take remaining height */
        min-width: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Mobile Input Font Size Fix (Prevent Zoom) & Scrollbars */
    .input-box-row input {
        font-size: 16px !important;
        /* Prevents iOS Zoom */
    }

    /* Hide Scrollbars for Clean UI */
    .stage-view::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }

    .selectors-row::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }

    .input-box-row input {
        font-size: 16px !important;
        /* Prevents iOS Zoom */
    }

    /* Hide Scrollbars for Clean UI */
    .stage-view::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }

    .selectors-row::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }

    .mobile-header {
        display: flex;
        /* Ensure Logo is bold */
    }

    .mobile-header h1,
    .logo-text {
        font-weight: 800 !important;
        /* Thicker Logo */
        text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3);
    }

    /* Fix First Message Clipping behind Header */
    .stage-view {
        padding-top: 85px !important;
    }

    .dashboard-handle {
        display: block;
    }

    /* .dash-header used to be here, removed empty rule */

    .nav-rail {
        display: none;
    }

    /* Drawer: Slide from Left, Overlay handled by JS or simple click-out */
    .dashboard-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 400px;
        /* Cap width for Tablets */
        height: 100vh;
        transform: translateX(-100%) !important;
        /* Force hidden initially */
        z-index: 300;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.2);
        border-right: 1px solid var(--km-amber);
    }

    .dashboard-panel.open {
        transform: translateX(0) !important;
    }

    /* Overlay for Drawer */
    .drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 290;
        display: none;
        /* JS toggles class 'show' which sets block */
        backdrop-filter: blur(2px);
    }

    .drawer-overlay.show {
        display: block;
    }

    /* Input Floating on Mobile too */
    /* Input Floating on Mobile - REMOVE TRANSFORM to fix Fixed Children context */
    /* UI UNIFICATION: Match Desktop "Manuscript" Style exactly */
    .input-stage-wrapper {
        position: fixed;
        bottom: 20px;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: 92%;
        /* Slightly wider on mobile */
        transform: none;
        /* CRITICAL: Allows children to be fixed relative to viewport */
        padding: 15px;
        /* Manuscript Shape: Top-Right Bottom-Left Rounded */
        border-radius: 0 20px 0 20px;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        background-color: #FFFFFF;
        /* Paper Texture */
        background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E");
        border: 1px solid rgba(207, 144, 3, 0.3);
    }

    .selectors-row {
        overflow-x: auto;
        padding-bottom: 5px;
        justify-content: flex-start;
        /* Left align scrollable */
    }

    /* Clean Selectors on Mobile */
    .selector-trigger {
        padding: 5px;
    }

    .selector-trigger span {
        /* User said: "texts of selectors is seen cluttered" -> keep text but smaller, or hide? */
        /* "pop up in side" might mean labels breaking layout. */
        /* Let's keep icons + text but simpler. */
        display: inline-block;
        max-width: 80px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
    }

    .selector-trigger i {
        margin: 0;
    }

    /* Ensure popup width is managed */
    /* BOTTOM SHEET STYLE FOR POPUPS */
    /* BOTTOM SHEET STYLE FOR POPUPS (Portal Friendly) */
    .selector-popup.mobile-sheet {
        display: none;
        /* Default hidden */
        position: fixed;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: none !important;
        max-height: 60vh;
        z-index: 10000 !important;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
        background: #fff;
        padding: 20px;
        padding-bottom: 40px;
        overflow-y: auto;
        transform: none !important;
        /* Reset any transform */
    }

    .selector-popup.mobile-sheet.show {
        display: block !important;
        animation: mobileSlideUp 0.2s ease-out forwards;
    }

    @keyframes mobileSlideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .stage-view {
        padding-bottom: 350px;
        /* Increased to clear fixed input */
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* AI-style loader bubble */
.karmalipi-loader {
    display: flex;
    align-items: center;
    gap: 10px;

    /* Match AI bubble style */
    background: #fff;
    border: 1px solid rgba(42, 75, 89, 0.12);
    /* subtle teal border */
    border-left: 3px solid var(--km-teal);
    border-radius: 12px 12px 12px 6px;

    padding: 10px 14px;
    width: max-content;
    margin: 10px 0;
    align-self: flex-start;
    /* left aligned like AI messages */

    font-family: "Courier New", monospace;
    color: var(--km-teal);
}

/* Hollow teal box */
.karmalipi-loader .loader-box {
    width: 28px;
    height: 28px;
    border: 2px solid var(--km-teal);
    /* <-- hollow border */
    border-radius: 6px;
    background: transparent;
    /* <-- NO fill */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Amber dot orbiting in circular motion */
.karmalipi-loader .loader-dot {
    width: 6px;
    height: 6px;
    background: var(--km-amber);
    border-radius: 50%;
    position: absolute;
    animation: km-orbit 1.2s linear infinite;
}

/* Circular orbit animation */
@keyframes km-orbit {
    0% {
        transform: rotate(0deg) translateX(8px) rotate(0deg);
    }

    50% {
        transform: rotate(180deg) translateX(8px) rotate(-180deg);
    }

    100% {
        transform: rotate(360deg) translateX(8px) rotate(-360deg);
    }
}

/* Loader text */
.karmalipi-loader .loader-text {
    font-family: "Courier New", monospace;
    font-size: 13px;
    color: var(--km-teal);
    opacity: 0.95;
}