:root {
    --container-margin-vertical: 40px; /* 10px top + 10px bottom */
}

html, body {
    height: 100%;
    margin: 0;
    padding: 10px;
    overflow: hidden; /* Prevent body scrollbar due to flex layout */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f9;
    color: #333;
    line-height: 1.6;
    display: flex; /* Enable flex container */
    flex-direction: column; /* Stack children vertically */
}

.container {
    width: 70vw; /* Adjusted to 70% of browser width */
    margin: 0 auto; /* Use var for consistency */
    padding: 0 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    flex: 1; /* Allow container to grow and shrink */
    display: flex; /* Enable flex container for its children */
    flex-direction: column; /* Stack children vertically */
    max-height: calc(100vh - var(--container-margin-vertical)); /* Ensure container uses available viewport height */
    box-sizing: border-box; /* Include padding in height calculation */
}

h1 {
    color: #2c3e50;
    text-align: center;
    margin: 5px;
    flex-shrink: 0; /* Prevent h1 from shrinking */
}

/* Navbar specific styles */
.navbar {
    display: flex;
    justify-content: flex-end; /* Align to the left */
    padding: 0 50px 10px 0;
    margin: 0 10px 0 10px;
    border-bottom: 1px solid #eee; /* Subtle separator */
    z-index: 1000;
}

.navbar .nav-button {
    background-color: #007bff;
    color: white;
    padding: 6px 15px;
    border-radius: 5px;
    text-decoration: none; /* Remove underline */
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.navbar .nav-button:hover {
    background-color: #0056b3;
}

body.dark-mode .navbar {
    border-bottom: none;
}

body.dark-mode .navbar .nav-button {
    background-color: #007acc;
}

body.dark-mode .navbar .nav-button:hover {
    background-color: #005fa3;
}

p {
    text-align: center;
    margin: 5px;
    color: #555;
    flex-shrink: 0; /* Prevent p from shrinking */
}

code {
    background-color: #e8eaed;
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

/* Tab Styles */
.tabs {
    display: flex;
    margin-bottom: 15px;
    border-bottom: 2px solid #dee2e6;
    flex-shrink: 0; /* Prevent tabs from shrinking */
}

.tab-button {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 16px;
    font-weight: 500;
    color: #495057;
    border-bottom: 2px solid transparent; /* For the active indicator */
    margin-bottom: -2px; /* Align with the container's border-bottom */
    transition: color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.tab-button:hover {
    color: #007bff;
}

.tab-button.active {
    color: #007bff;
    border-bottom-color: #007bff;
}

/* Editor Content Area Styles */
/* The div with position: relative, which contains the editor-tab-content */
/* This element should now correctly flex-grow to fill remaining space */
div[style*="position:relative"] {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex items contained in a column flex */
    box-sizing: border-box;
    padding-bottom: 10px; /* Add some padding so content doesn't touch save button margin */
}


.editor-tab-content {
    border: 1px solid #ddd;
    border-radius: 5px;
    /* margin-bottom: 10px; Removed, as parent div has padding-bottom */
    flex: 1; /* Allow editor content to grow and shrink */
    display: flex; /* Make it a flex container for CodeMirror */
    min-height: 0; /* Allow the editor content to shrink */
    box-sizing: border-box;
}

.editor-tab-content.active {
    display: flex; /* Changed from block to flex for proper layout */
    flex-direction: column;
}

/* CodeMirror specific styling */
.CodeMirror {
    height: 100%; /* Ensure CodeMirror takes up the container height */
    border-radius: 4px;
    font-size: 14px;
}

#saveButton {
    display: block;
    width: 100%;
    padding: 12px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.3s ease;
    margin-bottom: 15px; /* Keep its original margin */
    flex-shrink: 0; /* Prevent button from shrinking */

}

#saveButton:hover {
    background-color: #2980b9;
}

#saveButton:active {
    background-color: #2471a3;
}

#messageArea {
    margin-top: 5px;
    margin-bottom: 5px;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    font-weight: 500;
    flex-shrink: 0; /* Prevent message area from shrinking */
}

#messageArea.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

#messageArea.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

#messageArea pre { /* For displaying JSON errors */
    text-align: left;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.9em;
    max-height: 200px;
    overflow-y: auto;
    background-color: #fff;
    border: 1px solid #eee;
    padding: 10px;
}

/* Theme Selector Styles */
.controls {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px; /* Adds space between label and select */
    position:  absolute;
    top:  10px;
    right: 24px;
    z-index: 10000;
    flex-shrink: 0; /* Prevent controls from shrinking */
}

.controls label {
    font-weight: 500;
    color: #333;
}

#themeSelector {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 14px;
    cursor: pointer;
    min-width: 150px; /* Ensures the dropdown is not too small */
}

#themeSelector:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

/* Dark Mode Toggle Button */
#darkModeToggle {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none; /* Align with editor.css */
    border: 1px solid #ccc; /* Light mode default */
    color: #333; /* Icon color for light mode */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* Keep shadow for consistency with container shadow */
    padding: 0;
    margin-left: 10px;
    margin-right: 10px;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease; /* Add transition */
}
.icon-placeholder
{
    width:35px;

}

#darkModeToggle .icon-placeholder::before {
    content: '🌙'; /* Moon icon for dark mode */
    font-size: 20px;
}

body.dark-mode #darkModeToggle .icon-placeholder::before {
    content: '☀️'; /* Sun icon for light mode */
}

#darkModeToggle:hover {
    background-color: #f0f0f0; /* Light hover effect */
}

/* Dark Mode Styles */
body.dark-mode {
    background-color: #1C2833; /* Dark background for the page */
    color: #e0e0e0; /* Light text for dark mode */
}

body.dark-mode .container {
    background-color: #111827; /* Darker background for the container */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); /* Adjusted shadow for dark mode */
    border: 1px solid #444; /* Subtle border for container in dark mode */
}

body.dark-mode h1 {
    color: #e0e0e0; /* Light H1 text */
}

body.dark-mode p {
    color: #b0b0b0; /* Lighter paragraph text */
}

body.dark-mode code {
    background-color: #3a3a3a; /* Darker code background */
    color: #d0d0d0; /* Lighter code text */
}

body.dark-mode #editor-container {
    border: 1px solid #444; /* Darker border for editor container */
}

body.dark-mode .tabs {
    border-bottom-color: #444;
}

body.dark-mode .tab-button {
    color: #adb5bd;
}

body.dark-mode .tab-button:hover {
    color: #8ab4f8; /* A light blue for hover in dark mode */
}

body.dark-mode .tab-button.active {
    color: #8ab4f8;
    border-bottom-color: #8ab4f8;
}

body.dark-mode .editor-tab-content {
    border: 1px solid #444; /* Darker border for editor container */
}


/* CodeMirror in dark mode will be handled by its own theme, but we can adjust container if needed */

body.dark-mode #saveButton {
    background-color: #007acc; /* A slightly different blue for dark mode */
    color: #fff;
}

body.dark-mode #saveButton:hover {
    background-color: #005fa3;
}

body.dark-mode #messageArea.success {
    background-color: #2a3a2a; /* Darker success background */
    color: #a7d7a7; /* Lighter success text */
    border: 1px solid #3c5c3c;
}

body.dark-mode #messageArea.error {
    background-color: #4a2a2a; /* Darker error background */
    color: #f0a0a0; /* Lighter error text */
    border: 1px solid #6c3c3c;
}

body.dark-mode #messageArea pre {
    background-color: #333;
    border: 1px solid #555;
    color: #ccc;
}

body.dark-mode .controls label {
    color: #e0e0e0; /* Light label text */
}

body.dark-mode #themeSelector {
    background-color: #3a3a3a; /* Dark select background */
    color: #e0e0e0; /* Light select text */
    border: 1px solid #555; /* Darker border for select */
}

body.dark-mode #themeSelector:focus {
    border-color: #007acc;
    box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.3);
}

/* Dark Mode Toggle Button in Dark Mode */
body.dark-mode #darkModeToggle {
    background: none;
    border: 1px solid #555; /* Darker border */
    color: #e0e0e0; /* Icon color for dark mode */
}

body.dark-mode #darkModeToggle:hover {
    background-color: #3a3a3a; /* Darker hover effect */
}
