/* 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: 11000;
    /* Drawer Layer */
    /* 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;
    /* Right column is `auto` — oracle-tray controls its own width (320px expanded / 60px collapsed) */
    grid-template-columns: 400px minmax(0, 1fr) auto;
    height: 100vh; height: 100dvh;
    width: 100vw;
    position: relative;
    background: var(--km-bg-main);
    overflow: clip;
    /* clip prevents scrollbars; unlike hidden, does NOT create scroll container — positioned children (edge handle) can escape */
}

/* --- 1. DASHBOARD PANEL (Left) --- */
.dashboard-panel {
    background: var(--km-bg-sidebar);
    border-right: none;
    /* Removed for unified canvas */
    display: flex;
    flex-direction: column;
    overflow: visible;
    /* EXPERT FIX: Required for handle to protrude */
    position: relative;
    z-index: auto;
    /* EXPERT FIX: auto prevents stacking context, allowing handle and tooltips to overlap as needed */
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.02);
    /* Soft depth instead of border */
}

/* Edge handle must sit above stage-panel (1100) so it's always clickable */
.dash-edge-handle {
    z-index: 1200 !important;
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
}

/* Dashboard Header */
.dash-header {
    padding: 8px 12px;
    /* Reduced from 15px */
    border-bottom: none;
    /* Removed for unified canvas */
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    height: 50px;
    /* Force thinner fixed height if needed, or just let padding dictate */
}

.dash-title {
    font-size: 1.15rem;
    /* Reduced from 1.3rem */
    font-weight: 700;
    color: var(--km-teal);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-title img {
    height: 42px;
    /* Canonical value — also defined in console.css with !important for .logo-full */
    width: auto;
}

/* NOTE: .dash-title .logo-icon sizing is managed solely in console.css (line ~164) */

.dash-title i {
    font-size: 1.2rem;
    color: var(--km-amber);
}

/* (Removed duplicate active/tooltip rules) */

/* Chart Text Toggle - Compact */
.chart-style-text-toggle {
    display: flex;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--km-text-light);
    cursor: pointer;
    background: rgba(47, 93, 98, 0.03);
    /* Soft background instead of border */
    padding: 2px 6px;
    border-radius: 12px;
    border: none;
    /* Removed hard border */
    align-items: center;
}

.style-opt {
    transition: all 0.2s;
    padding: 2px 6px;
    border-radius: 8px;
}

.style-opt.active {
    background: var(--km-teal);
    color: #fff;
    font-weight: 600;
}

.style-opt:hover:not(.active) {
    color: var(--km-teal);
    background: rgba(0, 0, 0, 0.03);
}

.separator {
    display: none;
    /* Hide separator for pill look */
}

/* Tabs */
.dash-tabs {
    display: flex;
    background: var(--km-bg-sidebar);
    padding: 0 10px;
    border-bottom: 1px solid var(--km-border);
}

/* Chart Sub-Tabs - Horizontal Scroll Container */
.chart-sub-tabs-bar {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--km-amber) transparent;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding: 4px 0;
    flex-wrap: nowrap;
    max-width: 100%;
}

.chart-sub-tabs-bar::-webkit-scrollbar {
    height: 4px;
}

.chart-sub-tabs-bar::-webkit-scrollbar-track {
    background: transparent;
}

.chart-sub-tabs-bar::-webkit-scrollbar-thumb {
    background: var(--km-amber);
    border-radius: 4px;
}

/* NOTE: .sub-tab-item below is the canonical design, but is overridden at runtime
   by dashboard.js injectStyles(). To change chip appearance, edit injectStyles(). */
.sub-tab-item {
    flex-shrink: 0;
    padding: 6px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    border: 1px solid var(--km-border);
    border-radius: 16px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    color: var(--km-text-light);
    background: transparent;
}

.sub-tab-item:hover {
    border-color: var(--km-amber);
    color: var(--km-teal);
}

.sub-tab-item.active {
    background: var(--km-teal);
    color: #fff;
    border-color: var(--km-teal);
    font-weight: 600;
}

.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: 5px;
    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: visible;
    overflow-y: clip;
    min-width: 0;
    height: 100%;
    min-height: 0;
    z-index: auto;
    /* EXPERT FIX: auto prevents stacking context */
}

/* Base: all stage views hidden by default */
.stage-view {
    flex: 1;
    min-height: 0;
    /* FIX: allows height:100% on children to resolve in flex column */
    display: none;
    position: relative;
}

/* Text chat view — scrollable with input bar padding */
#view-text.stage-view {
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 200px;
    /* space for floating input bar */
}

/* Audio + Video views — fill panel completely, no scroll, no padding */
#view-audio.stage-view,
#view-video.stage-view {
    overflow: hidden;
    padding: 0;
    display: none;
    flex: 1;
    min-height: 0;
    width: 100%;
    align-items: stretch;
    /* FIX: stretch so scene-wrapper fills full height */
    justify-content: center;
}

#view-audio.stage-view.active,
#view-video.stage-view.active {
    display: flex;
}

/* Audio Sanctum inner layout */
.audio-sa-wrapper {
    flex: 1;
    min-height: 0;
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFFCF8;
}

/* Canvas fills its positioned parent via absolute — resize() sets width/height attributes */
#mandala-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Report view — scrollable, comfortable padding */
#view-report.stage-view {
    overflow-y: auto;
    padding: 30px;
}

.stage-view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Overrides for media views (flex layout) */
#view-audio.stage-view.active,
#view-video.stage-view.active {
    display: flex !important;
}

/* Stage-level loading overlay — shown during experience generation */
#stage-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 252, 248, 0.92);
    backdrop-filter: blur(6px);
    gap: 16px;
    pointer-events: none;
    animation: fadeIn 0.3s ease;
}

#stage-loading-overlay .stage-loader-icon {
    font-size: 2.8rem;
    animation: spinSlow 4s linear infinite;
    color: var(--km-amber);
}

#stage-loading-overlay .stage-loader-text {
    font-family: 'Cinzel Decorative', serif;
    font-size: 0.9rem;
    color: var(--km-teal);
    letter-spacing: 1px;
    opacity: 0.85;
}

/* Back-to-chat pill — bottom-left corner, not top-left, so it doesn't block stage content */
#back-to-chat-btn {
    position: absolute;
    bottom: 16px;
    left: 16px;
    top: auto !important;
    z-index: 500;
}


/* Manuscripts Floating Input Bar */
.input-stage-wrapper {
    position: absolute;
    bottom: 45px;
    /* Shifted up to make room for disclaimer */
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 80%;
    max-width: 800px;
    /* Clean Paper Style & Glassmorphism */
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    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.05'/%3E%3C/svg%3E");
    padding: 15px 25px;
    z-index: 2000;
    /* ABOVE sidebars (1000) to prevent tooltip clipping */
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* Ancient Manuscript Shape: TR & BL Rounded */
    border-radius: 0 20px 0 20px;
    box-shadow: 0 12px 40px rgba(42, 75, 89, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
    /* Elevated shadow */
    border: 1px solid rgba(207, 144, 3, 0.15);
    /* Soft amber defining border to prevent invisibility */
}

.ai-disclaimer {
    position: absolute;
    bottom: 15px;
    left: 0;
    right: 0;
    font-size: 0.72rem;
    color: var(--km-text-light);
    text-align: center;
    opacity: 0.95;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 0.2px;
    z-index: 50;
    background: var(--km-bg-main);
    padding:5px 0;
    border-radius: 0 0 20px 20px;
}

.input-box-row {
    display: flex;
    align-items: center;
    background: transparent;
    border-bottom: none;
    /* Removed internal partition */
    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 textarea {
    flex: 1;
    border: none;
    padding: 10px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    background: transparent;
    resize: none;
    /* Disable manual resize */
    /* Enable manual scroll if content exceeds max-height */
    overflow-y: auto !important;
    /* Hide scrollbar until max-height */
    min-height: 44px;
    /* Match previous input height approx */
    max-height: 120px;
    /* Cap growth */
    line-height: 1.4;
}

/* AI Message Border - Stronger & Forced */
/* Chat Channel Container */
#chat-history {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 20px;
}

/* AI Message Border - Expert Design */
.ai-message {
    border: none !important;
    /* Removed full border for unified canvas */
    border-left: 2px solid var(--km-amber) !important;
    /* Elegant thin left border */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
    /* Very soft shadow */
    background: rgba(250, 247, 242, 0.5);
    /* Subtle tint against white canvas */
    border-radius: 4px 12px 12px 12px;
    /* Sharper Top-Left */
    margin: 6px 0 !important;
    /* Spacing */
    align-self: flex-start;
    /* Left Align */
    width: fit-content;
    max-width: 90%;
    /* Constraint within 800px channel */
    display: block;
    /* Ensure margins apply */
    position: relative;
    /* Stacking context */
    padding: 14px 24px !important;
    /* Increased padding, esp Left */
    overflow-wrap: break-word !important;
    /* Proper word breaking */
    word-break: break-word !important;
    /* No mid-word breaks */
    transition: all 0.2s;
    /* Added for selection animation */
}

/* Selected state — amber left-border accent (passive, non-intrusive indicator) */
.ai-message.selected {
    border-color: transparent !important;
    border-left: 3px solid var(--km-amber) !important;
    background: #fdfbf7;
    position: relative;
}

/* Removed: "Context Active" badge — replaced by amber border accent */

/* AI messages are no longer whole-bubble clickable. Pill handles interaction. */
.ai-message {
    cursor: default !important;
}

/* ================================================================
   FLOATING EXPERIENCE PILL
   - Renders only on insight messages (truthHash present)
   - Desktop: shows on hover, fades in/out
   - Mobile: shows on bubble tap, hides on tap-away
================================================================= */
.exp-floating-pill {
    position: absolute;
    bottom: 8px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(250, 247, 242, 0.96);
    border: 1px solid rgba(200, 155, 60, 0.3);
    border-radius: 24px;
    padding: 4px 6px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    /* Ghost hint at 0.18 — user can SEE something is there, full reveal on hover */
    opacity: 0.18;
    pointer-events: none;
    transition: opacity 0.06s ease, transform 0.06s ease;
    transform: translateY(0);
    z-index: 10;
    backdrop-filter: blur(4px);
}

.exp-floating-pill.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.exp-pill-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--km-teal);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
    font-size: 0;
    /* Hide default button text */
}

.exp-pill-btn .material-icons-round {
    font-size: 16px;
    color: var(--km-teal);
    transition: color 0.15s ease;
}

.exp-pill-btn:hover {
    background: var(--km-amber);
    transform: scale(1.12);
}

.exp-pill-btn:hover .material-icons-round {
    color: #fff;
}

.exp-pill-btn:active {
    transform: scale(0.95);
}

/* Tooltip via title attribute (native) + aria-label for accessibility */
.exp-pill-btn[title]:focus-visible {
    outline: 2px solid var(--km-amber);
    outline-offset: 2px;
}

/* Mobile: pill is a bit larger for touch targets */
@media (max-width: 767px), (max-width: 1024px) and (orientation: portrait) {
    .exp-pill-btn {
        width: 36px;
        height: 36px;
    }

    .exp-pill-btn .material-icons-round {
        font-size: 18px;
    }

    .exp-floating-pill {
        padding: 5px 8px;
        bottom: 10px;
        right: 8px;
    }
}

/* ================================================================
   ORACLE TRAY — Generated Experiences Inline Section
   Replaces: collapsible single-row (user wants inline list)
================================================================= */
.tray-gen-exp-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.tray-gen-exp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0 8px;
    flex-shrink: 0;
}

.gen-exp-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--km-text-light);
    font-family: 'Outfit', sans-serif;
}

.gen-exp-count {
    background: var(--km-amber);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ================================================================
   GENERATED EXPERIENCES — Tray Pills
================================================================= */
.gen-exp-pills-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.gen-exp-tray-pill {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    background: #fcf9f2;
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--km-teal);
    font-family: 'Manrope', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition-property: background-color, border-color, color, transform;
    transition-duration: 90ms;
    transition-timing-function: ease-out;
    width: 100%;
}

.gen-exp-tray-pill:hover {
    background: rgba(212, 175, 55, 0.15);
    transform: translateY(-1px);
}

.gen-exp-tray-pill i {
    font-size: 18px;
    color: var(--km-gold);
}

.gen-exp-tray-pill .badge {
    margin-left: auto;
    background: var(--km-amber);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* ================================================================
   GENERATED EXPERIENCES — Bottom Sheet Panel
================================================================= */
.gen-exp-panel-scrim {
    position: fixed;
    inset: 0;
    background: rgba(30, 25, 15, 0.35);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.gen-exp-panel-scrim.open {
    opacity: 1;
    pointer-events: auto;
}

.gen-exp-panel {
    position: fixed;
    bottom: 130px;
    /* Sits above the fixed input island (30px offset + ~80px input height + 20px buffer) */
    left: 0;
    right: 0;
    max-width: 680px;
    margin: 0 auto;
    background: #FAF7F2;
    border-radius: 20px 20px 0 0;
    border-top: 2px solid var(--km-amber);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
    z-index: 10001;
    /* Above mobile dashboard (z-index: 9500) and all overlays */
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    max-height: 55vh;
}

.gen-exp-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.gen-exp-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(47, 93, 98, 0.08);
    flex-shrink: 0;
}

.gen-exp-panel-title {
    font-family: 'Cinzel Decorative', serif;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--km-teal);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.gen-exp-panel-close {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(42, 75, 89, 0.12);
    border-radius: 50%;
    background: rgba(42, 75, 89, 0.05);
    color: var(--km-teal);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s cubic-bezier(0.4,0,0.2,1);
    padding: 0;
}

.gen-exp-panel-close:hover {
    background: rgba(42, 75, 89, 0.12);
    color: var(--km-amber);
    transform: rotate(90deg) scale(1.1);
}

.gen-exp-panel-list {
    overflow-y: auto;
    padding: 12px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.gen-exp-panel-list::-webkit-scrollbar {
    width: 4px;
}

.gen-exp-panel-list::-webkit-scrollbar-thumb {
    background: rgba(200, 155, 60, 0.3);
    border-radius: 4px;
}

/* Handle bar at top of panel */
.gen-exp-panel-handle {
    width: 36px;
    height: 4px;
    background: rgba(47, 93, 98, 0.2);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
}

/* Utility spin keyframe — used by exp-pill-btn generating state */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Mic Button Polish */
#mic-btn {
    color: var(--km-teal) !important;
    background: transparent;
    transition-property: color, background-color, transform, opacity;
    transition-duration: 120ms;
    transition-timing-function: ease-out;
}

#mic-btn i.fa-stop-circle {
    color: var(--km-amber) !important;
    animation: km-pulse 1.5s infinite;
}

@keyframes km-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.send-btn,
.mic-btn {
    background: rgba(47, 93, 98, 0.05);
    /* Subtle background block */
    border: none;
    cursor: pointer;
    color: var(--km-teal);
    padding: 8px;
    border-radius: 50%;
    transition-property: background-color, color, transform, opacity;
    transition-duration: 120ms;
    transition-timing-function: ease-out;
}

.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. ORACLE TRAY (Right) - Context & History Manager --- */
.oracle-tray {
    background: rgba(250, 247, 242, 0.85);
    border-left: none;
    /* Removed for unified canvas */
    display: flex;
    flex-direction: column;
    z-index: auto;
    /* EXPERT FIX: auto prevents stacking context */
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.02);
    /* Soft ambient shadow */
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 320px;
    /* Expanded Width */
    overflow: hidden;
    position: relative;
}

.oracle-tray.collapsed {
    width: 60px;
    /* Collapsed Width */
}

/* Collapsed Icons Container */
.tray-collapsed-icons {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 30px;
    gap: 24px;
    width: 60px;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.oracle-tray.collapsed .tray-collapsed-icons {
    opacity: 1;
    pointer-events: all;
}

/* Expanded Content Container */
.tray-expanded-content {
    display: flex;
    flex-direction: column;
    width: 320px;
    height: 100%;
    opacity: 1;
    pointer-events: all;
    transition: opacity 0.2s ease;
    padding: 20px;
    box-sizing: border-box;
}

.oracle-tray.collapsed .tray-expanded-content {
    opacity: 0;
    pointer-events: none;
}

/* Header */
.tray-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(200, 155, 60, 0.2);
    /* km-amber tinted */
}

.tray-header h3 {
    margin: 0;
    font-family: 'Cinzel Decorative', serif;
    color: var(--km-teal);
    font-size: 1.1rem;
}

#tray-collapse-btn {
    background: none;
    border: none;
    color: var(--km-text-light);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 5px;
    transition: color 0.2s;
}

#tray-collapse-btn:hover {
    color: var(--km-amber);
}

/* Sections */
.tray-section {
    margin-bottom: 25px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.history-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--km-text-light);
    margin-bottom: 15px;
    font-weight: 600;
}

/* Empty State */
.empty-state {
    font-size: 0.85rem;
    color: #95a5a6;
    font-style: italic;
    text-align: center;
    padding: 20px 0;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    border: 1px dashed rgba(0, 0, 0, 0.08);
}

/* Context Actions */
.context-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tray-action-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: rgba(47, 93, 98, 0.02);
    /* Softer background */
    border: 1px solid transparent;
    /* Flattened */
    border-radius: 10px;
    color: var(--km-teal);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition-property: transform, background-color, border-color, color, box-shadow;
    transition-duration: 90ms;
    transition-timing-function: ease-out;
    box-shadow: none;
    /* Removed hard shadow */
}

.tray-action-btn i {
    font-size: 1.2rem;
    color: var(--km-amber);
}

.tray-action-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(200, 155, 60, 0.3);
    background: #fff;
    /* Pop on hover */
}

/* Generating Status (Pulse) */
.tray-action-btn.generating {
    background: rgba(200, 155, 60, 0.05);
    border-color: var(--km-amber);
    pointer-events: none;
    animation: generatePulse 1.5s infinite alternate;
}

@keyframes generatePulse {
    from {
        box-shadow: 0 0 5px rgba(200, 155, 60, 0.2);
    }

    to {
        box-shadow: 0 0 15px rgba(200, 155, 60, 0.5);
    }
}

/* History List */
.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
    /* Scrollbar space */
}

/* Custom Scrollbar for history */
.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(200, 155, 60, 0.3);
    border-radius: 4px;
}

.history-card {
    background: #fff;
    border: 1px solid rgba(47, 93, 98, 0.05);
    border-left: 3px solid var(--km-amber);
    padding: 12px;
    border-radius: 6px 10px 10px 6px;
    cursor: pointer;
    transition-property: background-color, border-color, transform, box-shadow;
    transition-duration: 100ms;
    transition-timing-function: ease-out;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-card:hover {
    background: #fafafa;
    border-color: rgba(47, 93, 98, 0.15);
}

.history-title {
    font-size: 0.8rem;
    color: var(--km-text);
    font-weight: 500;
    line-height: 1.3;
}

.history-meta {
    font-size: 0.7rem;
    color: var(--km-text-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-badge {
    background: rgba(47, 93, 98, 0.1);
    color: var(--km-teal);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* Icons for tray */
.nav-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--km-teal);
    cursor: pointer;
    transition-property: transform, background-color, border-color, color;
    transition-duration: 90ms;
    transition-timing-function: ease-out;
    background: transparent;
    position: relative;
    border: 1px solid transparent;
}

.nav-icon[data-label]::after {
    content: attr(data-label);
    position: absolute;
    right: 60px;
    background: var(--km-teal);
    color: #FAF7F2;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateX(10px);
    transition: opacity 80ms ease-out, transform 80ms ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 11000;
}

.nav-icon:hover::after {
    opacity: 1;
    transform: translateX(0);
}

.nav-icon .material-symbols-outlined {
    font-size: 24px;
    font-variation-settings: 'FILL' 0, 'wght' 300;
    transition: color 90ms ease-out;
}

.nav-icon:hover {
    background: rgba(47, 93, 98, 0.05);
    color: var(--km-amber);
    border-color: rgba(200, 155, 60, 0.2);
    transform: translateY(-1px);
}

/* Bottom Actions in Expanded State */
.nav-rail-bottom {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-rail-bottom .nav-icon {
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    padding: 0 15px;
    height: 40px;
}

.nav-rail-bottom .nav-text {
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-rail-bottom .nav-icon::after {
    display: none;
    /* No tooltip in expanded mode */
}

/* --- SELECTORS (Restored Logic Style) --- */
.selectors-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    /* Comfortable gap */
    padding: 0 8px;
    /* Safe edge buffer */
    justify-content: space-between;
    /* The Root Solution for Even Spacing */
    align-items: center;
}

.selector-container {
    position: relative;
    /* Natural Width */
}

.selector-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px;
    background: transparent;
    border: none;
    border-radius: 0;
    font-size: 0.8rem;
    color: var(--km-teal);
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.selector-trigger span {
    display: inline-block !important;
    width: auto !important;
    vertical-align: middle;
    color: var(--km-amber);
    font-size: 0.7rem;
    min-width: 0;
    opacity: 1 !important;
    white-space: normal !important;
    line-height: 1.2;
    text-align: left;
    max-width: 160px;
}

/* FIX: Remove chevrons completely as requested */
.selector-trigger .fa-chevron-down {
    display: none !important;
}

.selector-trigger:hover {
    filter: brightness(1.2);
    /* Simple hover effect */
    background: transparent !important;
}

/* Hide the chevron arrow */
.selector-trigger .fa-chevron-down {
    display: none;
}


.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.65);
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s;
}

.modal-card {
    background: #fff;
    width: 90%;
    max-width: 420px;
    max-height: 85vh;           /* Cap height so it doesn't overflow viewport */
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;     /* Flex column so header is sticky, body scrolls */
    overflow: hidden;           /* Clip rounded corners cleanly */
}

/* Sticky header stays pinned while modal-body scrolls */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    flex-shrink: 0;             /* Never compress */
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.modal-header h3 {
    margin: 0;
    font-family: 'Cinzel Decorative', serif;
    color: var(--km-teal);
}

/* Scrollable modal body */
.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 24px;
}

/* ─── Unified Close Button ─────────────────────────────────────
   Use .km-close-btn on ANY close button across modals,
   drawers, panels, or split-screen overlays.
   Always pair with a <i class="material-icons-round">close</i>
──────────────────────────────────────────────────────────────── */
.km-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(42, 75, 89, 0.05);
    border: 1px solid rgba(42, 75, 89, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--km-teal);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s cubic-bezier(0.4,0,0.2,1);
    padding: 0;
    outline: none;
    flex-shrink: 0;
}

.km-close-btn:hover {
    background: rgba(42, 75, 89, 0.12);
    color: var(--km-amber);
    transform: rotate(90deg) scale(1.1);
}

.km-close-btn i,
.km-close-btn .material-icons-round,
.km-close-btn .material-symbols-outlined {
    font-size: 18px !important;
    line-height: 1;
    display: block;
}

/* Legacy alias — keeps existing HTML working without touching every button */
.close-modal-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(42, 75, 89, 0.05);
    border: 1px solid rgba(42, 75, 89, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--km-teal);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s cubic-bezier(0.4,0,0.2,1);
    padding: 0;
}

.close-modal-btn:hover {
    background: rgba(42, 75, 89, 0.12);
    color: var(--km-amber);
    transform: rotate(90deg) scale(1.1);
}

.close-modal-btn i,
.close-modal-btn .material-icons-round {
    font-size: 18px !important;
    line-height: 1;
    display: block;
}

.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: 767px), (max-width: 1024px) and (orientation: portrait) {

    /* --- DISABLE HOVERS & TOOLTIPS FOR TOUCH UI --- */
    .nav-icon::after {
        display: none !important;
    }

    .nav-icon:hover,
    .gen-exp-tray-pill:hover,
    .exp-pill-btn:hover,
    .tray-action-btn:hover,
    .history-card:hover {
        transform: none !important;
        background: inherit;
    }

    /* Mobile Input Font Size Fix (Prevent Zoom) & Scrollbars */
    .input-box-row input {
        font-size: 16px !important;
        /* Prevents iOS Zoom */
    }

    /* Keep floating experience pill fully visible on mobile */
    .exp-floating-pill {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* 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; height: 100dvh;
        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.65);
        z-index: 290;
        display: none;
    }

    .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 {
        z-index: 2000 !important;
        /* Unified with Desktop stack (Above Sidebars) */
        position: fixed;
        bottom: 45px;
        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;
        padding-left: 10px;
        /* Prevent first item touching edge */
        /* 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: 120px;
        /* Increased to clear fixed input */
    }

    /* 6. GENERATED EXPERIENCES PANEL - Mobile Bottom Sheet */
    .gen-exp-panel {
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: none !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 70vh !important;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .gen-exp-panel.open {
        transform: translateY(0);
    }

    .gen-exp-panel-header {
        padding: 20px;
        background: #fff;
        border-radius: 24px 24px 0 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .history-card {
        padding: 15px !important;
        margin-bottom: 12px !important;
        background: #fff !important;
        border: 1px solid var(--km-border) !important;
        border-radius: 12px !important;
    }
}

@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-size: 0.8rem;
    color: var(--km-teal);
    font-weight: 500;
}

/* REV 10: Chat Bubble Wrapping */
.chat-message,
.user-message,
.ai-message {
    overflow-wrap: anywhere;
    word-break: break-word;
    /* Standard */
    word-break: break-all;
    /* Aggressive for long strings without spaces */
    white-space: pre-wrap;
    /* Preserve newlines */
    overflow-x: hidden;
    /* Prevent horizontal scroll triggers */
    max-width: 100%;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

@keyframes fadeInTooltip {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(5px);
    }

    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* Webkit (Chrome, Edge, Safari) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
    /* Faded effect */
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.3);
}

/* Specific for Popups/Selectors */
.selector-popup::-webkit-scrollbar {
    width: 4px;
}

/* --- ASPECT HIGHLIGHTS --- */
.aspect-target rect,
.aspect-target polygon {
    stroke: var(--km-amber) !important;
    stroke-width: 3px !important;
    fill: rgba(207, 144, 3, 0.15) !important;
    filter: drop-shadow(0 0 4px var(--km-amber));
    transition: all 0.3s ease;
}

/* Specific handling for North Indian text */
.aspect-target text {
    fill: var(--km-amber) !important;
    font-weight: 800 !important;
    font-size: 1.1em;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.aspect-source rect,
.aspect-source polygon {
    stroke: var(--km-teal) !important;
    stroke-width: 3px !important;
}

.aspect-line {
    stroke-dasharray: 4;
    animation: dash 60s linear infinite;
    pointer-events: none;
    opacity: 0.6;
}

@keyframes dash {
    to {
        stroke-dashoffset: 1000;
    }
}

/* --- Tablet Landscape (Interactive Read-Only View) --- */
/* Target actual tablets (iPad), but NOT touch-enabled laptops, by checking for lack of hover capability */
@media screen and (orientation: landscape) and (max-width: 1024px) and (hover: none) and (pointer: coarse) {
    
    /* 1. READ-ONLY SPLIT VIEW (When Dashboard is Expanded) */
    /* Hide input bar and mobile header to maximize vertical space for reading charts, but keep the dash-header logo */
    html body .app-container:not(.dashboard-collapsed) .mobile-header,
    html body .app-container:not(.dashboard-collapsed) .input-stage-wrapper {
        display: none !important;
    }

    /* Show Keyboard FAB when input is hidden (Dashboard Expanded) */
    html body .app-container:not(.dashboard-collapsed) .chat-resume-fab {
        display: flex !important;
    }

    /* Hide Keyboard FAB when input is visible (Dashboard Collapsed) */
    html body .app-container.dashboard-collapsed .chat-resume-fab {
        display: none !important;
    }
    
    /* Obliterate any padding/margin that leaves a blank space when headers are hidden */
    html body .app-container:not(.dashboard-collapsed) .dashboard-panel,
    html body .app-container:not(.dashboard-collapsed) .stage-panel,
    html body .app-container:not(.dashboard-collapsed) .context-bar,
    html body .app-container:not(.dashboard-collapsed) .stage-view {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* Force panels to reach the absolute bottom of the screen */
    html body .app-container:not(.dashboard-collapsed) .dashboard-panel,
    html body .app-container:not(.dashboard-collapsed) .stage-panel {
        height: 100vh !important; height: 100dvh !important;
        height: 100dvh !important;
    }

    html body .app-container:not(.dashboard-collapsed) .stage-view {
        height: 100% !important; 
        padding-bottom: 20px !important;
    }
}

/* --- Mobile Landscape (The Blocker) --- */
@media screen and (orientation: landscape) and (max-height: 499px) {
    html body .app-container {
        display: none !important;
    }
    html body .landscape-blocker {
        display: flex !important;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: var(--km-bg-main);
        z-index: 999999;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 30px;
        color: var(--km-text);
    }
    html body .landscape-blocker i { font-size: 3rem; color: var(--km-amber); margin-bottom: 20px; }
    html body .landscape-blocker h2 { font-family: 'Cinzel Decorative', serif; color: var(--km-teal); margin-bottom: 15px; }
    html body .landscape-blocker p { color: var(--km-text-light); line-height: 1.6; max-width: 400px; }
}

/* --- Fix Overlapping Input Bar in Typing Mode --- */
@media screen and (orientation: landscape) and (max-width: 1024px) {
    html body .app-container.dashboard-collapsed .stage-view,
    html body .app-container.mobile-split-active .stage-view,
    html body .app-container .stage-view {
        padding-bottom: 150px !important; 
    }
    
    html body .app-container.dashboard-collapsed .input-stage-wrapper,
    html body .app-container.mobile-split-active .input-stage-wrapper,
    html body .app-container .input-stage-wrapper {
        bottom: 45px !important;
    }
    
    html body .app-container.dashboard-collapsed .ai-disclaimer,
    html body .app-container.mobile-split-active .ai-disclaimer,
    html body .app-container .ai-disclaimer {
        bottom: 15px !important;
        z-index: 1000 !important;
    }
}
