/* --- Modern Editor Theme - CSS Reset & Foundational Styles --- */
:root {
  /* Color Palette (Inspired by VS Code's Dark+ Theme) */
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', sans-serif;

  /* Light Theme */
  --primary-bg-light: #F3F3F3;
  --secondary-bg-light: #FFFFFF;
  --header-bg-light: #F3F3F3;
  --panel-bg-light: #FFFFFF;
  --text-color-light: #24292E;
  --text-color-secondary-light: #586069;
  --accent-color-light: #0366D6;
  --border-color-light: #E1E4E8;
  --icon-color-light: #444D56;
  --button-hover-bg-light: #E1E4E8;
  --sidebar-bg-light: #F3F3F3;
  --activity-bar-bg-light: #EBEBEB;

  /* Dark Theme (VS Code Aligned) */
  --primary-bg-dark: #1E1E1E;
  --secondary-bg-dark: #252526;
  --header-bg-dark: #333333;
  --panel-bg-dark: #1E1E1E;
  --text-color-dark: #CCCCCC;
  --text-color-secondary-dark: #8B949E;
  --accent-color-dark: #007ACC;
  --border-color-dark: #3c3c3c;
  --icon-color-dark: #C5C5C5;
  --button-hover-bg-dark: #4A4A4A;
  --sidebar-bg-dark: #252526;
  --activity-bar-bg-dark: #333333;

  /* Syntax Highlighting Icons */
  --icon-html: #E34F26;
  --icon-css: #1572B6;
  --icon-js: #F7DF1E;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  overflow: hidden;
  transition: background-color 0.2s linear, color 0.2s linear;
}

/* --- Theme Class Definitions --- */
body.light-mode {
  --primary-bg: var(--primary-bg-light);
  --secondary-bg: var(--secondary-bg-light);
  --header-bg: var(--header-bg-light);
  --panel-bg: var(--panel-bg-light);
  --text-color: var(--text-color-light);
  --text-color-secondary: var(--text-color-secondary-light);
  --accent-color: var(--accent-color-light);
  --border-color: var(--border-color-light);
  --icon-color: var(--icon-color-light);
  --button-hover-bg: var(--button-hover-bg-light);
  --sidebar-bg: var(--sidebar-bg-light);
  --activity-bar-bg: var(--activity-bar-bg-light);
}

body.dark-mode {
  --primary-bg: var(--primary-bg-dark);
  --secondary-bg: var(--secondary-bg-dark);
  --header-bg: var(--header-bg-dark);
  --panel-bg: var(--panel-bg-dark);
  --text-color: var(--text-color-dark);
  --text-color-secondary: var(--text-color-secondary-dark);
  --accent-color: var(--accent-color-dark);
  --border-color: var(--border-color-dark);
  --icon-color: var(--icon-color-dark);
  --button-hover-bg: var(--button-hover-bg-dark);
  --sidebar-bg: var(--sidebar-bg-dark);
  --activity-bar-bg: var(--activity-bar-bg-dark);
}

/* --- VS Code Layout Structure --- */
.ide-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background-color: var(--primary-bg);
}

.ide-main-content {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative; /* Added for mobile overlay positioning */
}

/* --- Activity Bar --- */
.activity-bar {
    width: 50px;
    background-color: var(--activity-bar-bg);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    z-index: 30; /* Ensure it's above other elements */
}

.activity-bar-top, .activity-bar-bottom {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.activity-bar .icon {
    font-size: 24px;
    color: var(--text-color-secondary);
    text-decoration: none;
    padding: 10px;
    border-radius: 5px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.activity-bar .icon:hover {
    color: var(--text-color);
}

.activity-bar .icon.active {
    color: var(--accent-color);
}
.activity-bar .icon.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background-color: var(--accent-color);
}

/* --- Sidebar --- */
.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease-in-out; /* Added for smooth transition */
}

.sidebar-header {
    padding: 15px 20px; /* Increased padding for better spacing */
    font-size: 12px;
    font-weight: 600;
    color: var(--text-color-secondary);
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* --- NEW: Sidebar File List --- */
.file-explorer-content {
    flex-grow: 1;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px; /* Adjusted vertical padding and increased horizontal */
    font-size: 14px;
    cursor: pointer;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-item:hover {
    background-color: var(--button-hover-bg);
}

.file-item.active {
    background-color: var(--accent-color);
    color: white;
}

.file-item.active i {
    color: white !important;
}

.file-item-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-item .close-file-sidebar {
    visibility: hidden;
    opacity: 0;
    font-family: sans-serif;
    font-size: 18px;
    padding: 0 4px;
    border-radius: 4px;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.file-item:hover .close-file-sidebar,
.file-item.active .close-file-sidebar {
    visibility: visible;
    opacity: 1;
}

.file-item .close-file-sidebar:hover {
    background-color: rgba(255,255,255,0.2);
}

body.light-mode .file-item .close-file-sidebar:hover {
    background-color: rgba(0,0,0,0.1);
}

.file-explorer-content .placeholder-text {
    padding: 15px 20px; /* Aligned horizontal padding */
    font-size: 14px;
    color: var(--text-color-secondary);
}

/*
================================================================
--- NEW: Modern Scrollbar Styles ---
================================================================
*/

/* --- Scrollbar Styles for WebKit Browsers --- */
::-webkit-scrollbar {
  width: 12px;  /* Width of the entire scrollbar */
  height: 12px; /* Height of the scrollbar (for horizontal scrolling) */
}

::-webkit-scrollbar-track {
  background: var(--secondary-bg); /* Use the secondary background color for the track */
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background-color: var(--button-hover-bg); /* Use a subtle color for the thumb */
  border-radius: 10px;
  border: 3px solid var(--secondary-bg); /* Creates a padding effect around the thumb */
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent-color); /* Highlight with the accent color on hover */
}

/* --- Specific overrides for the light theme to ensure good contrast --- */
body.light-mode ::-webkit-scrollbar-thumb {
    background-color: #C1C1C1; /* A slightly darker grey for better visibility in light mode */
    border-color: var(--secondary-bg-light);
}

body.light-mode ::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent-color-light); /* Use the light theme's accent color on hover */
}
/* --- Editor Group Wrapper --- */
.editor-group-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Editor Header (Previously main-header) --- */
.editor-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* Allow items to wrap */
  background-color: var(--primary-bg);
  height: auto; /* Changed from fixed height */
  min-height: 40px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* --- File Tabs --- */
.file-tabs {
  display: flex;
  height: 40px; /* Give a fixed height */
  flex-grow: 1;
  overflow-x: auto;
  flex-shrink: 1;
}

.tab {
  display: flex;
  align-items: center;
  padding: 0 15px;
  cursor: pointer;
  border-right: 1px solid var(--border-color);
  background-color: var(--secondary-bg);
  color: var(--text-color-secondary);
  font-size: 14px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab:hover {
  background-color: var(--primary-bg);
  color: var(--text-color);
}

.tab.active {
  background-color: var(--panel-bg);
  color: var(--text-color);
  border-top: 2px solid var(--accent-color);
}

.tab i {
  margin-right: 8px;
  font-size: 16px;
}

/* --- Header Actions --- */
.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* Allow buttons to wrap */
  gap: 8px;
  margin-left: auto;
  padding: 0 10px; /* Adjust padding */
  width: 100%; /* Take full width on a new line if needed */
  justify-content: flex-end;
}

#format-code-btn, #upload-btn, #live-preview-btn, #save-as-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: transparent;
  color: var(--text-color);
  padding: 6px 10px; /* Adjust padding */
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--border-color);
  font-family: inherit;
  font-size: 12px; /* Slightly smaller font for mobile */
  transition: background-color 0.2s ease, color 0.2s ease;
}

#format-code-btn:hover, #upload-btn:hover, #live-preview-btn:hover, #save-as-btn:hover {
  background-color: var(--button-hover-bg);
}

/* --- Modern Theme Switcher --- */
.theme-switcher button {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 36px;
    height: 36px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.theme-switcher button:hover {
    background-color: var(--button-hover-bg);
}

/* --- Main Editor Area (Content) --- */
.editor-area-content {
  flex-grow: 1;
  display: flex;
}

.editor-pane {
  position: relative;
  width: 100%;
  height: 100%;
  transition: width 0.3s ease;
}

.preview-pane {
  width: 0;
  height: 100%;
  background-color: #fff;
  display: none;
}

#preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.resizer {
  width: 5px;
  background-color: var(--border-color);
  cursor: col-resize;
  flex-shrink: 0;
  display: none;
}

/* When preview is active */
body.preview-active .editor-pane { width: 50%; }
body.preview-active .preview-pane,
body.preview-active .resizer { display: block; }
body.preview-active .preview-pane { width: 50%; }

/* --- Ace Editor Overrides --- */
#editor {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  font-size: 15px !important;
  line-height: 1.6;
}

.ace_editor {
  background: var(--panel-bg) !important;
  color: var(--text-color) !important;
  font-family: 'Fira Code', 'Consolas', 'Monaco', monospace !important;
}

.ace_gutter {
  background: var(--panel-bg) !important;
  border-right: 1px solid var(--border-color);
}

/* --- Status Bar --- */
.status-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background-color: var(--secondary-bg);
  color: var(--text-color-secondary);
  height: 24px;
  padding: 0 15px;
  font-size: 12px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* --- Icon Colors --- */
.fa-html5 { color: var(--icon-html); }
.fa-css3-alt { color: var(--icon-css); }
.fa-js-square { color: var(--icon-js); }
.fa-python { color: #3776AB; }
.fa-php { color: #777BB4; }
.fa-markdown, .fa-docker { color: #0db7ed; }

/* --- Styles for Dynamic Tab Close Button --- */
.tab .close-tab {
    margin-left: 10px;
    padding: 0 4px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-family: sans-serif;
    font-size: 16px;
    line-height: 1;
}

.tab .close-tab:hover {
    background-color: var(--button-hover-bg);
}

/* --- Search Bar Styles --- */
#search-container {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--secondary-bg);
    padding: 8px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10;
    display: none;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-color);
    flex-direction: column; /* Stack vertically on small screens */
    align-items: stretch;
}

.search-input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#find-input, #replace-input {
    background-color: var(--primary-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 13px;
    width: 180px;
}

#find-input:focus, #replace-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.search-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: space-between; /* Space out the buttons */
}

.search-actions button {
    background: none;
    border: 1px solid transparent;
    color: var(--icon-color);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.search-actions button:hover {
    background-color: var(--button-hover-bg);
    color: var(--text-color);
}

body.light-mode .ace_selected-word {
    background-color: #cce5ff !important;
    border: 1px solid #99caff !important;
}

body.dark-mode .ace_selected-word {
    background-color: #3a3d41 !important;
    border: 1px solid #5a5d61 !important;
}

/* --- NEW: Zen Mode Styles --- */
.ide-container.zen-mode-active .activity-bar,
.ide-container.zen-mode-active .sidebar,
.ide-container.zen-mode-active .editor-header,
.ide-container.zen-mode-active .status-bar,
.ide-container.zen-mode-active .resizer {
    display: none;
}

.ide-container.zen-mode-active .preview-pane {
    display: none;
}

.ide-container.zen-mode-active .editor-pane {
    width: 100% !important; /* Override inline style from resizer.js */
}

/* --- REVISED: Modern Popup & FAQ Accordion Styles (V2) --- */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.popup-container {
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 600px; /* Increased max-width */
    color: var(--text-color);
    transform: scale(0.95);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}

.popup-overlay.active .popup-container {
    transform: scale(1);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 25px; /* Increased padding */
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.popup-header h2 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.popup-close-btn {
    background: none;
    border: none;
    font-size: 28px;
    font-weight: 300;
    color: var(--text-color-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}
.popup-close-btn:hover {
    color: var(--text-color);
}

.popup-content {
    padding: 15px 25px 25px 25px; /* Adjusted padding */
    font-size: 15px;
    line-height: 1.7;
    overflow-y: auto;
}

.popup-content > p:first-of-type {
    margin-bottom: 20px;
}

/* --- FAQ Accordion Styles --- */
.faq-accordion {
    border-top: 1px solid var(--border-color);
}

.faq-item {
    border-bottom: 1px solid var(--border-color);
}

.faq-question {
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 18px 5px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease;
}

.faq-question:hover {
    background-color: var(--button-hover-bg);
}

.faq-question::after {
    content: '\002B'; /* Plus sign */
    font-size: 22px;
    font-weight: bold;
    color: var(--accent-color);
    transition: transform 0.3s ease-in-out;
}

.faq-item.active .faq-question::after {
    transform: rotate(45deg); /* Rotates to an 'X' */
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, padding 0.3s ease;
}
.faq-answer p {
    padding: 0px 5px 18px 5px;
    line-height: 1.6;
    color: var(--text-color-secondary);
}

/* --- Original Button Styles (for Support Popup) --- */
.popup-buttons {
    display: flex;
    flex-direction: column; /* Stack buttons vertically on mobile */
    gap: 15px;
    margin-top: 25px;
}

.popup-btn {
    flex-grow: 1;
    text-decoration: none;
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.popup-btn:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.popup-btn.github { background-color: #333; }
.popup-btn.portfolio { background-color: #007ACC; }

/* Hide popups by default */
#help-center-popup, #support-popup {
    display: none;
}
/* --- NEW: Inline File Input Styles --- */
.new-file-input-container {
    /* REMOVED !important and aligned padding with other items */
    padding: 4px 15px 4px 15px;
}

.new-file-input {
    width: 100%;
    background-color: var(--primary-bg);
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    color: var(--text-color);
    font-family: var(--font-sans);
    font-size: 14px;
    padding: 6px 10px; /* Increased internal padding */
    outline: none;
}

/*
================================================================
--- NEW: Mobile & Responsive Styles ---
================================================================
*/

/* --- General Mobile Adjustments --- */
.sidebar-toggle-btn {
    display: none; /* Hide toggle button by default */
    font-size: 24px;
    padding: 10px;
    color: var(--text-color-secondary);
}

/* --- Styles for screens smaller than 768px (Tablets and Mobiles) --- */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 20;
        transform: translateX(-100%);
        border-right-width: 2px;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 5px 0 15px rgba(0,0,0,0.2);
    }
    
    .sidebar-toggle-btn {
        display: flex; /* Show the toggle button */
    }
    
    .activity-bar .icon.active {
       color: var(--accent-color); /* Ensure the active file icon is always visible */
    }

    .editor-header {
        flex-direction: column;
        align-items: flex-start;
        height: auto;
        padding-bottom: 8px;
    }

    .file-tabs {
        width: 100%;
        border-bottom: 1px solid var(--border-color);
        margin-bottom: 8px;
    }

    .header-actions {
        width: 100%;
        justify-content: space-around;
        gap: 5px;
    }
    
    #format-code-btn span, #upload-btn span, #live-preview-btn span, #save-as-btn span {
        display: none; /* Hide text on buttons to save space */
    }
    
    #format-code-btn, #upload-btn, #live-preview-btn, #save-as-btn {
        padding: 8px;
        min-width: 40px;
        justify-content: center;
    }

    /* Hide live preview pane by default on mobile */
    body.preview-active .editor-pane, body.preview-active .preview-pane {
        width: 100%;
        height: 50%;
    }
    body.preview-active .editor-area-content {
        flex-direction: column;
    }
    body.preview-active .resizer {
        width: 100%;
        height: 5px;
        cursor: row-resize;
    }

    .status-bar p {
        font-size: 11px;
    }

    .popup-container {
        width: 95%;
        max-height: 90vh;
    }
    
    .popup-header h2 {
        font-size: 16px;
    }
}

/* --- Styles for screens larger than 768px --- */
@media (min-width: 769px) {
    .header-actions {
        width: auto;
        padding-right: 15px;
    }
    .editor-header {
      flex-wrap: nowrap;
    }
    .popup-buttons {
        flex-direction: row; /* Horizontal buttons on larger screens */
    }

    #search-container {
      flex-direction: row; /* Horizontal layout for search on desktop */
      align-items: center;
    }
}