* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #252526;
    --text-primary: #d4d4d4;
    --text-secondary: #999;
    --border-color: #3e3e42;
    --accent-color: #667eea;
    --accent-color-2: #764ba2;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --text-primary: #1e1e1e;
    --text-secondary: #666;
    --border-color: #d0d0d0;
    --accent-color: #667eea;
    --accent-color-2: #764ba2;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.login-box p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.error {
    background: #f44336;
    color: white;
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-tertiary) 100%);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    min-height: 60px;
    flex-wrap: nowrap;
    gap: 1rem;
}

.header > div:first-child {
    flex-shrink: 0;
    white-space: nowrap;
    min-width: fit-content;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header h1,
.header .logo-title {
    font-size: 1.75rem;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    text-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
    align-items: center;
    overflow: visible; /* allow dropdown to escape */
}

.header-actions-main {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
    align-items: center;
    min-width: 0;
    overflow: visible; /* allow buttons to overflow naturally, we'll hide them with JS */
    flex: 1 1 auto; /* grow to fill available space */
}

.header-action-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

.header-action-btn.is-overflowed {
    display: none !important;
}

.header-overflow {
    flex-shrink: 0;
    position: relative;
    z-index: 10050;
}

.menu-dropdown {
    flex-shrink: 0;
}

.menu-toggle {
    white-space: nowrap;
}

.menu-dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    background: var(--bg-secondary);
    min-width: 220px;
    max-width: 360px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.55);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    z-index: 10060;
    overflow: hidden;
}

.menu-dropdown-content.show {
    display: block;
}

.menu-dropdown-content a {
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    text-decoration: none;
    display: block;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.1rem;
    transition: background 0.15s ease;
}

.menu-dropdown-content a:hover {
    background: var(--bg-tertiary);
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

/* Make header degrade nicely on narrow widths */
@media (max-width: 900px) {
    .header {
        padding: 0.75rem 1rem;
    }
    .header .logo-title {
        font-size: 1.5rem;
    }
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    min-width: 200px;
    max-width: 50%;
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-primary) 100%);
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
}

[data-theme="light"] .sidebar {
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

.sidebar-resize-handle {
    width: 5px;
    background: var(--border-color);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    user-select: none;
}

.sidebar-resize-handle:hover {
    background: #007acc;
}

.file-browser {
    flex: 1;
    overflow-y: auto;
}

.breadcrumb {
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-bottom: 2px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.breadcrumb-item {
    color: #007acc;
    cursor: pointer;
    text-decoration: none;
}

.breadcrumb-item:hover {
    text-decoration: underline;
}

.breadcrumb-item:not(:last-child)::after {
    content: ' / ';
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.file-list {
    padding: 0.5rem;
}

.file-item, .dir-item {
    padding: 0.625rem 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    user-select: none;
    transition: all 0.2s ease;
    margin: 0.125rem 0.5rem;
}

.file-item:hover, .dir-item:hover {
    background: linear-gradient(90deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    transform: translateX(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

[data-theme="light"] .file-item:hover, 
[data-theme="light"] .dir-item:hover {
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.file-item.active {
    background: linear-gradient(90deg, #007acc 0%, #005a9e 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0,122,204,0.4);
}

.file-item.active .file-icon,
.dir-item.active .dir-icon {
    filter: brightness(2);
}

.file-icon {
    width: 16px;
    height: 16px;
}

.dir-icon {
    width: 16px;
    height: 16px;
}

.loading {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
}

/* Editor Area */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

.editor-toolbar {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    padding: 0.875rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

[data-theme="light"] .editor-toolbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.file-info span {
    color: var(--text-primary);
}

.status {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status.saved {
    color: #4caf50;
}

.status.unsaved {
    color: #ff9800;
}

.toolbar-actions {
    display: flex;
    gap: 0.5rem;
}

.welcome-message {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.welcome-message h2 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.welcome-message p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #007acc 0%, #005a9e 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #005a9e 0%, #004080 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,122,204,0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

[data-theme="light"] .btn-secondary:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-danger {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(244,67,54,0.3);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-primary) 100%);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    border: 1px solid var(--border-color);
}

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

.modal-header h2 {
    color: var(--text-primary);
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--accent-color);
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
}

.search-results {
    margin-top: 1rem;
}

.search-result-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.search-result-item:hover {
    background: var(--bg-tertiary);
}

.search-result-item .file-path {
    color: #007acc;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.search-result-item .match-line {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: 1rem;
}

.match-line .line-number {
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-tertiary);
}

/* Additional styles for new features */
.file-browser-actions {
    padding: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-item, .dir-item {
    position: relative;
}

.file-item .btn, .dir-item .btn,
.file-item .context-menu-btn, .dir-item .context-menu-btn {
    opacity: 0;
    transition: opacity 0.15s;
}

.file-item:hover .btn, .dir-item:hover .btn,
.file-item:hover .context-menu-btn, .dir-item:hover .context-menu-btn {
    opacity: 1;
}

/* Keep button visible when context menu is showing - no transition */
.file-item:has(.context-menu.show) .context-menu-btn,
.dir-item:has(.context-menu.show) .context-menu-btn {
    opacity: 1 !important;
    transition: none;
}

/* Context menu styling */
.context-menu-wrapper {
    position: relative;
    display: inline-block;
}

.context-menu-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
    border-radius: 4px;
    line-height: 1;
}

.context-menu-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.context-menu {
    display: none;
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    z-index: 1001;
    overflow: hidden;
}

.context-menu.show {
    display: block;
}

.context-menu a {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.875rem;
    white-space: nowrap;
}

.context-menu a:hover {
    background: var(--bg-secondary);
}

.context-menu .menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.25rem 0;
}

.context-menu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: transparent;
}

.context-menu-backdrop.show {
    display: block;
}

/* File size display */
.file-size {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-right: 0.5rem;
    display: none;
}

.show-file-sizes .file-size {
    display: inline;
}

.modal-body .form-group {
    margin-bottom: 1rem;
}

.modal-body label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.modal-body input[type="checkbox"] {
    margin-right: 0.5rem;
}

.search-result-item .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}
