body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    margin: 0;
    background-color: #f8f9fa;
    color: #212529;
    line-height: 1.5;
}

header {
    background-color: #343a40;
    color: white;
    padding: 0.75rem 1.5rem; 
    display: flex;
    flex-direction: column; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding-bottom: 0.5rem; 
}

header .header-top-row h1 { /* Corrected to h1 */
    margin: 0;
    font-size: 1.4rem; 
    border-bottom: none;
    padding-bottom: 0;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis; 
    flex-grow: 1; 
    margin-right: 1rem; 
}

.header-top-row #logout-button {
    background-color: #dc3545;
    color: white;
    padding: 0.4rem 0.8rem; 
    margin-left: auto; 
    margin-top: 0;
    margin-bottom: 0;
    margin-right: 0; 
    font-size: 0.9rem; 
    flex-shrink: 0; 
}
.header-top-row #logout-button:hover {
    background-color: #c82333;
}


nav#main-nav {
    display: flex; 
    flex-wrap: wrap; 
    justify-content: flex-start; 
    width: 100%;
    padding-top: 0.5rem; 
    border-top: 1px solid #495057; 
}

nav#main-nav button, nav#main-nav a.nav-button { 
    background: none;
    border: none;
    color: #adb5bd;
    padding: 0.5rem 1rem;
    margin-right: 0.5rem; 
    margin-bottom: 0.5rem; 
    margin-left: 0; 
    cursor: pointer;
    font-size: 0.9rem; 
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    text-decoration: none; 
    display: inline-flex; 
    align-items: center;
}

nav#main-nav button:hover, nav#main-nav a.nav-button:hover {
    color: white;
    background-color: #495057;
}

nav#main-nav button.active, nav#main-nav a.nav-button.active { 
    color: white;
    font-weight: bold;
    background-color: #007bff; 
}

main#main-content {
    padding: 1.5rem; 
}

.admin-section, #login-section {
    background-color: #ffffff;
    padding: 1.5rem; 
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.07);
}

#login-section {
    max-width: 450px; 
    margin-left: auto;
    margin-right: auto;
}

.admin-section h2, #login-section h2 {
     margin-top: 0;
     margin-bottom: 1.5rem;
     padding-bottom: 0.5rem;
     border-bottom: 1px solid #dee2e6;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
textarea {
    width: 100%;
    box-sizing: border-box; 
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
input:focus, textarea:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

textarea {
    min-height: 60px;
    resize: vertical;
    font-family: monospace; 
}

button, .add-button { 
    display: inline-block;
    font-weight: 400;
    color: #fff;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    background-color: #007bff;
    border: 1px solid #007bff;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    margin-right: 0.5rem;
    margin-top: 0.5rem;
}

button:hover, .add-button:hover {
    color: #fff;
    background-color: #0056b3;
    border-color: #0056b3;
}

button:focus, .add-button:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.5);
}

button:disabled, .add-button:disabled {
    background-color: #6c757d;
    border-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.65;
}

.add-button { 
    background-color: #28a745;
    border-color: #28a745;
}
.add-button:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

.error-message {
    color: red;
    font-weight: bold;
    margin-top: 10px;
}

.status-message {
    color: green;
    font-weight: bold;
    margin-top: 10px;
}

.server-entry, .tool-entry {
    border: 1px solid #e9ecef;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 6px;
    background-color: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* Shared header styles for server and tool entries */
.server-entry .server-header, .tool-entry .tool-header {
    display: flex;
    align-items: center; /* Key for vertical alignment of items in the row */
    margin-bottom: 1rem;
    /* justify-content: flex-start; Let items flow and use margins/flex-grow for spacing */
}

.server-entry .server-header h3, .tool-entry .tool-header h3 {
    margin: 0;
    color: #007bff;
    cursor: pointer;
    flex-grow: 1; /* Allow h3 to take available space */
    padding-right: 1rem; /* Space after h3, before next inline element */
}
.server-entry .server-header h3:hover, .tool-entry .tool-header h3:hover {
    text-decoration: underline;
}

/* Style for the "Active" checkbox label in server header */
.server-entry .server-header .server-active-label {
    margin-right: 0.75rem; /* Space after checkbox, before H3 */
    display: inline-flex;
    align-items: center; /* Align items within the label itself */
}
.server-entry .server-header .server-active-label input[type="checkbox"] {
    margin: 0;
    vertical-align: middle; /* Helps align checkbox with potential (now removed) text in label */
}


/* Specific to tool header for additional elements */
.tool-entry .tool-header {
    /* display: flex; align-items: center; are shared */
    flex-wrap: wrap; /* Allow items to wrap to the next line if space is insufficient */
}

.tool-entry .tool-header .tool-exposed-name {
    font-size: 0.85em;
    color: #6c757d;
    margin-left: 0.5rem; /* Space after H3 */
    white-space: normal; /* Allow long text to wrap */
    /* margin-right: auto; Remove this, as there's no element to push to the far right anymore */
    /* Adding a small flex-shrink to allow it to shrink if needed, but h3 should grow more */
    flex-shrink: 1;
}

/* Style for the "Enabled" checkbox label in tool header (now at the start) */
.tool-entry .tool-header .tool-enable-label {
    margin-right: 0.75rem; /* Space after checkbox, before H3 */
    display: inline-flex;
    align-items: center;
}
.tool-entry .tool-header .tool-enable-label input[type="checkbox"] {
    margin: 0;
    vertical-align: middle; /* Consistent vertical alignment */
}

/* Styles for tools belonging to an inactive server */
.tool-entry.tool-server-inactive .tool-header h3,
.tool-entry.tool-server-inactive .tool-header .tool-exposed-name {
    color: #999; /* Gray out the text */
    cursor: not-allowed; /* Indicate non-interactivity */
}
.tool-entry.tool-server-inactive .tool-header .tool-enable-label {
    opacity: 0.6; /* Dim the checkbox label slightly */
    cursor: not-allowed;
}


/* Delete button specific styling if needed, assuming it's the last element */
.server-entry .server-header .delete-button {
    margin-left: auto; /* Push delete button to the far right */
    flex-shrink: 0; /* Prevent delete button from shrinking */
}


/* Shared details styles for server and tool entries */
.server-entry .server-details, .tool-entry .tool-details {
    padding-left: 1rem;
    border-left: 2px solid #e9ecef;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out, margin-top 0.3s ease-out, padding-top 0.3s ease-out, padding-bottom 0.3s ease-out;
    overflow: hidden;
    max-height: 2000px; /* Arbitrary large number for expanded state */
    opacity: 1;
    margin-top: 1rem; /* Add some space when expanded */
    padding-top: 1rem; /* Add padding when expanded */
    padding-bottom: 1rem; /* Add padding when expanded */
}

.server-entry.collapsed .server-details, .tool-entry.collapsed .tool-details {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-left-width: 0; /* Hide border when collapsed for compactness */
    padding-left: 0; /* Remove padding when collapsed */
}

/* Reduce bottom margin of header when entry is collapsed for compactness */
.server-entry.collapsed .server-header, .tool-entry.collapsed .tool-header {
    margin-bottom: 0;
}

.server-entry label, .tool-entry label {
    font-weight: 500; 
    color: #495057;
    margin-bottom: 0.25rem;
    display: block; 
}
.server-entry label.inline-label {
    display: inline-flex;
    align-items: center;
    width: auto; 
    margin-bottom: 1rem; 
}

.server-entry input[type="checkbox"], .tool-entry input[type="checkbox"] {
    margin-right: 0.5rem;
    vertical-align: middle;
    width: auto; 
    margin-bottom: 0; 
}
.tool-entry label { 
    display: inline-flex; 
    align-items: center;
    font-weight: normal; 
    width: 100%;
}
.tool-entry label strong {
    margin-right: 0.5rem;
}

.server-entry .delete-button, .server-entry .install-button {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #212529;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    margin: 0; 
    flex-shrink: 0; 
}
.server-entry .delete-button:hover {
    background-color: #e0a800;
    border-color: #d39e00;
}
.server-entry .install-button {
    background-color: #17a2b8;
    border-color: #17a2b8;
    color: white;
    margin-top: 0.5rem; 
}
.server-entry .install-button:hover {
     background-color: #138496;
    border-color: #117a8b;
}
.server-entry .install-button:disabled {
     background-color: #6c757d;
    border-color: #6c757d;
}

.reload-button { 
    background-color: #fd7e14; 
    border-color: #fd7e14;
    color: white;
}
.reload-button:hover { 
    background-color: #e67312;
    border-color: #d96c10;
}
.reload-button:disabled {
    background-color: #ffc99c;
    border-color: #ffc99c;
}

.cleanup-button { /* Styles for Reset All Tool Overrides and similar buttons */
    background-color: #ffc107; /* Yellow/Orange for warning/cleanup actions */
    border-color: #ffc107;
    color: #212529; /* Dark text for better contrast on yellow */
}
.cleanup-button:hover {
    background-color: #e0a800;
    border-color: #d39e00;
    color: #212529;
}
.cleanup-button:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(224, 168, 0, 0.5); /* Adjusted shadow color */
}


hr {
    margin: 20px 0;
    border: 0;
    border-top: 1px solid #eee;
}

/* Styles for the footer button container in Tools section */
.tool-actions-footer {
    display: flex;
    justify-content: space-between; /* Pushes first item (save) to left, last item (reset) to right */
    align-items: center;
    margin-top: 1rem; /* Space above the button row */
    flex-wrap: wrap; /* Allow buttons to wrap on very narrow screens if needed, before media query kicks in */
}

.tool-actions-footer button {
    margin-top: 0.5rem; /* Keep consistent top margin for buttons */
    /* margin-right: 0; Remove default right margin from generic button if it interferes with space-between */
    /* The default button style has margin-right: 0.5rem. For space-between, this is usually fine. */
    /* If only two buttons, the space-between will handle it. If more, this might need adjustment. */
}

/* Ensure the cleanup button (Reset All) doesn't have excessive left margin from generic button style if it's the rightmost */
/* Note: Specific styles for .cleanup-button within .tool-actions-footer were previously here but removed as they were empty or handled by parent layout. */

/* Ensure the save button (first child) doesn't have excessive right margin from generic button style */


/* Responsive adjustments for Tool Header on narrow screens */
@media screen and (max-width: 768px) {
    .tool-entry .tool-header {
        flex-direction: column; /* Stack items vertically */
        align-items: flex-start; /* Align items to the left */
    }

    .tool-entry .tool-header .tool-enable-label,
    .tool-entry .tool-header h3,
    .tool-entry .tool-header .tool-exposed-name,
    .tool-entry .tool-header .reset-tool-overrides-button { /* Added reset button here */
        width: 100%; /* Make each item take full width in column layout */
        margin-left: 0;
        margin-right: 0;
        padding-right: 0; /* Reset padding that was for row layout */
        box-sizing: border-box; /* Ensure padding/border don't add to width */
    }

    .tool-entry .tool-header .tool-enable-label {
        margin-bottom: 0.5rem; /* Space below checkbox label */
    }
    
    .tool-entry .tool-header h3 {
        margin-bottom: 0.25rem; /* Space below H3 */
        /* flex-grow: 0; Not strictly necessary in column, but good for clarity */
    }
    
    .tool-entry .tool-header .tool-exposed-name {
        margin-bottom: 0.5rem; /* Space below "Exposed As" text before reset button */
        /* font-size can remain as is or be adjusted if needed */
        /* margin-left was reset above */
    }

    .tool-entry .tool-header .reset-tool-overrides-button {
        /* width: auto; Allow button to size to its content, but still be left-aligned due to align-items: flex-start on parent */
        /* align-self: flex-start; Explicitly align left if width is auto */
        /* No margin-bottom needed if it's the last item in the stacked header before details */
        margin-top: 0.25rem; /* Add a little space if it stacks below exposed-name */
    }

    /* Responsive adjustments for the new .tool-actions-footer */
    .tool-actions-footer {
        flex-direction: column;
        align-items: stretch; /* Make buttons full width */
    }
    .tool-actions-footer button {
        width: 100%;
        margin-right: 0; /* Remove right margin when stacked */
    }
    .tool-actions-footer button:not(:last-child) {
        margin-bottom: 1.5rem; /* Increased bottom margin for better spacing when stacked */
    }
}


footer p {
    margin: 0.25rem 0;
}
.env-vars-container {
    margin-top: 5px;
    margin-bottom: 10px;
    padding-left: 15px; 
    border-left: 2px solid #eee; 
}

.env-var-row {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}

.env-var-row input[type="text"] {
    flex-grow: 1;
    margin: 0 5px;
    padding: 4px 6px; 
    font-size: 0.9em; 
}

.env-var-row span {
    margin: 0 5px;
}

.env-var-row .env-key-input {
    max-width: 150px; 
}

.delete-env-var-button {
    padding: 3px 8px;
    font-size: 0.9em;
    cursor: pointer;
    border: 1px solid #f5c6cb; 
    background-color: #f8d7da; 
    color: #721c24;
    border-radius: 3px;
    margin-left: 5px;
}

.add-env-var-button {
    padding: 3px 8px; 
    font-size: 0.9em; 
    cursor: pointer;
    border: 1px solid #007bff; 
    background-color: #007bff; 
    color: #fff; 
    border-radius: 3px;
    margin-left: 0; 
    margin-top: 5px; 
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out; 
}

.delete-env-var-button:hover {
    background-color: #f1b0b7;
}

.add-env-var-button:hover {
    background-color: #0056b3; 
    border-color: #0056b3;
}

/* Modal Styles */
.modal {
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.6); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

.modal-content {
    background-color: #fefefe;
    margin: auto; 
    padding: 25px;
    border: 1px solid #888;
    width: 80%; 
    max-width: 700px; 
    border-radius: 8px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    position: relative; 
}

.modal-content h2 {
    margin-top: 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.modal-content textarea {
    width: calc(100% - 20px); 
    min-height: 200px;
    margin-bottom: 15px;
    font-family: monospace;
    font-size: 0.9em;
    padding: 10px;
}

.close-button {
    color: #aaa;
    float: right; 
    font-size: 28px;
    font-weight: bold;
    position: absolute; 
    top: 10px;
    right: 20px;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-actions {
    text-align: right; 
    margin-top: 15px;
}

.modal-actions button {
    margin-left: 10px;
}

.modal-actions button[type="button"] { 
    background-color: #6c757d;
    border-color: #6c757d;
}
.modal-actions button[type="button"]:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

/* Responsive adjustments */
@media screen and (max-width: 768px) {
    header {
        padding: 0.75rem 1rem; 
    }
    /* .header-top-row adjustments for mobile are handled by its default flex properties */
    /* No specific overrides needed here for .header-top-row itself in this media query */
    header .header-top-row h1 { /* Corrected to h1 */
        font-size: 1.1rem; /* Smaller title on mobile */
        white-space: normal; /* Allow title to wrap if very long */
    }
    .header-top-row #logout-button {
        padding: 0.3rem 0.6rem; /* Smaller logout button */
        font-size: 0.8rem;
        white-space: nowrap; /* Prevent "Logout" text from wrapping */
    }
    nav#main-nav {
        justify-content: space-around; /* Distribute nav buttons more evenly */
        padding-top: 0.75rem;
    }
    nav#main-nav button, nav#main-nav a.nav-button {
        margin: 0.25rem; 
        padding: 0.4rem 0.6rem; /* Slightly smaller nav buttons */
        font-size: 0.85rem;
    }

    .modal-content {
        width: 90%;
        padding: 20px;
    }
    .modal-content h2 {
        font-size: 1.2rem;
    }
    .modal-content textarea {
        min-height: 150px;
    }
}

footer { /* Basic footer style */
    padding: 1.5rem 2rem;
    text-align: center;
    font-size: 0.9em;
    background-color: #e9ecef;
    color: #6c757d;
    border-top: 1px solid #dee2e6;
    margin-top: 2rem; /* Space above footer */
}

/* Responsive adjustments for Tool Header on narrow screens */
@media screen and (max-width: 768px) {
    .tool-entry .tool-header {
        flex-direction: column; /* Stack items vertically */
        align-items: flex-start; /* Align items to the left */
    }

    .tool-entry .tool-header .tool-enable-label,
    .tool-entry .tool-header h3,
    .tool-entry .tool-header .tool-exposed-name,
    .tool-entry .tool-header .reset-tool-overrides-button { /* Added reset button here */
        width: 100%; /* Make each item take full width in column layout */
        margin-left: 0;
        margin-right: 0;
        padding-right: 0; /* Reset padding that was for row layout */
        box-sizing: border-box; /* Ensure padding/border don't add to width */
    }

    .tool-entry .tool-header .tool-enable-label {
        margin-bottom: 0.5rem; /* Space below checkbox label */
    }
    
    .tool-entry .tool-header h3 {
        margin-bottom: 0.25rem; /* Space below H3 */
        /* flex-grow: 0; /* Not strictly necessary in column, but good for clarity */
    }
    
    .tool-entry .tool-header .tool-exposed-name {
        margin-bottom: 0.5rem; /* Space below "Exposed As" text before reset button */
        /* font-size can remain as is or be adjusted if needed */
        /* margin-left was reset above */
    }

    .tool-entry .tool-header .reset-tool-overrides-button {
        /* width: auto; /* Allow button to size to its content, but still be left-aligned due to align-items: flex-start on parent */
        /* align-self: flex-start; /* Explicitly align left if width is auto */
        /* No margin-bottom needed if it's the last item in the stacked header before details */
        margin-top: 0.25rem; /* Add a little space if it stacks below exposed-name */
    }
}

footer p {
    margin: 0.25rem 0;
}

footer a {
    color: #007bff;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}
/* Styles for Per-Tool Reset Button */
.reset-tool-overrides-button {
    background-color: #6c757d; /* Secondary/neutral color */
    border-color: #6c757d;
    color: #fff;
    padding: 0.2rem 0.5rem; /* Smaller padding */
    font-size: 0.8em; /* Smaller font */
    margin-left: 0.75rem; /* Space from the "Exposed As" text */
    line-height: 1.4;
    flex-shrink: 0; /* Prevent shrinking if header space is tight */
}
.reset-tool-overrides-button:hover {
    background-color: #5a6268;
    border-color: #545b62;
    color: #fff;
}