/* ========== Main Container ========== */
.main-container {
    display: flex;
    margin-top: 50px;
    height: calc(100vh - 50px);
    overflow: hidden; /* ← Prevent container from expanding */
}

/* ========== Code Panel ========== */
.code-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 8px solid #f1f1f1;
    min-width: 0; /* ← Allow flex item to shrink below content size */
    overflow: hidden;
}

.code-header {
    background: #f1f1f1;
    padding: 5px 20px;
    border-bottom: 1px solid #d4d4d4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 49px;
    gap: 20px;
    flex-shrink: 0; /* ← Biarkan header fixed di atas */
}

.code-header-text {
    color: #232323;
    font-size: 14px;
    font-weight: 600;
    flex: 1;
    min-width: 0; /* Prevent text overflow */
}

.code-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
}

.editor-container {
    flex: 1;
    overflow: hidden; /* ← Hidden, CodeMirror will handle its own scroll */
    min-width: 0;
    position: relative;
}

/* ========== Preview Panel ========== */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* ← Allow flex item to shrink below content size */
    overflow: hidden;
}

.preview-header {
    background: #f1f1f1;
    padding: 12px 20px;
    border-bottom: 1px solid #d4d4d4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 49px;
}

.preview-title {
    color: #232323;
    font-size: 14px;
    font-weight: 600;
}

.preview-frame {
    flex: 1;
    border: none;
    background: #ffffff;
    width: 100%;
    height: 100%;
}

/* ========== Topic Selector ========== */
.topic-selector {
    position: relative;
    margin-right: 15px;
}

.topic-select {
    background: #383a47;
    color: #f1f1f1;
    border: 1px solid #555;
    padding: 8px 35px 8px 15px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
    appearance: none;
    min-width: 150px;
}

.topic-selector::after {
    content: '▼';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #f1f1f1;
    font-size: 10px;
    pointer-events: none;
}

/* ========== Run Button ========== */
.run-btn {
    background: #04AA6D;
    color: white;
    border: none;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;  /* ← Prevent text wrapping */
    flex-shrink: 0;       /* ← Prevent button from shrinking */
}

.run-btn:hover {
    background: #039663;
    transform: translateY(-1px);
}

/* ========== CodeMirror ========== */
.CodeMirror {
    height: 100% !important;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', monospace;
    /* Biarkan CodeMirror handle scrolling secara native */
}

.CodeMirror-gutters {
    border-right: 1px solid #d4d4d4 !important;
    background: #f5f5f5 !important;
}

/* ========== Tabs (Web Editor) ========== */
.tabs {
    display: flex;
    background: #fff;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0; /* ← Biarkan tabs fixed di atas */
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}

.tab.active {
    border-bottom-color: #04AA6D;
    color: #04AA6D;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden; /* ← Penting: biarkan scroll di CodeMirror saja */
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* ========== Loading ========== */
.loading {
    display: none;
    align-items: center;
    gap: 8px;
    color: #04AA6D;
    font-size: 13px;
}

.loading.show {
    display: flex;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #04AA6D;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }

    .code-panel {
        height: 50%;
    }

    .preview-panel {
        height: 50%;
    }

    /* Mobile: Stack text and actions vertically */
    .code-header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        align-items: stretch;
    }

    .code-header-text {
        text-align: left;
    }

    .code-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .topic-selector {
        margin-right: 0;
        flex: 1;
    }

    .topic-select {
        width: 100%;
        min-width: 120px;
    }

    .run-btn {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 10px 12px;  /* ← Adjust padding for small screens */
    }

    /* Mobile: Adjust preview header */
    .preview-header {
        padding: 10px;
    }
}
