:root {
    --bg-main: #020202;
    --bg-sidebar: #0a0a0a;
    --bg-input: #0a0a0a;
    --text-primary: #00ff41;
    --text-secondary: #008f11;
    --accent: #00ff41;
    --border-color: #003b00;
    --hover-bg: #111111;
    --btn-primary: #001a00;
    --btn-hover: #002b00;
    --radius-lg: 4px;
    --radius-md: 2px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* 
 * The main application body theme configuration.
 * We use a dark aesthetic, reminiscent of the Matrix.
 * The height is set using 100dvh (dynamic viewport height) to help prevent
 * the UI from getting cut off on mobile devices when the address bar
 * or the virtual keyboard appears and disappears.
 */
body.dark-theme {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    /* fallback to vh for older browsers, dvh for modern responsive views */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    text-shadow: 0 0 5px rgba(0, 255, 65, 0.4);
}

/* Base Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* 
 * Sidebar container that holds menus, chats, and keys. 
 * Default width is generous for desktop, but will be toggled into
 * view intelligently on mobile via specialized classes.
 */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 10px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.sidebar-header {
    padding: 10px 5px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background-color: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background-color: var(--hover-bg);
}

.close-sidebar-btn {
    display: none; /* Hidden by default on desktop view */
}

.projects-section {
    margin-top: 20px;
    padding: 0 10px;
}

.projects-section h3 {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.new-project-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    margin-bottom: 10px;
}

.projects-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    margin-top: 20px;
    padding: 0 10px;
}

.history-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.chat-history ul {
    list-style: none;
}

.chat-history li {
    padding: 10px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    transition: background 0.2s;
}

.chat-history li:hover {
    background-color: var(--hover-bg);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.byot-ad {
    background: linear-gradient(135deg, #2b1f3a, #1a2a40);
    padding: 12px;
    border-radius: 8px;
    font-size: 12px;
}

.byot-ad span {
    font-weight: bold;
    color: var(--accent);
}

.settings-btn {
    width: 100%;
    padding: 10px;
    background-color: var(--btn-primary);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

/* 
 * Main Chat Area Container.
 * It flexes to fill the remaining space. Position relative is important here
 * so that modal components overlay correctly and input area anchors itself.
 * Added transition so that when the sidebar opens on mobile, the entire
 * chat area physically "readjusts" (slides) to accommodate it instead of being 
 * rudely covered up.
 */
.chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Prevent shrinking below zero so input doesn't get squeezed */
    min-width: 0; 
    transition: transform 0.3s ease;
}

/* 
 * Elegant elegant falling code background canvas. 
 * Dimmed using opacity and locked from clicks so it doesn't interfere.
 */
.matrix-canvas {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    z-index: 0;
    opacity: 0.25; /* Noticeably brighter digital rain backdrop */
    pointer-events: none;
}

/* 
 * Transparent gesture overlay for mobile. When the sidebar opens, this overlay
 * fades in over the main chat field. Tapping it retracts the sidebar.
 */
.sidebar-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-header {
    display: none;
    padding: 15px;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
}

.chat-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 40px 15%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: relative;
    z-index: 10;
}

.greeting-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 30px;
    animation: fadeIn 1s ease-out;
}

.logo-circle {
    width: 64px;
    height: 64px;
    background: #000;
    border: 2px solid #00ff41;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
    color: #00ff41;
    box-shadow: 0 0 15px rgba(0,255,65,0.6);
}

.greeting-container h1 {
    font-size: 36px;
    color: #00ff41;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0px #003b00;
}

.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.action-card {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.action-card:hover {
    background-color: var(--hover-bg);
    transform: translateY(-2px);
}

/* Input Area */
.input-area {
    padding: 20px 15%;
    background: transparent;
    position: relative;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--bg-input);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    gap: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.mode-select {
    background: transparent;
    color: var(--accent);
    border: none;
    outline: none;
    font-size: 14px;
    cursor: pointer;
}

.mode-select option {
    background: var(--bg-sidebar);
}

#chat-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    resize: none;
    font-family: inherit;
    max-height: 200px;
}

.send-btn, .icon-btn {
    background: var(--text-primary);
    color: var(--bg-main);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.icon-btn {
    background: transparent;
    color: var(--text-secondary);
}

.send-btn:hover, .icon-btn:hover {
    transform: scale(1.05);
}

.icon-btn:hover {
    color: var(--accent);
}

/* Voice recording blinker */
@keyframes pulseRed {
    0% { color: var(--text-secondary); }
    50% { color: #f44336; }
    100% { color: var(--text-secondary); }
}

.icon-btn.recording {
    animation: pulseRed 1.5s infinite;
}

.icon-btn.tts-active {
    color: #4ade80; /* Sleek futuristic green */
}

.disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 10px;
}

.api-indicator {
    color: #ffd700;
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 15px;
    max-width: 800px;
    line-height: 1.6;
}

.message.user {
    align-self: flex-end;
    background-color: var(--bg-sidebar);
    padding: 12px 18px;
    border-radius: 20px;
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
}

/* Loading / Throught Process */
.thought-status-container {
    padding: 10px 15%;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: -15px;
    position: relative;
    z-index: 10;
}

.italic-text {
    font-style: italic;
    font-size: 13px;
    color: var(--text-primary);
}

.pulse-ring {
    width: 8px;
    height: 8px;
    background-color: var(--text-primary);
    border-radius: 0;
    animation: matrixPulse 1.5s infinite;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-sidebar);
    padding: 30px;
    border-radius: var(--radius-md);
    width: 400px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-content input {
    padding: 12px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
}

.modal-content button {
    padding: 12px;
    background: var(--accent);
    color: var(--bg-main);
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

.secondary-btn {
    background: var(--btn-primary) !important;
    color: var(--text-primary) !important;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 255, 65, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(0, 255, 65, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 255, 65, 0); }
}

@keyframes matrixPulse {
    0% { opacity: 1; text-shadow: 0 0 10px #00ff41; }
    50% { opacity: 0.5; text-shadow: none; }
    100% { opacity: 1; text-shadow: 0 0 10px #00ff41; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 
 * Dynamic Media Queries and Device Targeting
 * Enquires screen size to adjust layouts on the fly, tailoring
 * elements for standard mobile devices and specialized split/foldable screens.
 */
@media (max-width: 768px) {
    /* 
     * Mobile views require the sidebar to be hidden off-screen by default.
     * Toggling '.open' will bring it cleanly into view.
     */
    .sidebar { 
        position: absolute; 
        transform: translateX(-100%); 
        z-index: 1000; 
        height: 100%; 
        box-shadow: 2px 0 10px rgba(0,0,0,0.8);
    }
    
    .sidebar.open { 
        transform: translateX(0); 
    }
    
    /* Reveal the close sidebar cross button explicitly on mobile devices */
    .close-sidebar-btn {
        display: block !important;
    }
    
    /* 
     * The magical readjustment request.
     * When the sidebar is toggled open, we physically push the main chat area
     * completely out of the way. Coupled with the overlay, it looks clean and natural.
     */
    body.sidebar-open .chat-container {
        transform: translateX(260px);
    }
    
    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-header { 
        display: flex; 
        justify-content: space-between;
        padding: 10px 15px; /* Tighter padding for mobile ratios */
    }
    
    .chat-scroll-area { 
        padding: 15px 10px; /* Better ratio for reading space */
        gap: 16px;
    }
    
    .input-area { 
        padding: 10px 10px; 
        /* Ensure the input area stays visible above virtual keyboards */
        position: relative;
        bottom: 0;
        z-index: 100;
    }
    
    .input-wrapper {
        flex-wrap: wrap; /* allow wrapping on super tiny screens */
        padding: 8px 12px;
        gap: 10px;
    }

    /* Bubble read-ratios optimization for mobile */
    .message {
        font-size: 14px;
        gap: 10px;
    }
    .message.user {
        padding: 10px 14px;
    }
    
    .greeting-container h1 { font-size: 22px; }
    .logo-circle { width: 50px; height: 50px; font-size: 24px; }
}
/* 
 * Samsung Z Fold specific layouts.
 * Handling the ultra-narrow cover screen (approx. 330px - 380px wide).
 * Extremely constrained real-estate, aggressive ratio shrinking.
 */
@media (max-width: 380px) {
    .greeting-container h1 { font-size: 18px; }
    .logo-circle { width: 44px; height: 44px; font-size: 20px; }
    
    .quick-actions {
        flex-direction: column;
        width: 100%;
        gap: 6px;
    }
    
    .action-card {
        width: 100%;
        text-align: center;
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .input-wrapper {
        padding: 6px 8px;
        gap: 6px;
    }
    
    #chat-input {
        font-size: 13px;
    }
    
    .mode-select {
        font-size: 11px;
        max-width: 100px;
        padding: 2px;
    }
    
    body.sidebar-open .chat-container {
        /* On extreme narrow devices, push exact width of sidebar */
        transform: translateX(260px);
    }
}

/* 
 * Samsung Z Fold specific layouts.
 * Handling the opened wide inner screen that behaves like a mini-tablet.
 */
@media (min-width: 381px) and (max-width: 600px) {
    .input-wrapper {
        padding: 8px 12px;
    }
    .sidebar { width: 280px; }
    
    body.sidebar-open .chat-container {
        transform: translateX(280px); /* Match wider sidebar push */
    }
}
