/**
 * Accessible Modal Styles using HTML <dialog> Element
 * WCAG 2.1 AA Compliant
 */

/* ==================== Base Dialog Styles ==================== */

dialog.modal {
    /* Force display even with open attribute */
    display: block;
    border: none;
    border-radius: 6px;
    box-shadow: 0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1),
                0 0 0 1px rgba(10, 10, 10, 0.02);
    padding: 0;
    background: white;
    color: #4a4a4a;

    /* Make dialog display as modal */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    z-index: 1000;
}

/* Manual backdrop (since we're not using .showModal()) */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(10, 10, 10, 0.86);
    backdrop-filter: blur(3px);
    z-index: 999;
}

/* Native backdrop (for reference, not used with open attribute) */
dialog.modal::backdrop {
    background-color: rgba(10, 10, 10, 0.86);
    backdrop-filter: blur(3px);
}

/* ==================== Size Variants ==================== */

/* Small modal - 400px max */
dialog.modal-small {
    max-width: 400px;
    width: 90%;
}

/* Medium modal - 600px max (default) */
dialog.modal-medium {
    max-width: 600px;
    width: 90%;
}

/* Large modal - 800px max */
dialog.modal-large {
    max-width: 800px;
    width: 90%;
}

/* Extra large modal - 1000px max */
dialog.modal-xlarge {
    max-width: 1000px;
    width: 90%;
}

/* Fit content - shrinks to content size */
dialog.modal-fit-content {
    width: auto;
    min-width: 300px;
    max-width: 90vw;
}

/* ==================== Modal Content Structure ==================== */

.modal-content {
    display: flex;
    flex-direction: column;
    min-height: 150px;
    background: white;
}

/* ==================== Modal Header ==================== */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #dbdbdb;
    flex-shrink: 0;
}

.modal-title {
    margin: 0 !important;
    color: #363636;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-header .delete {
    margin-left: auto;
    flex-shrink: 0;
}

/* ==================== Modal Body ==================== */

.modal-body {
    padding: 1.5rem;
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: calc(90vh - 200px); /* Prevent modal from being taller than viewport */
}

/* ==================== Modal Footer ==================== */

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid #dbdbdb;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ==================== Animations ==================== */

dialog.modal[open] {
    animation: modalFadeIn 0.2s ease-out;
}

dialog.modal::backdrop {
    animation: backdropFadeIn 0.2s ease-out;
}

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

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

/* ==================== Accessibility ==================== */

/* Focus visible for keyboard navigation */
dialog.modal button:focus-visible,
dialog.modal a:focus-visible,
dialog.modal input:focus-visible,
dialog.modal select:focus-visible,
dialog.modal textarea:focus-visible {
    outline: 2px solid #3273dc;
    outline-offset: 2px;
}

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

    dialog.modal::backdrop {
        background-color: rgba(0, 0, 0, 0.9);
    }

    .modal-header,
    .modal-footer {
        border-color: currentColor;
    }
}

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

/* ==================== Mobile Responsive ==================== */

@media screen and (max-width: 768px) {
    dialog.modal-small,
    dialog.modal-medium,
    dialog.modal-large,
    dialog.modal-xlarge {
        max-width: 95vw;
        width: 95vw;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        max-height: calc(90vh - 150px);
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .button {
        width: 100%;
    }
}

/* ==================== RTL Support ==================== */

[dir="rtl"] .modal-footer {
    flex-direction: row-reverse;
}

[dir="rtl"] .modal-header .delete {
    margin-left: 0;
    margin-right: auto;
}

/* ==================== Dark Mode Support (Optional) ==================== */

@media (prefers-color-scheme: dark) {
    dialog.modal {
        background: #2b2b2b;
        color: #f5f5f5;
    }

    .modal-content {
        background: #2b2b2b;
    }

    .modal-header,
    .modal-footer {
        border-color: #4a4a4a;
    }

    .modal-title {
        color: #f5f5f5;
    }

    dialog.modal::backdrop {
        background-color: rgba(0, 0, 0, 0.9);
    }
}
