:root {
    --bg-color: #0f111a;
    --panel-bg: #1a1d27;
    --border-color: #2a2d3d;
    --text-primary: #e2e8f0;
    --text-muted: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --user-bubble: #2563eb;
    --ai-bubble: #1e293b;
    --danger: #ef4444;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* 3-Column Layout */
.workspace-layout {
    display: grid;
    grid-template-columns: 280px 1fr 1fr;
    height: 100vh;
    width: 100vw;
}

.panel-left, .panel-middle, .panel-right {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background-color: var(--panel-bg);
    min-height: 0; /* PENTING: agar flex child bisa scroll */
    overflow: hidden;
}

.panel-right {
    border-right: none;
}

/* Header Areas */
.panel-header, .chat-header {
    min-height: 60px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--panel-bg);
    flex-shrink: 0; /* Header tidak boleh mengecil */
}

.panel-header h3, .chat-header h2 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Buttons & Inputs */
.icon-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.sq-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ================================ */
/* Left Panel: File Manager         */
/* ================================ */

.workspace-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}
#workspace-select {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 5px;
    border-radius: 4px;
    font-size: 11px;
    width: 110px;
    flex-shrink: 0;
}
.file-manager-toolbar {
    display: flex;
    padding: 8px 10px;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    background-color: #151720;
    flex-shrink: 0; /* Toolbar tidak boleh mengecil */
}
.file-tree {
    flex: 1;
    overflow-y: auto; /* SCROLL untuk file tree */
    overflow-x: hidden;
    padding: 8px;
    min-height: 0;
}

/* Tree Item — nama file di-truncate, tombol aksi selalu terlihat */
.tree-item {
    padding: 5px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-muted);
    min-height: 30px;
}
.tree-item:hover, .tree-item.active {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

/* Ikon file/folder — tidak boleh mengecil */
.tree-item > i:first-child {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

/* Nama file — truncate jika terlalu panjang */
.tree-item > span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0; /* PENTING agar ellipsis bekerja di flexbox */
}

/* Tombol aksi — SELALU fixed-width, tidak termakan nama file */
.tree-item .actions {
    display: none;
    flex-shrink: 0;
    gap: 4px;
    margin-left: auto;
    align-items: center;
}
.tree-item:hover .actions {
    display: flex;
}
.tree-item .actions i {
    font-size: 11px;
    cursor: pointer;
    padding: 3px;
    border-radius: 3px;
    flex-shrink: 0;
}
.tree-item .actions i:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* ================================ */
/* Middle Panel: Chat               */
/* ================================ */

.chat-history {
    flex: 1;
    padding: 20px;
    overflow-y: auto; /* SCROLL untuk chat */
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; /* PENTING agar bisa scroll */
}
.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    flex-shrink: 0; /* Bubble tidak boleh mengecil */
}
.bubble-content {
    overflow-wrap: break-word;
    word-break: break-word;
}
.user-bubble {
    background-color: var(--user-bubble);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.ai-bubble {
    background-color: var(--ai-bubble);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-input-area {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* Input area tidak boleh mengecil */
}
.input-wrapper {
    display: flex;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    align-items: flex-end;
    gap: 8px;
}
#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
    resize: none;
    line-height: 1.5;
    max-height: 120px;
    min-height: 36px;
    overflow-y: auto;
}
#chat-input:disabled {
    opacity: 0.5;
}
.stop-btn {
    color: var(--danger) !important;
}
.stop-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}
.send-btn {
    color: var(--accent-blue);
}

/* ================================ */
/* Right Panel: Preview             */
/* ================================ */

.preview-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #fff;
    min-height: 0; /* PENTING agar bisa scroll/contain */
    overflow: hidden;
}
.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin: auto;
}
#preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    flex: 1;
}

.preview-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}
.preview-actions button {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}
.preview-actions button:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.1);
}

.header-status {
    color: #22c55e;
    font-size: 12px;
    font-weight: 500;
}

/* ================================ */
/* Scrollbar                        */
/* ================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


/* Custom Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s;
}
.modal-overlay.show {
    display: flex !important;
    opacity: 1;
}
.modal-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    transform: scale(0.95);
    transition: transform 0.2s;
    overflow: hidden;
}
.modal-overlay.show .modal-container {
    transform: scale(1);
}
.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #0f172a;
}
.modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: #f1f5f9;
}
.modal-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 16px;
}
.modal-close:hover {
    color: #f1f5f9;
}
.modal-body {
    padding: 20px;
    color: #cbd5e1;
    font-size: 14px;
}
.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #0f172a;
}
.modal-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
}
.modal-btn.btn-secondary {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #334155;
}
.modal-btn.btn-secondary:hover {
    background: #1e293b;
    color: #f1f5f9;
}
.modal-btn.btn-primary {
    background: var(--accent-blue);
    color: #ffffff;
}
.modal-btn.btn-primary:hover {
    background: #2563eb;
}
.modal-btn.btn-danger {
    background: #ef4444;
    color: #ffffff;
}
.modal-btn.btn-danger:hover {
    background: #dc2626;
}

/* Chat Minimize Styles */
.workspace-layout.chat-minimized {
    grid-template-columns: 280px 1fr;
}
.workspace-layout.chat-minimized .panel-middle {
    display: none;
}

