@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400&display=swap');

:root {
    /* Premium Color Palette */
    --bg-color: #f3f4f6;
    --surface-color: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;

    --primary-color: #4f46e5;
    /* Indigo 600 */
    --primary-hover: #4338ca;
    /* Indigo 700 */
    --accent-color: #ec4899;
    /* Pink 500 */

    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --success-color: #10b981;

    --radius-sm: 6px;
    --radius-md: 10px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --header-height: 64px;
    --nav-width: 280px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #111827;
        /* Gray 900 */
        --surface-color: #1f2937;
        /* Gray 800 */
        --text-primary: #f9fafb;
        --text-secondary: #9ca3af;
        --border-color: #374151;

        --primary-color: #6366f1;
        /* Indigo 500 */
        --primary-hover: #818cf8;
        /* Indigo 400 */

        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    }
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

[hidden] {
    display: none !important;
}

body {
    font-family: var(--font-sans);
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Typography */
h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.secondary-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

/* Layout */
header {
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 24px;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
}

.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    color: var(--text-primary);
    background-color: var(--bg-color);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.header-right {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}



/* Layout container */
.container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* File Tree */
.file-tree {
    width: var(--nav-width);
    background-color: var(--surface-color);
    /* Matches header/editor bg for cleaner look */
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
}

.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.file-list li {
    margin-bottom: 2px;
}

.file-item,
.folder-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
}

.file-item .icon,
.folder-item .icon {
    margin-right: 10px;
    opacity: 0.7;
    font-size: 1.1em;
}

.file-item:hover,
.folder-item:hover {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

.file-item.selected {
    background-color: var(--bg-color);
    /* Light highlight */
    color: var(--primary-color);
    font-weight: 500;
    border-left: 3px solid var(--primary-color);
    /* Accent line */
    padding-left: 7px;
    /* Adjust for border */
}

/* Nesting */
.folder-content {
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
}

/* Main Editor Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    overflow: hidden;
    position: relative;
}

#current-filename {
    font-weight: 600;
    color: var(--text-primary);
}

#unsaved-indicator {
    color: var(--warning-color);
    margin-left: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

#save-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--text-secondary);
}



#editor {
    flex: 1;
    width: 100%;
    border: none;
    padding: 24px;
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: 1.7;
    background-color: var(--bg-color);
    /* Slight difference from surface */
    color: var(--text-primary);
    resize: none;
    outline: none;
    white-space: pre;
    overflow-y: scroll;
    /* Always show scrollbar to match line numbers if synced */
}

#editor:focus {
    /* Subtle focus state if needed, usually editor is clean */
}

/* Editor Wrapper */
.editor-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-color);
}

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 1rem;
    text-align: center;
    opacity: 0.8;
}

.empty-state p {
    margin-top: 10px;
}

/* Footer */
footer {
    padding: 8px 24px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    text-align: right;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

#editor-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: block;
    /* Override default dialog display behavior when not open, though we use .show() */
    position: static;
    /* Override dialog fixed/absolute positioning to let flexbox handle stacking */
    margin: 0;
    /* Reset dialog margin */
    border: none;
    /* Reset dialog border */
    background-color: var(--surface-color);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    border-left: 4px solid var(--primary-color);
    pointer-events: auto;
    min-width: 250px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-left-color: var(--success-color);
}

.toast-error {
    border-left-color: var(--danger-color);
}

.toast-info {
    border-left-color: var(--primary-color);
}

/* Unsaved Changes Dialog */
#unsaved-dialog {
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    background-color: var(--surface-color);
    color: var(--text-primary);
    max-width: 400px;
    width: 90%;
}

#unsaved-dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
}

.dialog-content {
    padding: 24px;
}

.dialog-content h3 {
    margin: 0 0 12px 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.dialog-content p {
    margin: 0 0 24px 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.danger-btn {
    background-color: var(--danger-color);
}

.danger-btn:hover {
    background-color: #dc2626;
    /* Darker red */
}