/**
 * Unified Modal System CSS
 * Single source of truth for all modal styling
 * Replaces: duplicate modal definitions in style-guide.css
 * 
 * @version 1.0.0
 * @author Claude Code
 */

/* === MODAL BACKDROP === */
.um-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.um-backdrop.um-show {
    opacity: 1;
    visibility: visible;
}

/* === MODAL CONTAINER === */
.um-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2010;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    overflow: auto;
}

.um-container.um-show {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* === MODAL DIALOG === */
.um-dialog {
    background-color: white;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: auto;
}

/* Dialog Size Variants */
.um-dialog--sm {
    max-width: 400px;
}

.um-dialog--md {
    max-width: 600px;
}

.um-dialog--lg {
    max-width: 900px;
}

.um-dialog--xl {
    max-width: 1200px;
}

.um-dialog--full {
    max-width: 95vw;
    max-height: 95vh;
}

/* === MODAL CONTENT === */
.um-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 0.5rem;
    overflow: hidden;
}

/* === MODAL HEADER === */
.um-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f8f9fa;
    min-height: 70px;
    flex-shrink: 0;
}

.um-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    flex: 1;
    display: flex;
    align-items: center;
    line-height: 1.2;
}

.um-title i {
    margin-right: 0.5rem;
    color: #6b7280;
}

.um-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    color: #6b7280;
    border: none;
    background: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.um-close:hover {
    background-color: #f3f4f6;
    color: #374151;
}

.um-close:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* === MODAL BODY === */
.um-body {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
    max-height: calc(90vh - 140px); /* Account for header and footer */
}

/* === MODAL FOOTER === */
.um-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid #e5e7eb;
    background-color: #f8f9fa;
    min-height: 70px;
    flex-shrink: 0;
}

/* Footer buttons inside form (for HTMX compatibility) */
.um-footer-inside-form {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    margin: -1.5rem -1.5rem 0 -1.5rem; /* Negative margins to extend to body edges */
    border-top: 1px solid #e5e7eb;
    background-color: #f8f9fa;
    min-height: 70px;
    margin-top: 1.5rem; /* Space from last form element */
}

/* === BUTTONS === */
.um-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    min-height: 38px;
}

.um-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.um-btn-primary {
    background-color: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.um-btn-primary:hover {
    background-color: #2563eb;
    border-color: #2563eb;
}

.um-btn-secondary {
    background-color: #6b7280;
    color: white;
    border-color: #6b7280;
}

.um-btn-secondary:hover {
    background-color: #4b5563;
    border-color: #4b5563;
}

.um-btn-danger {
    background-color: #dc2626;
    color: white;
    border-color: #dc2626;
}

.um-btn-danger:hover {
    background-color: #b91c1c;
    border-color: #b91c1c;
}

.um-btn-success {
    background-color: #059669;
    color: white;
    border-color: #059669;
}

.um-btn-success:hover {
    background-color: #047857;
    border-color: #047857;
}

.um-btn-warning {
    background-color: #d97706;
    color: white;
    border-color: #d97706;
}

.um-btn-warning:hover {
    background-color: #b45309;
    border-color: #b45309;
}

/* Button Loading State */
.um-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.um-btn-loading {
    position: relative;
    color: transparent !important;
}

.um-btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: um-spin 1s linear infinite;
    color: white;
}

@keyframes um-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* === ARCHIVE-SPECIFIC STYLING === */

/* Archive Confirmation Modal Enhancements */
.um-container[data-modal-type="archive"] .um-title {
    color: #d97706;
}

.um-container[data-modal-type="archive"] .um-title i {
    color: #d97706;
}

.um-container[data-modal-type="restore"] .um-title {
    color: #059669;
}

.um-container[data-modal-type="restore"] .um-title i {
    color: #059669;
}

/* Archive Action Button States */
.archive-action-button {
    position: relative;
    transition: all 0.2s ease;
}

.archive-action-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.archive-action-button[data-loading="true"] {
    color: transparent;
}

.archive-action-button[data-loading="true"]::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: um-spin 1s linear infinite;
}

/* Archive Item Information Display */
.um-archive-info {
    background-color: #f8f9fa;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.um-archive-info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.um-archive-info-item:last-child {
    margin-bottom: 0;
}

.um-archive-info-label {
    font-weight: 500;
    color: #374151;
}

.um-archive-info-value {
    color: #6b7280;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.875rem;
}

/* Enhanced Alert Styling for Archive Modals */
.um-body .alert {
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.um-body .alert-warning {
    background-color: #fef3c7;
    border: 1px solid #f59e0b;
    color: #92400e;
}

.um-body .alert-success {
    background-color: #d1fae5;
    border: 1px solid #10b981;
    color: #047857;
}

.um-body .alert-danger {
    background-color: #fee2e2;
    border: 1px solid #ef4444;
    color: #dc2626;
}

.um-body .alert i {
    flex-shrink: 0;
    font-size: 1.25rem;
    margin-top: 0.125rem;
}

/* Archive Action Icons */
.um-archive-icon {
    color: #d97706;
    margin-right: 0.5rem;
}

.um-restore-icon {
    color: #059669;
    margin-right: 0.5rem;
}

/* Row Fade Out Animation (for successful actions) */
@keyframes um-fade-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0.3;
        transform: translateX(-10px);
    }
}

.um-row-fade-out {
    animation: um-fade-out 0.3s ease-out forwards;
}

/* === LOADING STATE === */
.um-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #6b7280;
    font-size: 0.875rem;
}

.um-loading i {
    margin-right: 0.5rem;
    animation: spin 1s linear infinite;
}

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

/* === ERROR STATE === */
.um-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #dc2626;
    font-size: 0.875rem;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.375rem;
    margin: 1rem;
}

/* === FORM STYLES === */
.um-container form {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.um-container .form-group {
    margin-bottom: 1rem;
}

.um-container .form-group:last-child {
    margin-bottom: 0;
}

.um-container label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
}

.um-container input,
.um-container textarea,
.um-container select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
}

.um-container input:focus,
.um-container textarea:focus,
.um-container select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.um-container .form-text {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

.um-container .form-error {
    font-size: 0.75rem;
    color: #dc2626;
    margin-top: 0.25rem;
}

/* === RESPONSIVE DESIGN === */
@media (max-width: 768px) {
    .um-container {
        padding: 0.5rem;
        align-items: flex-start;
    }
    
    .um-dialog {
        margin-top: 1rem;
        margin-bottom: 1rem;
        max-height: calc(100vh - 2rem);
    }
    
    .um-dialog--lg,
    .um-dialog--xl,
    .um-dialog--full {
        max-width: 100%;
    }
    
    .um-header,
    .um-body,
    .um-footer {
        padding: 1rem;
    }
    
    .um-footer,
    .um-footer-inside-form {
        flex-direction: column;
        gap: 0.5rem;
    }

    .um-footer .um-btn,
    .um-footer-inside-form .um-btn {
        width: 100%;
        justify-content: center;
    }
    
    .um-body {
        max-height: calc(100vh - 120px);
    }
}

@media (max-width: 480px) {
    .um-header,
    .um-body,
    .um-footer {
        padding: 0.75rem;
    }
    
    .um-title {
        font-size: 1.125rem;
    }
    
    .um-btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
    }
}

/* === MODAL OPEN BODY STATE === */
body.um-modal-open {
    overflow: hidden;
    padding-right: 0; /* Scrollbar compensation handled by JS if needed */
}

/* === ACCESSIBILITY === */
.um-container:focus {
    outline: none;
}

.um-container[aria-hidden="true"] {
    display: none !important;
}

/* Screen reader only content */
.um-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === ANIMATION VARIANTS === */
.um-container.um-fade {
    transition: opacity 0.15s linear;
}

.um-container.um-slide-down {
    transform: translateY(-50px);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.um-container.um-slide-down.um-show {
    transform: translateY(0);
}

.um-container.um-zoom {
    transform: scale(0.5);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.um-container.um-zoom.um-show {
    transform: scale(1);
}

/* === COMPONENT INTEGRATION === */

/* TinyMCE integration */
.um-container .tox-tinymce {
    position: relative;
    z-index: auto;
}

.um-container .tox-dialog-wrap__backdrop {
    z-index: 2020;
}

.um-container .tox-dialog {
    z-index: 2030;
}

/* Tom Select integration */
.um-container .ts-dropdown {
    z-index: 2020;
}

/* Tooltip integration */
.um-container .tooltip {
    z-index: 2020;
}

/* Date picker integration */
.um-container .datepicker {
    z-index: 2020;
}

/* === CONFIRMATION MODAL SPECIFIC === */
.um-container[data-modal-type="confirm"] .um-header {
    background-color: #fef2f2;
    border-bottom-color: #fecaca;
}

.um-container[data-modal-type="confirm"] .um-title {
    color: #dc2626;
}

/* === FORM MODAL SPECIFIC === */
.um-container[data-modal-type="form"] .um-body {
    padding: 0;
}

.um-container[data-modal-type="form"] form {
    padding: 1.5rem;
}

/* === PRINT STYLES === */
@media print {
    .um-backdrop,
    .um-container {
        display: none !important;
    }
}