/**
 * Portal Modals - Global Modal Styles
 * 
 * Piękne custom modale z dark mode support, animacjami i accessibility
 * 
 * @package Portal Transportowy
 * @since 4.10.0
 * @version 1.0.0
 */

/* ==========================================
   ACCESSIBILITY - Screen Readers
   ========================================== */

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

/* ==========================================
   VARIABLES - Light & Dark Mode Support
   ========================================== */

:root {
    /* Modal colors - Light Mode */
    --modal-backdrop: rgba(0, 0, 0, 0.5);
    --modal-bg: #ffffff;
    --modal-border: #e0e0e0;
    --modal-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    --modal-header-border: #e0e0e0;
    --modal-footer-bg: #f8f9fa;
    --modal-title-color: #1a1a1a;
    --modal-text-color: #333333;
    --modal-close-hover: #f1f1f1;
    --modal-icon-bg: #f0f0f0;
    
    /* Input colors */
    --modal-input-bg: #ffffff;
    --modal-input-border: #d1d5db;
    --modal-input-focus: #3b82f6;
    --modal-input-error: #ef4444;
    
    /* Animation */
    --modal-animation-duration: 0.3s;
    --modal-animation-timing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Support */
[data-theme="dark"] {
    --modal-backdrop: rgba(0, 0, 0, 0.7);
    --modal-bg: #1e1e1e;
    --modal-border: #333333;
    --modal-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --modal-header-border: #333333;
    --modal-footer-bg: #252525;
    --modal-title-color: #e0e0e0;
    --modal-text-color: #b0b0b0;
    --modal-close-hover: #2a2a2a;
    --modal-icon-bg: #2a2a2a;
    
    --modal-input-bg: #2a2a2a;
    --modal-input-border: #404040;
    --modal-input-focus: #60a5fa;
    --modal-input-error: #f87171;
}

/* ==========================================
   MODAL CONTAINER & BACKDROP
   ========================================== */

.portal-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--modal-animation-duration) var(--modal-animation-timing),
                visibility 0s linear var(--modal-animation-duration);
}

.portal-modal.portal-modal-show {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--modal-animation-duration) var(--modal-animation-timing);
}

.portal-modal.portal-modal-hide {
    opacity: 0;
    visibility: hidden;
}

/* Backdrop (tło przezroczyste) */
.portal-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-backdrop);
    backdrop-filter: blur(2px);
    animation: fadeIn var(--modal-animation-duration) var(--modal-animation-timing);
}

/* ==========================================
   MODAL DIALOG (główny kontener)
   ========================================== */

.portal-modal-dialog {
    position: relative;
    z-index: 10000;
    max-width: 90%;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn var(--modal-animation-duration) var(--modal-animation-timing);
}

/* Rozmiary modalów */
.portal-modal-small {
    width: 400px;
}

.portal-modal-medium {
    width: 500px;
}

.portal-modal-large {
    width: 700px;
}

/* Responsive */
@media (max-width: 768px) {
    .portal-modal-dialog {
        width: 95% !important;
        max-width: 95%;
    }
}

/* ==========================================
   MODAL CONTENT
   ========================================== */

.portal-modal-content {
    background: var(--modal-bg);
    border-radius: var(--radius-modal); /* 16px - Shape & Sizing System v4.0 */
    box-shadow: var(--modal-shadow);
    border: 1px solid var(--modal-border);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

/* ==========================================
   MODAL HEADER
   ========================================== */

.portal-modal-header {
    padding: var(--card-padding-md) var(--btn-padding-md); /* 20px 24px - Shape & Sizing System v4.0 */
    border-bottom: 1px solid var(--modal-header-border);
    display: flex;
    align-items: center;
    gap: var(--gap-md); /* 16px */
    position: relative;
}

.portal-modal-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

.portal-modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--modal-title-color);
    flex: 1;
}

/* Przycisk zamknięcia (X) */
.portal-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--modal-text-color);
    cursor: pointer;
    padding: var(--badge-padding-sm); /* 4px 8px */
    border-radius: var(--radius-md); /* 8px - Shape & Sizing System v5.0 */
    transition: background 0.2s ease;
    opacity: 0.6;
}

.portal-modal-close:hover {
    background: var(--modal-close-hover);
    opacity: 1;
}

.portal-modal-close:focus {
    outline: 2px solid var(--modal-input-focus);
    outline-offset: 2px;
}

/* ==========================================
   MODAL BODY
   ========================================== */

.portal-modal-body {
    padding: var(--modal-padding-md); /* 30px - Shape & Sizing System v4.0 */
    color: var(--modal-text-color);
    font-size: 1rem;
    line-height: 1.6;
    overflow-y: auto;
    max-height: calc(90vh - 180px);
}

.portal-modal-body p {
    margin: 0 0 12px 0;
}

.portal-modal-body p:last-child {
    margin-bottom: 0;
}

/* Input wrapper (dla prompt) */
.portal-modal-input-wrapper {
    margin-top: 16px;
}

.portal-modal-input {
    width: 100%;
    padding: var(--input-padding); /* 10px 15px - Shape & Sizing System v4.0 */
    font-size: 1rem;
    border: 2px solid var(--modal-input-border);
    border-radius: var(--radius-input); /* 4px */
    background: var(--modal-input-bg);
    color: var(--modal-text-color);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: var(--input-height-md); /* 44px - WCAG compliant */
}

.portal-modal-input:focus {
    outline: none;
    border-color: var(--modal-input-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.portal-modal-input.error {
    border-color: var(--modal-input-error);
}

.portal-modal-input.error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Dark mode input */
[data-theme="dark"] .portal-modal-input {
    color: #e0e0e0;
}

/* ==========================================
   MODAL FOOTER (przyciski)
   ========================================== */

.portal-modal-footer {
    padding: var(--btn-padding-lg); /* 16px 32px - Shape & Sizing System v4.0 */
    background: var(--modal-footer-bg);
    border-top: 1px solid var(--modal-header-border);
    display: flex;
    gap: var(--gap-md); /* 16px */
    justify-content: flex-end;
    border-radius: 0 0 var(--radius-modal) var(--radius-modal); /* 16px */
}

/* ==========================================
   MODAL BUTTONS
   ========================================== */

.portal-modal-btn {
    padding: var(--btn-padding-md); /* 12px 24px - Shape & Sizing System v4.0 */
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-button); /* 8px */
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
    min-height: var(--btn-height-md); /* 44px - WCAG compliant */
}

/* Primary Button */
.portal-modal-btn.btn-primary,
.portal-modal-btn.portal-btn-primary {
    background: #3b82f6;
    color: #ffffff;
}

.portal-modal-btn.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Secondary Button */
.portal-modal-btn.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

[data-theme="dark"] .portal-modal-btn.btn-secondary {
    background: #374151;
    color: #e5e7eb;
}

.portal-modal-btn.btn-secondary:hover {
    background: #d1d5db;
}

[data-theme="dark"] .portal-modal-btn.btn-secondary:hover {
    background: #4b5563;
}

/* Danger Button */
.portal-modal-btn.btn-danger {
    background: #ef4444;
    color: #ffffff;
}

.portal-modal-btn.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Warning Button */
.portal-modal-btn.btn-warning {
    background: #f59e0b;
    color: #ffffff;
}

.portal-modal-btn.btn-warning:hover {
    background: #d97706;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* Success Button */
.portal-modal-btn.btn-success {
    background: #10b981;
    color: #ffffff;
}

.portal-modal-btn.btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

/* Focus state dla wszystkich przycisków */
.portal-modal-btn:focus {
    outline: 2px solid var(--modal-input-focus);
    outline-offset: 2px;
}

/* Active state */
.portal-modal-btn:active {
    transform: translateY(0);
}

/* Disabled state */
.portal-modal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ==========================================
   ANIMATIONS
   ========================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================
   BODY CLASS (blokada scroll)
   ========================================== */

body.portal-modal-open {
    overflow: hidden;
    padding-right: var(--scrollbar-width, 0); /* Zapobiega layout shift */
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .portal-modal-content {
        border: 2px solid currentColor;
    }
    
    .portal-modal-btn {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .portal-modal,
    .portal-modal-backdrop,
    .portal-modal-dialog,
    .portal-modal-btn {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus visible (tylko dla keyboard navigation) */
.portal-modal-btn:focus-visible {
    outline: 3px solid var(--modal-input-focus);
    outline-offset: 2px;
}

/* ==========================================
   MOBILE OPTIMIZATIONS
   ========================================== */

@media (max-width: 480px) {
    .portal-modal-header {
        padding: 16px 20px;
    }
    
    .portal-modal-body {
        padding: var(--card-padding-md); /* 20px - Shape & Sizing System v5.0 */
    }
    
    .portal-modal-footer {
        padding: 12px 20px;
        flex-direction: column-reverse;
    }
    
    .portal-modal-btn {
        width: 100%;
        min-width: auto;
    }
    
    .portal-modal-title {
        font-size: 1.1rem;
    }
    
    .portal-modal-icon {
        font-size: 24px;
    }
}

/* ==========================================
   PRINT (ukryj modale w druku)
   ========================================== */

@media print {
    .portal-modal {
        display: none !important;
    }
}

