/* ═══════════════════════════════════════════════════════════════════════════════
   Cache Service Browser - v0.1.3 Patches
   
   Major Changes:
   - 3-column layout (sidebar | content | html preview)
   - Proper scroll isolation (CRITICAL FIX)
   - Dual resize handles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════════════════
   CRITICAL: Complete Layout Reset for Scroll Isolation
   Each column must be an independent scroll container
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Root app container */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden !important;
}

/* Header - fixed height */
.app-header {
    flex-shrink: 0;
    height: 48px;
    overflow: hidden;
}

/* Main area - fills remaining space, NO SCROLLING */
.app-main {
    display: flex !important;
    flex: 1 !important;
    min-height: 0 !important; /* Critical for flex children to scroll */
    overflow: hidden !important;
    position: relative;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Column 1: Sidebar (File Tree)
   ═══════════════════════════════════════════════════════════════════════════════ */

.sidebar {
    width: 300px;
    min-width: 200px;
    max-width: 600px;
    height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden !important; /* Sidebar container doesn't scroll */
    flex-shrink: 0;
    border-right: 1px solid var(--color-border-default);
}

/* File tree component must scroll internally */
.sidebar file-tree {
    flex: 1;
    min-height: 0; /* Critical! */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Column 2: Main Content
   ═══════════════════════════════════════════════════════════════════════════════ */

.main-content {
    flex: 1 !important;
    min-width: 400px;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important; /* Container doesn't scroll */
    min-height: 0 !important;
}

/* View tabs - fixed height */
.main-content view-tabs {
    flex-shrink: 0;
}

/* View container fills remaining space */
.view-container {
    flex: 1 !important;
    min-height: 0 !important; /* Critical for internal scrolling */
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
}

/* View panels */
.view-panel {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: none;
}

.view-panel.active {
    display: flex !important;
    flex-direction: column;
}

/* Content viewer must handle its own scrolling */
.view-panel content-viewer {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Column 3: HTML Preview Panel
   ═══════════════════════════════════════════════════════════════════════════════ */

.html-preview-panel {
    width: 500px;
    min-width: 300px;
    max-width: 800px;
    height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    flex-shrink: 0;
    border-left: 1px solid var(--color-border-default);
    background: var(--color-bg-primary);
}

.html-preview-panel.visible {
    display: flex !important;
}

.html-preview-panel html-panel {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Resize Handles
   ═══════════════════════════════════════════════════════════════════════════════ */

.resize-handle {
    width: 5px;
    height: 100%;
    background: transparent;
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background-color 0.15s ease;
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 40px;
    background: var(--color-border-muted);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.resize-handle:hover {
    background: rgba(0, 217, 255, 0.1);
}

.resize-handle:hover::after {
    opacity: 1;
}

.resize-handle.dragging {
    background: rgba(0, 217, 255, 0.2);
}

.resize-handle.dragging::after {
    opacity: 1;
    background: var(--color-accent-primary);
}

/* Hidden when panel is hidden */
#resize-handle-2 {
    display: none;
}

#resize-handle-2.visible {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Override v0.1.2 sidebar resize handle (use new unified system)
   ═══════════════════════════════════════════════════════════════════════════════ */

.sidebar-resize-handle {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   HTML Panel Component Styles
   ═══════════════════════════════════════════════════════════════════════════════ */

.html-panel-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: var(--color-bg-primary);
    overflow: hidden;
}

.html-panel-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border-muted);
    flex-shrink: 0;
}

.html-panel-title {
    flex: 1;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.html-panel-title::before {
    content: '🌐 ';
}

.html-panel-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.html-panel-toolbar {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--color-bg-tertiary);
    border-bottom: 1px solid var(--color-border-muted);
    flex-shrink: 0;
}

.html-panel-toolbar .mode-btn {
    padding: 4px 10px;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.html-panel-toolbar .mode-btn:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-hover);
}

.html-panel-toolbar .mode-btn.active {
    color: var(--color-accent-primary);
    background: rgba(0, 217, 255, 0.1);
    border-color: var(--color-accent-primary);
}

.html-panel-body {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.html-panel-body iframe {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.html-panel-body .source-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    padding: var(--spacing-md);
    background: var(--color-bg-primary);
}

.html-panel-body .source-view pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-sm);
    line-height: 1.6;
    color: var(--color-text-primary);
}

/* Close button */
.html-panel-close {
    padding: 4px 8px;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.html-panel-close:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-hover);
}

/* Empty state */
.html-panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
    text-align: center;
    padding: var(--spacing-xl);
}

.html-panel-empty-icon {
    font-size: 48px;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.html-panel-empty-text {
    font-size: var(--font-size-sm);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Common CSS import
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Import chain handled by common.css */
