/* ─── Shared backdrop ────────────────────────────────────────────────────── */

.modal__backdrop,
.drawer__backdrop {
    position: absolute;
    inset: 0;
    background-color: var(--overlay-image);
    cursor: pointer;
}

/* ─── Shared panel chrome ────────────────────────────────────────────────── */

.modal__title,
.drawer__title {
    grid-area: title;
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 600;
    padding: var(--space-6) 0 var(--space-6) var(--space-6);
    align-self: center;
}

.modal__close,
.drawer__close {
    grid-area: close;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: var(--space-4);
    width: var(--space-8);
    margin-right: var(--space-4);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition:
        color var(--duration-fast) var(--ease),
        background-color var(--duration-fast) var(--ease);
}

.modal__close:hover,
.drawer__close:hover {
    color: var(--text-primary);
    background-color: var(--surface-hover);
}

.modal__close svg,
.drawer__close svg {
    width: var(--space-6);
    height: var(--space-6);
}

.modal__body,
.drawer__body {
    grid-area: body;
    padding: 0 var(--space-6) var(--space-6);
    overflow-y: auto;
}

/* ─── Modal ──────────────────────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-6);
}

.modal__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: var(--width-narrow);
    max-height: 90dvh;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "title close"
        "body  body";
}

.modal__panel--lg {
    max-width: var(--width-content);
}

/* ─── Modal transitions ──────────────────────────────────────────────────── */

.modal--enter .modal__backdrop,
.modal--leave .modal__backdrop {
    transition: opacity var(--duration-slow) var(--ease);
}

.modal--enter-start .modal__backdrop,
.modal--leave-end   .modal__backdrop { opacity: 0; }

.modal--enter-end   .modal__backdrop,
.modal--leave-start .modal__backdrop { opacity: 1; }

.modal--enter .modal__panel,
.modal--leave .modal__panel {
    transition:
        opacity   var(--duration-slow) var(--ease),
        transform var(--duration-slow) var(--ease);
}

.modal--enter-start .modal__panel,
.modal--leave-end   .modal__panel {
    opacity: 0;
    transform: scale(0.97) translateY(var(--space-2));
}

.modal--enter-end   .modal__panel,
.modal--leave-start .modal__panel {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* ─── Drawer ─────────────────────────────────────────────────────────────── */

.drawer {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
}

.drawer__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    width: 100%;
    max-width: var(--width-narrow);
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "title close"
        "body  body";
}

/* ─── Drawer transitions ─────────────────────────────────────────────────── */

.drawer--enter .drawer__backdrop,
.drawer--leave .drawer__backdrop {
    transition: opacity var(--duration-slow) var(--ease);
}

.drawer--enter-start .drawer__backdrop,
.drawer--leave-end   .drawer__backdrop { opacity: 0; }

.drawer--enter-end   .drawer__backdrop,
.drawer--leave-start .drawer__backdrop { opacity: 1; }

.drawer--enter .drawer__panel,
.drawer--leave .drawer__panel {
    transition: transform var(--duration-slow) var(--ease-out);
}

.drawer--enter-start .drawer__panel,
.drawer--leave-end   .drawer__panel { transform: translateX(100%); }

.drawer--enter-end   .drawer__panel,
.drawer--leave-start .drawer__panel { transform: translateX(0); }
