/* ---- CSS Variables & Theming ---- */
:root {
    /* Fluid Typography using clamp */
    --fs-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --fs-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --fs-md: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --fs-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    /* Theme - Light (Default overridden by dark) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #cbd5e1;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --header-height: 60px;
    --tabs-height: 48px;
    /* Glassmorphism settings */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-soft: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
body.theme-dark {
    --bg-primary: #0f172a;
    /* Deep Dark */
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --accent-color: #6366f1;
    --accent-hover: #818cf8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.05);
    --shadow-soft: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}
/* ---- Resets & Global ---- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: var(--font-ui);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}
/* ---- Header (Glassmorphism) ---- */
.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}
.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.pulse-icon {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}
.pulse-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: inherit;
    filter: blur(10px);
    opacity: 0.8;
}
.logo h1 {
    font-size: var(--fs-lg);
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.project-info input {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: var(--fs-md);
    font-family: var(--font-ui);
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    text-align: center;
    transition: all 0.2s ease;
}
.project-info input:hover,
.project-info input:focus {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    outline: none;
}
.actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.875rem;
    border-radius: 6px;
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-family: var(--font-ui);
}
.btn-primary {
    background-color: var(--accent-color);
    color: #fff;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}
.btn-icon {
    padding: 0.4rem;
    background: transparent;
    color: var(--text-secondary);
}
.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
/* ---- Layout & Grid ---- */
.app-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height));
    flex: 1;
}
/* File Explorer */
.file-explorer {
    width: 250px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}
.explorer-header {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}
.file-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    cursor: pointer;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
}
.file-item.active {
    background: var(--bg-tertiary);
    color: var(--accent-color);
    border-right: 3px solid var(--accent-color);
}
.file-item:hover:not(.active) {
    background: var(--bg-tertiary);
}
.file-item-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-item-name span.lang-icon {
    font-size: 14px;
    width: 16px;
    display: inline-flex;
    justify-content: center;
}
.file-item-actions {
    display: none;
    gap: 0.25rem;
}
.file-item:hover .file-item-actions {
    display: flex;
}
.file-item-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}
.file-item-actions button:hover {
    color: var(--accent-color);
}
.file-rename-input {
    background: var(--bg-primary);
    border: 1px solid var(--accent-color);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    padding: 0.2rem;
    width: 100%;
    outline: none;
    border-radius: 4px;
}
.editors-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.editor-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    background: var(--bg-secondary);
    overflow: hidden;
}
.pane-header {
    height: 36px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    gap: 0.5rem;
}
.lang-icon svg {
    color: var(--accent-color);
}
.editor-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--bg-secondary);
}
/* CM6 specific styles */
.cm-editor {
    height: 100%;
}
.cm-scroller {
    font-family: var(--font-mono) !important;
    font-size: var(--fs-sm);
}
/* Preview */
.preview-container {
    flex: 1;
    background: #fff;
    /* Always white background for preview like real browsers */
    display: flex;
    flex-direction: column;
    position: relative;
    transition: all 0.3s ease;
}
.iframe-wrapper {
    flex: 1;
    height: 100%;
    background: #fff;
}
iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}
/* Fullscreen Mode */
.preview-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
}
.close-fullscreen {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border-radius: 50%;
    padding: 0.5rem;
    z-index: 1010;
}
.preview-container.fullscreen .close-fullscreen {
    display: flex;
}
/* Resizer Bar Horizontal */
.resizer-bar.horizontal-dragger {
    width: 100%;
    height: 6px;
    cursor: row-resize;
}
.resizer-handle {
    width: 40px;
    height: 2px;
}
/* Resizer Bar Vertical */
.resizer-bar.vertical-dragger {
    width: 6px;
    height: 100%;
    cursor: col-resize;
    flex-direction: column;
    flex-shrink: 0;
}
.resizer-handle-v {
    width: 2px;
    height: 40px;
    background: var(--border-color);
    border-radius: 2px;
}
.resizer-bar.vertical-dragger:hover .resizer-handle-v {
    background: rgba(255, 255, 255, 0.8);
}
/* ---- Toasts ---- */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}
.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    font-size: var(--fs-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.toast.show {
    transform: translateX(0);
    opacity: 1;
}
.toast.success {
    border-left: 4px solid #10b981;
}
.toast.error {
    border-left: 4px solid #ef4444;
}
/* ---- Mobile / Tablet Approach (< 768px) ---- */
@media screen and (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
    .project-info input {
        max-width: 120px;
        font-size: var(--fs-sm);
    }
    .actions .btn .btn-text {
        display: none;
    }
    .app-layout {
        flex-direction: column;
    }
    .file-explorer {
        width: 100%;
        height: var(--tabs-height);
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .explorer-header {
        display: none;
    }
    .file-list {
        display: flex;
        flex-direction: row;
        overflow-y: hidden;
        overflow-x: auto;
        padding: 0;
    }
    .file-item {
        border-bottom: 2px solid transparent;
        border-right: none;
        padding: 0.5rem 1rem;
    }
    .file-item.active {
        border-bottom-color: var(--accent-color);
        border-right: none;
    }
    .file-item-actions {
        display: none !important;
        /* Hide actions on mobile for simplicity, or implement modal */
    }
    .editors-container,
    .preview-container {
        display: flex;
        flex: 1;
        height: 50%;
    }
    .preview-container {
        border-top: 1px solid var(--border-color);
    }
}
/* ---- Desktop Approach (> 768px) ---- */
@media screen and (min-width: 769px) {
    .hide-on-desktop {
        display: none !important;
    }
    .app-layout {
        flex-direction: row;
    }
    .editors-container {
        flex-direction: column;
        height: 100%;
        flex: 1;
    }
    .preview-container {
        flex: 1;
        height: 100%;
        border-left: 1px solid var(--border-color);
    }
    .editor-pane {
        display: flex !important;
        /* Always visible on desktop */
    }
}