/**
 * Server Settings Modal Styles
 * Matches productDetailsModal pattern: Full height, slide-in from right
 * 
 * @package Alledio Production Dashboard
 * @version 1.1
 */

/* Modal overlay - Fixed positioning but allows menu to be visible */
#serverSettingsModal {
    display: none;
    position: fixed;
    z-index: 50;
    /* Below menu panel (usually 500) but above content */
    top: var(--top-bar-height, 70px);
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100vh - var(--top-bar-height, 70px));
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: stretch;
    justify-content: flex-end;
    overflow: hidden;
    padding: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease, left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When menu panel is open, shift entire modal to start after menu */
body.menu-open #serverSettingsModal {
    left: 200px;
    /* Width of menu panel */
}

#serverSettingsModal[style*="flex"] {
    display: flex;
    pointer-events: auto;
    opacity: 1;
}

/* Apply frosted glass effect to main content when modal is open */
body.server-settings-modal-open .container,
body.server-settings-modal-open .dashboard-content,
body.server-settings-modal-open .dashboard-card {
    filter: blur(8px);
    transition: filter 0.5s ease;
    pointer-events: none;
}

/* Ensure top-bar and menu panel remain interactive and unblurred */
body.server-settings-modal-open .top-bar,
body.server-settings-modal-open .menu-panel {
    filter: none;
    pointer-events: auto;
}

/* Modal Container - The sliding panel */
#serverSettingsModal .modal-container {
    background-image: url("../../images/bg_noise.webp"), linear-gradient(180deg, #f8f8f7, #f1f0ee);
    background-position: 0 0, 0 0;
    background-size: auto, auto;
    border-radius: 0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 100%;
    /* Full width of the available space */
    height: 100%;
    margin: 0;
    border: none;
    border-left: 1px solid #dddfe0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
    pointer-events: auto;
    /* Start off-screen to the right */
    right: -100%;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Slide in when open */
#serverSettingsModal[style*="flex"] .modal-container {
    right: 0;
}

/* Modal Header */
#serverSettingsModal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #dddfe0;
    flex-shrink: 0;
    background: white;
    z-index: 10;
}

/* Header close button - override default modal-btn height */
#serverSettingsModal .modal-header .modal-btn-cancel {
    width: auto;
    height: auto;
    max-height: none;
    padding: 8px 16px;
    background: white;
    color: #2c3e50;
    border: 1px solid #dddfe0;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

#serverSettingsModal .modal-header .modal-btn-cancel:hover {
    background: #f8f9fa;
    border-color: #b0bec5;
}

/* Modal Body */
#serverSettingsModal .modal-body {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: none;
}

#serverSettingsModal .modal-body::-webkit-scrollbar {
    display: none;
}

/* Settings section styling */
.settings-section {
    max-width: auto;
    margin: 0 auto 24px auto;
}

.settings-section-title {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 8px;
}

.settings-section-hint {
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Horizontal grid layout for cleanup settings */
.cleanup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.cleanup-grid-item {
    min-width: 0;
    /* Prevent grid blowout */
}

/* Log subsection */
.log-subsection {
    background: white;
    border: 1px solid #e8ecef;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    height: -webkit-fill-available;
}

.log-subsection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.log-subsection-header h4 {
    font-size: 15px;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked+.toggle-slider {
    background-color: #2d8998;
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(24px);
}

/* Cleanup config */
.cleanup-config {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e8ecef;
}

.cleanup-config.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Form fields */
.form-field {
    margin-bottom: 16px;
}

.form-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #2c3e50;
}

.form-select,
.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    color: #1f2937;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-select:focus,
.form-input:focus {
    outline: none;
    border-color: #2d8998;
    box-shadow: 0 0 0 3px rgba(45, 137, 152, 0.1);
}

/* Date range fields */
.date-range-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.date-range-fields .form-field {
    margin-bottom: 0;
}

/* Clean Now button */
.clean-now-btn {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: #fff7ed;
    color: #d97706;
    border: 1px solid #fdba74;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.clean-now-btn svg {
    width: 18px;
    height: 18px;
}

.clean-now-btn:hover {
    background: #ffedd5;
    border-color: #fb923c;
}

.clean-now-btn:active {
    background: #fed7aa;
}

/* Modal footer */
#serverSettingsModal .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 32px;
    border-top: 1px solid #dddfe0;
    background: white;
    flex-shrink: 0;
}

/* Fix Save Settings and Cancel button height to match */
#serverSettingsModal .modal-footer .submit-btn,
#serverSettingsModal .modal-footer .modal-btn-cancel {
    height: 40px !important;
    max-height: 40px !important;
    padding: 0 24px !important;
    font-size: 13px !important;
    line-height: 40px !important;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#serverSettingsModal .modal-footer .modal-btn-cancel {
    border: 1px solid #dddfe0;
    color: #2c3e50;
    background: white;
}

#serverSettingsModal .modal-footer .modal-btn-cancel:hover {
    background: #f8f9fa;
    border-color: #b0bec5;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {

    #serverSettingsModal .modal-header,
    #serverSettingsModal .modal-container,
    .log-subsection,
    .modal-footer {
        background: #1a1d21;
        border-color: #2d3339;
    }

    #serverSettingsModal .modal-header {
        background: #1a1d21;
    }

    .settings-section-title,
    .log-subsection-header h4,
    .form-field label {
        color: #e5e7eb;
    }

    .settings-section-hint {
        color: #9ca3af;
    }

    .form-select,
    .form-input {
        background: #2d3339;
        border-color: #4b5563;
        color: #e5e7eb;
    }

    .clean-now-btn {
        background: rgba(245, 158, 11, 0.1);
        color: #fbbf24;
        border-color: rgba(245, 158, 11, 0.3);
    }

    .clean-now-btn:hover {
        background: rgba(245, 158, 11, 0.2);
    }

    #serverSettingsModal .modal-footer .modal-btn-cancel {
        background: #2d3339;
        border-color: #4b5563;
        color: #e5e7eb;
    }

    #serverSettingsModal .modal-footer .modal-btn-cancel:hover {
        background: #374151;
        border-color: #6b7280;
    }
}

/* Loading Overlay */
.settings-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

/* Dark mode loading overlay */
@media (prefers-color-scheme: dark) {
    .settings-loading-overlay {
        background: rgba(17, 24, 39, 0.7);
    }
}

/* Loading Spinner */
.settings-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Dark mode spinner */
@media (prefers-color-scheme: dark) {
    .settings-loading-spinner {
        border-color: rgba(96, 165, 250, 0.2);
        border-top-color: #60a5fa;
    }
}

/* Activity Log Settings Layout - Ultra Condensed */
.activity-log-toggles {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    /* Minimal gap */
    margin-top: 8px;
}

/* 2-column layout for larger screens */
@media (min-width: 768px) {
    .activity-log-toggles {
        grid-template-columns: 1fr 1fr;
        /* Max 2 columns */
        gap: 8px;
    }
}

.activity-log-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    /* Minimal padding */
    background: #fff;
    border: 1px solid #e8ecef;
    border-radius: 4px;
    transition: all 0.2s ease;
    min-height: 32px;
    /* Ultra compact height */
}

.activity-log-item:hover {
    border-color: #b0bec5;
    background: #f8f9fa;
    z-index: 1;
}

.activity-log-label {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow: hidden;
    line-height: 1;
}

.activity-log-title {
    font-size: 12px;
    /* Smaller font */
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

.activity-log-hint {
    font-size: 10px;
    /* Tiny hint */
    color: #95a5a6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
    max-width: 50%;
}

/* Ultra Small Toggle Switch */
.activity-log-item .toggle-switch {
    width: 28px;
    height: 16px;
    flex-shrink: 0;
}

.activity-log-item .toggle-slider {
    border-radius: 16px;
}

.activity-log-item .toggle-slider:before {
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
}

.activity-log-item .toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(12px);
}

/* Dark mode for activity logs */
@media (prefers-color-scheme: dark) {
    .activity-log-item {
        background: #2d3339;
        border-color: #4b5563;
    }

    .activity-log-item:hover {
        background: #374151;
        border-color: #6b7280;
    }

    .activity-log-title {
        color: #e5e7eb;
    }

    .activity-log-hint {
        color: #9ca3af;
    }
}