/* Generic modal built on the native <dialog> element.
 *
 * Markup:
 *   <button data-modal-open="my-modal">Open</button>
 *   <dialog id="my-modal" class="modal" aria-labelledby="my-modal-title">
 *       <div class="modal__panel">
 *           <h2 id="my-modal-title" class="modal__title">…</h2>
 *           <div class="modal__body">…</div>
 *           <div class="modal__actions">
 *               <button class="btn btn--ghost" data-modal-close>Cancel</button>
 *               <button class="btn btn--danger" type="submit">Confirm</button>  (destructive)
 *               <button class="btn btn--primary" type="submit">Confirm</button> (standard)
 *           </div>
 *       </div>
 *   </dialog>
 *
 * The companion modal.js wires up:
 *   - [data-modal-open="id"]   click → open the matching <dialog>
 *   - [data-modal-close]       click → close the containing dialog
 *   - Click on the dialog's backdrop → close
 *
 * <dialog> gives us focus trapping, Escape-to-close, and proper
 * accessibility semantics for free.
 */

.modal {
    border: none;
    padding: 0;
    border-radius: 10px;
    width: max-content;
    max-width: 90vw;
    background: var(--surface-card);
    color: var(--content-fg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, var(--alpha-shadow-lg));
}

.modal::backdrop {
    background: var(--surface-modal-scrim);
}

.modal__panel {
    padding: 1.25rem 1.5rem 1.1rem;
}

.modal__title {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal__body {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 0.95rem;
    white-space: nowrap;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.4rem;
}

/* Alias kept for existing markup; width is now max-content on all modals. */
.modal--wide {
    width: max-content;
    max-width: 90vw;
}

/* Subtle entry animation. */
.modal[open] {
    animation: modal-in 0.15s ease-out;
}

.modal[open]::backdrop {
    animation: backdrop-in 0.15s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ---- .modal--framed: the ClearView's dialog layout, for a dialog that opts in ----
   As the ClearView presentation draws its own dialogs (Settings, Term, ...):
   rounder corners, the title white on a blue bar across the top, and the
   buttons on a grey strip across the bottom.

   No change of markup: the title and the actions reach out through the
   panel's padding to the dialog's edges, so whatever sits between them
   keeps its usual inset. (Not clipped with overflow: a dropdown inside the
   dialog may need to hang out of it.) */
.modal--framed {
    --modal-frame-radius: 14px;
    /* A notch deeper than the buttons' blue, for white text at this size. */
    --modal-frame-bar: var(--color-blue-600);
    /* The title bar's height: its padding and one line of title. */
    --modal-frame-bar-height: calc(1.6rem + 1.1rem * 1.4);
    border-radius: var(--modal-frame-radius);
    /* The dialog itself is the bar's colour behind the bar. A white dialog
       shows through as a pale fringe along the bar's edges and round its
       corners: the browser clips the bar a fraction of a pixel inside the
       dialog's own rounded edge. */
    background: linear-gradient(
        to bottom,
        var(--modal-frame-bar) var(--modal-frame-bar-height),
        var(--surface-card) var(--modal-frame-bar-height)
    );
}

.modal--framed .modal__title {
    margin: -1.25rem -1.5rem 1.1rem;
    padding: 0.8rem 1.5rem;
    line-height: 1.4;
    border-radius: var(--modal-frame-radius) var(--modal-frame-radius) 0 0;
    background: var(--modal-frame-bar);
    color: var(--color-white);
}

.modal--framed .modal__actions {
    margin: 1.25rem -1.5rem -1.1rem;
    padding: 0.7rem 1.5rem;
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--modal-frame-radius) var(--modal-frame-radius);
    background: var(--surface-subtle);
}
