:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #475569;
    --secondary-hover: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --error: #ef4444;
    --success: #10b981;
}

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

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 0.9rem; /* Reduced base text size */
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}


/* Layout */
.container {
    width: 100%;
    max-width: 100vw;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-x: hidden;
}

header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.8rem; /* Reduced logo size */
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-color);
}

header p {
    color: var(--text-muted);
    font-size: 1rem;
}

/* Glassmorphism Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.glass-panel h2, .glass-panel h3 {
    margin-bottom: 15px;
    font-weight: 600;
}

#controls-section {
    margin-bottom: 20px;
    flex-shrink: 0;
}

/* Forms */
.controls-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.input-group {
    flex: 1;
    min-width: 200px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8rem; /* Reduced label size */
    color: var(--text-muted);
}

input, textarea {
    width: 100%;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Buttons */
.button-group {
    display: flex;
    gap: 10px;
}

button {
    padding: 8px 16px; /* Reduced button padding */
    border: none;
    border-radius: 6px;
    font-size: 0.85rem; /* Reduced button font size */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.secondary-btn {
    background-color: var(--secondary-color);
    color: white;
}

.secondary-btn:hover {
    background-color: var(--secondary-hover);
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Loader */
.loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Messages */
.message {
    margin-top: 15px;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.message.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

/* 3-Pane Workspace Grid */
.workspace-grid {
    display: grid;
    /* Documentation taking max space, chat hidden by default */
    grid-template-columns: minmax(280px, 320px) 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0; /* Important for scrollable children */
    transition: grid-template-columns 0.3s ease;
}

.workspace-grid.chat-open {
    grid-template-columns: minmax(280px, 320px) 1fr minmax(300px, 360px);
}

.workspace-grid.sidebar-hidden {
    grid-template-columns: 40px 1fr;
}

.workspace-grid.sidebar-hidden.chat-open {
    grid-template-columns: 40px 1fr minmax(300px, 360px);
}

.workspace-grid.chat-fullscreen > #chat-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    border-radius: 0;
    border: none;
    background: var(--bg-color);
}

.workspace-grid.chat-fullscreen .chat-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.workspace-grid.chat-fullscreen .chat-header {
    max-width: 900px;
    width: 100%;
    margin: 20px auto 15px auto;
}

.workspace-grid > .glass-panel {
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    min-width: 0; /* Critical for preventing grid blowout */
}

/* Sidebar */
.docs-list {
    flex: 1;
    overflow-y: auto;
}

ul.tree-root, ul.tree-nested {
    list-style: none;
    margin: 0;
    padding: 0;
}

ul.tree-nested {
    padding-left: 15px;
    margin-top: 5px;
    border-left: 1px dashed rgba(255, 255, 255, 0.2);
}

.tree-file, .tree-folder {
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s ease;
    margin-bottom: 2px;
    white-space: nowrap;
}

.tree-folder {
    font-weight: 600;
    color: var(--text-color);
}

.tree-folder > span {
    display: block;
}

.tree-file:hover, .tree-folder > span:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tree-file.active {
    background: var(--primary-color);
    color: white;
}

.empty-state {
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: default;
}

/* Markdown Viewer */
.markdown-body {
    flex: 1;
    overflow-y: auto;
    padding-right: 15px;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: #fff;
}

.markdown-body p {
    margin-bottom: 1em;
}

.markdown-body pre {
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1em;
}

.markdown-body code {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    padding: 0.2em 0.4em;
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85em;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.markdown-body pre code {
    background: transparent !important;
    padding: 0;
    border: none;
    color: inherit;
}

.markdown-body a, .chat-msg a {
    color: #60a5fa;
    text-decoration: none;
    border-bottom: 1px solid rgba(96, 165, 250, 0.4);
    transition: all 0.2s ease;
}

.markdown-body a:hover, .chat-msg a:hover {
    color: #93c5fd;
    border-bottom-color: #93c5fd;
}

.code-wrapper {
    position: relative;
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255,255,255,0.1);
    background: #1e1e1e; /* VS Code dark background */
    color: #d4d4d4 !important; /* Force light text in case syntax highlighter is absent */
}

.code-wrapper pre {
    margin: 0 !important;
    padding: 1rem !important; /* Standard padding */
    border-radius: 0 !important;
    background: transparent !important;
}

.copy-code-btn {
    position: absolute;
    top: 5px;
    right: 8px;
    background: rgba(255,255,255,0.1);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 0.75rem;
    z-index: 10;
    transition: all 0.2s;
    font-family: inherit;
}

.copy-code-btn:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* Chat UI */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.3);
}

.chat-msg {
    padding: 10px 14px;
    border-radius: 8px;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
}

.chat-msg.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--secondary-color);
    color: white;
}

.chat-msg.bot {
    align-self: flex-start;
    background: transparent;
    color: var(--text-color);
}

.copy-msg-btn {
    align-self: flex-end;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-msg-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

:root.light-mode .copy-msg-btn {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

:root.light-mode .copy-msg-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1e293b;
}

/* Chat markdown support */
.chat-msg pre {
    background: rgba(0,0,0,0.5);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin-top: 5px;
}
.chat-msg code {
    font-family: monospace;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: flex-end; /* Align bottom */
}

.chat-input-area textarea {
    flex: 1;
    resize: none;
    overflow-y: hidden;
    min-height: 36px;
    max-height: 150px;
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 1024px) {
    .workspace-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: minmax(400px, auto);
        height: auto;
    }
    .container {
        height: auto;
        display: block;
    }
}

/* Light Mode Overrides */
:root.light-mode {
    --bg-color: #f1f5f9;
    --text-color: #0f172a;
    --text-muted: #64748b;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #cbd5e1;
    --secondary-hover: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.1);
}

:root.light-mode input,
:root.light-mode textarea {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.9);
}

:root.light-mode .chat-msg.user {
    color: #1e293b;
}

:root.light-mode .secondary-btn {
    color: var(--text-color);
}

:root.light-mode .markdown-body h1, 
:root.light-mode .markdown-body h2, 
:root.light-mode .markdown-body h3 {
    color: var(--text-color);
}

:root.light-mode .markdown-body pre {
    background: #f8fafc;
    border: 1px solid var(--glass-border);
}

:root.light-mode .markdown-body code {
    background: #f1f5f9;
    color: #0f172a;
    border: 1px solid #e2e8f0;
}

:root.light-mode .markdown-body pre code {
    background: transparent;
    border: none;
    color: inherit;
}

:root.light-mode .markdown-body a, 
:root.light-mode .chat-msg a {
    color: #2563eb;
    border-bottom: 1px solid rgba(37, 99, 235, 0.4);
}

:root.light-mode .markdown-body a:hover, 
:root.light-mode .chat-msg a:hover {
    color: #1d4ed8;
    border-bottom-color: #1d4ed8;
}


:root.light-mode .tree-file:hover, 
:root.light-mode .tree-folder > span:hover {
    background: rgba(0, 0, 0, 0.05);
}

:root.light-mode .chat-history {
    background: transparent;
}

:root.light-mode .chat-msg.bot {
    background: transparent;
}

/* Mermaid Support */
.mermaid {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin-top: 10px;
    text-align: center;
}

:root.light-mode .mermaid {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--glass-border);
}
