/* =========================================
   LAYOUT
   ========================================= */

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--space-4);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.app-logo {
    width: 32px;
    height: 32px;
    color: var(--color-primary);
}

.app-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.header-center {
    flex: 1;
    max-width: 400px;
    margin: 0 var(--space-6);
}

.header-center .search-input {
    width: 100%;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ===== MAIN CONTENT ===== */
.app-main {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.sidebar-header h2 {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

/* Sidebar Sections */
.sidebar-section {
    margin-bottom: var(--space-2);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3);
    background-color: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.section-header:hover {
    background-color: var(--color-border-light);
}

.section-icon {
    font-size: var(--font-size-lg);
}

.section-name {
    flex: 1;
}

.section-count {
    padding: 2px 6px;
    background-color: var(--color-primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

.section-content {
    max-height: none;
    overflow-y: auto;
    padding: var(--space-3);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) var(--color-surface);
}

/* Custom Scrollbar Styles */
.section-content::-webkit-scrollbar {
    width: 8px;
}

.section-content::-webkit-scrollbar-track {
    background: var(--color-surface);
    border-radius: var(--radius-md);
}

.section-content::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.section-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

.sidebar-section.collapsed .section-content {
    display: none;
}

/* Grids */
.templates-grid,
.widgets-grid,
.sections-grid,
.elements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-2);
}

.grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    background-color: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.grid-item:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.grid-item-icon {
    font-size: var(--font-size-2xl);
}

.grid-item-name {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
}

/* ===== EDITOR CONTAINER ===== */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--color-surface);
}

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--toolbar-height);
    padding: 0 var(--space-4);
    background-color: var(--color-surface-elevated);
    border-bottom: 1px solid var(--color-border);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding-right: var(--space-3);
    border-right: 1px solid var(--color-border);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-right {
    margin-left: auto;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: var(--space-2);
    border-radius: var(--radius-base);
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.toolbar-btn:hover {
    background-color: var(--color-border-light);
    color: var(--color-text-primary);
}

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

.toolbar-select {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    cursor: pointer;
}

/* Editor Mode Toggle */
.editor-mode-toggle {
    display: flex;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-base);
    overflow: hidden;
}

.mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-3);
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    cursor: pointer;
    border-right: 1px solid var(--color-border);
}

.mode-btn:last-child {
    border-right: none;
}

.mode-btn:hover {
    background-color: var(--color-border-light);
}

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

/* Editor Workspace */
.editor-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-pane {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.preview-pane {
    flex: 1;
    overflow-y: auto;
    background-color: var(--color-surface);
    border-left: 1px solid var(--color-border);
}

.markdown-textarea {
    width: 100%;
    height: 100%;
    padding: var(--space-6);
    font-family: var(--font-family-mono);
    font-size: var(--font-size-base);
    line-height: var(--line-height-loose);
    color: var(--color-text-primary);
    background-color: var(--color-surface);
    border: none;
    resize: none;
    outline: none;
}

/* Split Mode */
.editor-workspace.split-mode .editor-pane,
.editor-workspace.split-mode .preview-pane {
    flex: 1;
}

.editor-workspace.split-mode .preview-pane {
    display: block;
}

/* Preview Only Mode */
.editor-workspace.preview-mode .editor-pane {
    display: none;
}

.editor-workspace.preview-mode .preview-pane {
    flex: 1;
    border-left: none;
}

/* ===== CONFIG PANEL ===== */
.config-panel {
    width: var(--panel-width);
    background-color: var(--color-surface);
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.config-panel.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.panel-header h2 {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.config-section {
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--color-border);
}

.config-section:last-child {
    border-bottom: none;
}

.config-section h3 {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
}
