/* DiveLog shared modal dialog. Drives DL.Modal.confirm / DL.Modal.alert.
 *
 * Self-contained: doesn't depend on /stat/stat.css or any module CSS.
 * Chrome uses the shared :root theme tokens (--bg-card, --border, …) so
 * the dialog matches whatever theme is active.
 *
 * Overlay layering, highest last: .dl-header 1000 < .stat-modal 1100 <
 * .chart-modal 1200 < .dl-modal 1300. This dialog is top of the stack so a
 * confirm asked from inside another modal still surfaces on top, and every
 * full-viewport overlay clears the sticky app header. */

.dl-modal {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    padding: var(--space-4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1300;
    animation: dl-modal-fade-in 120ms ease-out;
}

@keyframes dl-modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.dl-modal-card {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-modal);
    box-shadow: var(--shadow-lg);
    padding: var(--space-5) var(--space-6) var(--space-4);
    width: min(420px, 92vw);
    max-height: 88vh;
    overflow: auto;
    animation: dl-modal-pop-in 140ms ease-out;
}

@keyframes dl-modal-pop-in {
    from { transform: translateY(8px) scale(0.98); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

.dl-modal-title {
    margin: 0 0 8px;
    font-size: var(--font-size-lg);
    font-weight: 650;
}

.dl-modal-body {
    font-size: var(--font-size-md);
    line-height: 1.45;
    margin-bottom: 16px;
    color: var(--text);
    opacity: 0.9;
    white-space: pre-line;
}

/* Rich confirm body (DL.Modal.confirm({node})). Wider than a one-sentence
   dialog, and the content — not the card — is what scrolls when a merge
   preview lists a dozen parts. */
.dl-modal-card.dl-modal-wide {
    width: min(560px, 94vw);
}

.dl-modal-extra {
    margin-bottom: 4px;
    max-height: 52vh;
    overflow: auto;
}

.dl-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* Plain-<button> fallback used when dl-form.js isn't on the page.
   Mirrors the dlf-button-primary look just enough to stay readable. */
.dl-modal-fallback-btn {
    appearance: none;
    background: var(--accent);
    color: var(--text-on-accent);
    border: 0;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.dl-modal-fallback-btn:hover { filter: brightness(1.06); }

/* ── Option dialog (DL.Modal.options) ────────────────────────────────────
   A switch list grouped under small headings — used by the PDF export to
   ask what may go into the document. */
.dl-modal-card.dl-modal-options {
    width: min(460px, 94vw);
}

.dl-modal-optgroup {
    margin-bottom: 14px;
}

.dl-modal-optgroup-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.dl-modal-optgroup-note {
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--text-subtle);
    margin-top: 4px;
}

/* One row per option: text left, switch right. */
.dl-modal-optrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    min-height: var(--touch-target);
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--border);
}
.dl-modal-optrow:last-of-type { border-bottom: 0; }
.dl-modal-optrow .dlf-field { margin: 0; flex: 0 0 auto; }
.dl-modal-opttext { display: flex; flex-direction: column; min-width: 0; cursor: pointer; }
.dl-modal-optlabel { font-size: var(--font-size-sm); font-weight: 600; color: var(--text); }
.dl-modal-optsub {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

/* ── Content dialog (DL.Modal.dialog) ───────────────────────────────── */
.dl-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin: calc(-1 * var(--space-2)) calc(-1 * var(--space-3)) var(--space-2) 0;
}
.dl-modal-head .dl-modal-title { margin: var(--space-2) 0 0; }
.dl-modal-x {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    margin-left: auto;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}
.dl-modal-x:hover { color: var(--text); background: var(--bg-subtle); }
.dl-modal-content { margin-bottom: var(--space-2); max-height: 62vh; overflow: auto; }

/* Phone: a bottom sheet, where the thumb is. */
@media (max-width: 600px) {
    .dl-modal { align-items: flex-end; padding: 0; }
    .dl-modal-card,
    .dl-modal-card.dl-modal-wide,
    .dl-modal-card.dl-modal-options {
        width: 100%;
        max-height: 92vh;
        border-radius: var(--radius-modal) var(--radius-modal) 0 0;
        border-bottom: 0;
        padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    }
    .dl-modal-actions { flex-wrap: wrap; }
    .dl-modal-actions > * { flex: 1 1 auto; }
}
