/**
 * maintenance_handler.css - Styles for Maintenance Handler Modals
 * 
 * Provides consistent styling for maintenance task dialogs and result displays
 * Matches the existing login system and multi-view UI design patterns
 */

/* Base modal overlay */
.maintenance-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: maintenanceFadeIn 0.2s ease-out;
}

/* Fade in animation */
@keyframes maintenanceFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Modal content container */
.maintenance-modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    min-width: 350px;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
    animation: maintenanceSlideIn 0.3s ease-out;
    overflow-y: auto;
}

/* Wide modal for longer content */
.maintenance-modal-wide {
    min-width: 550px;
    max-width: 650px;
}

/* Slide in animation */
@keyframes maintenanceSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal title */
.maintenance-modal-title {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
}

/* Modal text */
.maintenance-modal-text {
    margin: 0 0 1.5rem 0;
    color: #666;
    line-height: 1.5;
    font-size: 0.95rem;
}

/* Form group */
.maintenance-form-group {
    margin-bottom: 1.5rem;
}

/* Label styling */
.maintenance-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
}

/* Input styling */
.maintenance-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.maintenance-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.maintenance-input::placeholder {
    color: #999;
}

/* File input styling */
.maintenance-file-input {
    width: 100%;
    padding: 0.6rem;
    border: 2px dashed #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    background: #fafafa;
    cursor: pointer;
}

.maintenance-file-input:hover {
    border-color: #2563eb;
    background: #f0f7ff;
}

.maintenance-file-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* File info text */
.maintenance-file-info {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

/* Button group */
.maintenance-button-group {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* Base button styling */
.maintenance-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    font-family: inherit;
    min-width: 90px;
}

.maintenance-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.maintenance-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Primary button (blue) */
.maintenance-btn-primary {
    background: #2563eb;
    color: white;
}

.maintenance-btn-primary:hover {
    background: #1d4ed8;
}

.maintenance-btn-primary:active {
    background: #1e40af;
}

/* Waiting for both the ZIP and the key */
.maintenance-btn.maintenance-btn-primary:disabled {
    background: #9ca3af;
    color: white;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Secondary button (gray) */
.maintenance-btn-secondary {
    background: #f5f5f5;
    color: #374151;
    border: 1px solid #d1d5db;
}

.maintenance-btn-secondary:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.maintenance-btn-secondary:active {
    background: #d1d5db;
}

/* Danger button (red) */
.maintenance-btn-danger {
    background: #dc2626;
    color: white;
}

.maintenance-btn-danger:hover {
    background: #b91c1c;
}

.maintenance-btn-danger:active {
    background: #991b1b;
}

/* Success button (green) */
.maintenance-btn-success {
    background: #10b981;
    color: white;
}

.maintenance-btn-success:hover {
    background: #059669;
}

.maintenance-btn-success:active {
    background: #047857;
}

/* Modal title with status colors */
.maintenance-title-success {
    color: #10b981;
}

.maintenance-title-error {
    color: #dc2626;
}

.maintenance-title-info {
    color: #2563eb;
}

/* Result container */
.maintenance-result-container {
    margin: 1rem 0 1.5rem 0;
}

/* Result message (pre-formatted) */
.maintenance-result-message {
    white-space: pre-wrap;
    margin: 0;
    color: #555;
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    border-left: 4px solid #2563eb;
    max-height: 400px;
    overflow-y: auto;
}

/* Execution log container */
.maintenance-execution-log-container {
    margin: 1rem 0 1.5rem 0;
}

.maintenance-log-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
}

/* Execution log textarea */
.maintenance-execution-log {
    width: 100%;
    min-height: 300px;
    max-height: 400px;
    padding: 0.8rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    background: #f8f9fa;
    color: #1f2937;
    resize: vertical;
    box-sizing: border-box;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

.maintenance-execution-log:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Toast message for brief notifications */
.maintenance-toast-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 0.8rem 1.2rem;
    border-radius: 6px;
    z-index: 10001;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    max-width: 320px;
    word-wrap: break-word;
}

.maintenance-toast-message.show {
    opacity: 1;
    transform: translateY(0);
}

/* Chinese text support */
.maintenance-modal-content.chinese-text {
    font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Source Han Sans CN", sans-serif;
    font-feature-settings: "kern" 1;
    text-rendering: optimizeLegibility;
}

.maintenance-modal-content.chinese-text .maintenance-modal-title {
    font-weight: 500;
    letter-spacing: 0.02em;
}

.maintenance-modal-content.chinese-text .maintenance-btn {
    letter-spacing: 0.05em;
}

/* Maintenance-specific styling for server key input */
.maintenance-input[type="password"] {
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    letter-spacing: 0.1em;
}

/* File upload area styling */
.maintenance-file-input::file-selector-button {
    background: #2563eb;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 3px;
    margin-right: 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background-color 0.2s ease;
}

.maintenance-file-input::file-selector-button:hover {
    background: #1d4ed8;
}

/* Progress indicator (if needed for future enhancements) */
.maintenance-progress {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin: 1rem 0;
    overflow: hidden;
}

.maintenance-progress-bar {
    height: 100%;
    background: #2563eb;
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* Status indicator */
.maintenance-status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.maintenance-status-success {
    background: #10b981;
}

.maintenance-status-error {
    background: #dc2626;
}

.maintenance-status-pending {
    background: #f59e0b;
    animation: maintenancePulse 1.5s infinite;
}

@keyframes maintenancePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Responsive design */
@media (max-width: 768px) {
    .maintenance-modal-content {
        padding: 1.5rem;
        margin: 1rem;
        min-width: 0;
        width: calc(100vw - 2rem);
    }
    
    .maintenance-modal-wide {
        min-width: 0;
        max-width: none;
    }
    
    .maintenance-button-group {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .maintenance-btn {
        width: 100%;
        padding: 0.8rem 1rem;
    }
    
    .maintenance-result-message {
        font-size: 0.8rem;
        padding: 0.8rem;
        max-height: 250px;
    }
    
    .maintenance-execution-log {
        min-height: 200px;
        max-height: 250px;
        font-size: 0.8rem;
        padding: 0.6rem;
    }
    
    .maintenance-toast-message {
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .maintenance-modal-content {
        padding: 1rem;
        margin: 0.5rem;
        width: calc(100vw - 1rem);
    }
    
    .maintenance-modal-title {
        font-size: 1.1rem;
    }
    
    .maintenance-modal-text,
    .maintenance-input,
    .maintenance-btn {
        font-size: 0.9rem;
    }
    
    .maintenance-execution-log {
        min-height: 150px;
        max-height: 200px;
        font-size: 0.75rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .maintenance-modal-content {
        border: 2px solid #000;
    }
    
    .maintenance-input,
    .maintenance-file-input {
        border: 2px solid #333;
    }
    
    .maintenance-input:focus,
    .maintenance-file-input:focus {
        border-color: #000;
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2);
    }
    
    .maintenance-btn {
        border: 2px solid;
    }
    
    .maintenance-btn-primary {
        border-color: #1e40af;
    }
    
    .maintenance-btn-secondary {
        border-color: #374151;
    }
    
    .maintenance-btn-danger {
        border-color: #991b1b;
    }
    
    .maintenance-execution-log {
        border: 2px solid #333;
    }
    
    .maintenance-execution-log:focus {
        border-color: #000;
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .maintenance-modal-overlay,
    .maintenance-modal-content,
    .maintenance-btn,
    .maintenance-input,
    .maintenance-file-input,
    .maintenance-toast-message {
        animation: none;
        transition: none;
    }
    
    .maintenance-btn:hover {
        transform: none;
    }
    
    .maintenance-status-pending {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .maintenance-modal-content {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .maintenance-modal-title {
        color: #f9fafb;
    }
    
    .maintenance-modal-text {
        color: #d1d5db;
    }
    
    .maintenance-label {
        color: #d1d5db;
    }
    
    .maintenance-input,
    .maintenance-file-input {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
    
    .maintenance-file-input {
        background: #2d3748;
    }
    
    .maintenance-input:focus,
    .maintenance-file-input:focus {
        border-color: #60a5fa;
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
    }
    
    .maintenance-input::placeholder {
        color: #9ca3af;
    }
    
    .maintenance-btn-secondary {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }
    
    .maintenance-btn-secondary:hover {
        background: #4b5563;
        border-color: #6b7280;
    }
    
    .maintenance-result-message,
    .maintenance-execution-log {
        background: #111827;
        border-left-color: #60a5fa;
        color: #f9fafb;
        border-color: #374151;
    }
    
    .maintenance-execution-log:focus {
        border-color: #60a5fa;
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
    }
    
    .maintenance-title-success {
        color: #34d399;
    }
    
    .maintenance-title-error {
        color: #f87171;
    }
    
    .maintenance-title-info {
        color: #60a5fa;
    }
    
    .maintenance-file-info {
        color: #9ca3af;
    }
}

/* Print styles (hide modals when printing) */
@media print {
    .maintenance-modal-overlay {
        display: none !important;
    }
}

/* Focus management for accessibility */
.maintenance-modal-content:focus-within {
    outline: none;
}

/* Ensure proper contrast for file input in all modes */
.maintenance-file-input::-webkit-file-upload-button {
    background: #2563eb;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 3px;
    margin-right: 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.maintenance-file-input::-webkit-file-upload-button:hover {
    background: #1d4ed8;
}

/* Enhanced server key input styling */
.maintenance-input[type="password"]::-webkit-input-placeholder {
    font-family: inherit;
    letter-spacing: normal;
}

.maintenance-input[type="password"]::-moz-placeholder {
    font-family: inherit;
    letter-spacing: normal;
}

.maintenance-input[type="password"]:-ms-input-placeholder {
    font-family: inherit;
    letter-spacing: normal;
}

.maintenance-input[type="password"]::placeholder {
    font-family: inherit;
    letter-spacing: normal;
}

/* Official calendar tool (official_calendar_tool.js) */
.ocal-content {
    font-size: 0.9rem;
    color: #374151;
    line-height: 1.5;
}

.ocal-section {
    border-top: 1px solid #e5e7eb;
    padding: 1rem 0;
}

.ocal-heading {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
}

.ocal-detail {
    color: #6b7280;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.ocal-warning {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    color: #78350f;
    overflow-wrap: anywhere;
}

.ocal-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.ocal-list {
    margin: 0.25rem 0 0.5rem 0;
    padding-left: 1.25rem;
    overflow-wrap: anywhere;
}

.ocal-staged {
    margin-top: 0.5rem;
    padding: 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.ocal-message {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    overflow-wrap: anywhere;
}

.ocal-message-success { background: #ecfdf5; color: #065f46; }
.ocal-message-info { background: #eff6ff; color: #1e3a8a; }
.ocal-message-error { background: #fef2f2; color: #991b1b; }

/* The button's label is rewritten on language change, so the mark is drawn with CSS. */
#btn-maintenance.has-calendar-notice::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 6px;
    border-radius: 50%;
    background: #dc2626;
    vertical-align: middle;
}

@media (max-width: 768px) {
    .maintenance-modal-wide.ocal-content {
        min-width: 0;
        width: calc(100vw - 32px);
    }
}
