/* ═══════════════════════════════════════════════════════════════════════════════
   WEBSLY MODAL — 5.1
   Reusable modal/dialog primitive. Uses native <dialog> for accessibility
   (focus trap, Esc-to-close, backdrop). All sizing/color hooks use theme tokens.
   ══════════════════════════════════════════════════════════════════════════════ */

/* ─── Container ──────────────────────────────────────────────────────────── */
.ws-modal {
    padding: 0;
    border: none;
    background: transparent;
    overflow: visible;
    max-width: min(92vw, 680px);
    width: 100%;
    color: var(--text-base);
}

.ws-modal::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.ws-modal[data-size="sm"]  { max-width: min(92vw, 420px); }
.ws-modal[data-size="md"]  { max-width: min(92vw, 560px); }
.ws-modal[data-size="lg"]  { max-width: min(92vw, 720px); }
.ws-modal[data-size="xl"]  { max-width: min(94vw, 960px); }

/* ─── Panel ──────────────────────────────────────────────────────────────── */
.ws-modal__panel {
    position: relative;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: var(--radius-2xl, 24px);
    box-shadow:
        0 40px 80px -20px rgba(0, 0, 0, 0.35),
        0 10px 24px -8px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: min(88vh, 800px);
}

/* Style presets */
.ws-modal[data-style="glass"] .ws-modal__panel {
    background: rgba(var(--bg-surface-rgb, 255, 255, 255), 0.7);
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    border-color: rgba(255, 255, 255, 0.15);
}

.ws-modal[data-style="premium"] .ws-modal__panel {
    background: linear-gradient(160deg,
        var(--bg-surface, #fff) 0%,
        var(--bg-subtle, #f7f7f7) 100%);
    border: 1px solid transparent;
    background-clip: padding-box;
}
.ws-modal[data-style="premium"] .ws-modal__panel::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: var(--theme-grad-accent, linear-gradient(135deg, var(--theme-accent), var(--theme-accent-secondary)));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    z-index: 1;
}

.ws-modal[data-style="minimal"] .ws-modal__panel {
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.25);
}

/* ─── Sections ───────────────────────────────────────────────────────────── */
.ws-modal__media {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--bg-subtle, #f2f2f2);
    overflow: hidden;
    flex-shrink: 0;
}
.ws-modal__media img,
.ws-modal__media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ws-modal__body {
    padding: clamp(1.5rem, 3vw, 2.5rem);
    overflow-y: auto;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ws-modal__title {
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.015em;
    color: var(--text-strong, var(--text-base));
    margin: 0;
}

.ws-modal__text {
    font-size: 1rem;
    line-height: 1.65;
    color: var(--text-base);
    opacity: 0.88;
}
.ws-modal__text p { margin: 0 0 0.75em; }
.ws-modal__text p:last-child { margin-bottom: 0; }
.ws-modal__text a { color: var(--theme-accent); text-decoration: underline; text-underline-offset: 3px; }

.ws-modal__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
}

/* ─── Close Button ───────────────────────────────────────────────────────── */
.ws-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--bg-surface-rgb, 255, 255, 255), 0.85);
    border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 999px;
    color: var(--text-base);
    cursor: pointer;
    transition: transform 180ms ease, background 180ms ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.ws-modal__close:hover {
    transform: rotate(90deg);
    background: var(--bg-surface);
}
.ws-modal__close svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; }

/* ─── Entrance Animation ─────────────────────────────────────────────────── */
@keyframes ws-modal-in {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes ws-modal-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.ws-modal[open] .ws-modal__panel {
    animation: ws-modal-in 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.ws-modal[open]::backdrop {
    animation: ws-modal-backdrop-in 240ms ease both;
}
/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ws-modal[open] .ws-modal__panel,
    .ws-modal[open]::backdrop { animation: none; }
}

/* Body scroll lock (added/removed by JS) */
body.ws-modal-open { overflow: hidden; }

/* ═══════════════════════════════════════════════════════════════════════════
   TRIGGER AFFORDANCE — applied to any element with a modal attached.
   Visual hint on hover that the element is clickable.
   ══════════════════════════════════════════════════════════════════════════ */
.ws-modal-trigger {
    cursor: pointer;
    position: relative;
    transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 300ms ease;
}

/* --- Style: subtle (just cursor + tiny scale, no chip) --- */
.ws-modal-trigger[data-trigger-style="subtle"]:hover {
    transform: translateY(-2px);
}

/* --- Style: chip (floating "+ Details" label in corner on hover) --- */
.ws-modal-trigger[data-trigger-style="chip"]::after {
    content: attr(data-trigger-label);
    position: absolute;
    top: 14px;
    right: 14px;
    padding: 6px 12px;
    background: var(--theme-accent, #000);
    color: var(--text-on-accent, #fff);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: 999px;
    opacity: 0;
    transform: translateY(-6px) scale(0.92);
    transition: opacity 260ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 6px 18px -4px rgba(0, 0, 0, 0.25);
}
.ws-modal-trigger[data-trigger-style="chip"]:hover::after,
.ws-modal-trigger[data-trigger-style="chip"]:focus-visible::after {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* --- Style: icon-badge (circular expand icon in corner) --- */
.ws-modal-trigger[data-trigger-style="icon-badge"]::after {
    content: "";
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: var(--theme-accent);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='15 3 21 3 21 9'/><polyline points='9 21 3 21 3 15'/><line x1='21' y1='3' x2='14' y2='10'/><line x1='3' y1='21' x2='10' y2='14'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    transform: scale(0.6) rotate(-20deg);
    transition: opacity 260ms ease, transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 6px 18px -4px rgba(0, 0, 0, 0.3);
}
.ws-modal-trigger[data-trigger-style="icon-badge"]:hover::after,
.ws-modal-trigger[data-trigger-style="icon-badge"]:focus-visible::after {
    opacity: 1;
    transform: scale(1) rotate(0);
}

/* --- Style: tint (dark overlay fades in + centered readable label) --- */
.ws-modal-trigger[data-trigger-style="tint"] {
    overflow: hidden; /* keep overlay clipped to the card's radius */
    isolation: isolate;
}
.ws-modal-trigger[data-trigger-style="tint"]::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.78) 100%);
    opacity: 0;
    transition: opacity 320ms cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
    z-index: 3;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.ws-modal-trigger[data-trigger-style="tint"]::after {
    content: attr(data-trigger-label);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 320ms ease 40ms, transform 360ms cubic-bezier(0.22, 1, 0.36, 1) 40ms;
    pointer-events: none;
    z-index: 4;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    padding: 0 1rem;
    text-align: center;
}
.ws-modal-trigger[data-trigger-style="tint"]:hover::before,
.ws-modal-trigger[data-trigger-style="tint"]:focus-visible::before {
    opacity: 1;
}
.ws-modal-trigger[data-trigger-style="tint"]:hover::after,
.ws-modal-trigger[data-trigger-style="tint"]:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

/* --- Style: glow (soft accent glow around the card on hover) --- */
.ws-modal-trigger[data-trigger-style="glow"]:hover {
    box-shadow:
        0 0 0 1px rgba(var(--theme-accent-rgb, 0, 0, 0), 0.25),
        0 20px 40px -12px rgba(var(--theme-accent-rgb, 0, 0, 0), 0.25);
    transform: translateY(-3px);
}

/* Keyboard focus ring for all trigger styles */
.ws-modal-trigger:focus-visible {
    outline: 2px solid var(--theme-accent);
    outline-offset: 3px;
}
