/* ==========================================================================
   app-dialogs.css
   Centred, colour-coded message and confirmation dialogs for every page.
   Paired with assets/js/app-dialogs.js and injected by includes/theme_loader.php
   after the page's own stylesheets, so it wins without touching each screen.
   ========================================================================== */

/* ---------- Boot guard ----------
   The page's own alert bars are hidden from the first paint and lifted into a
   proper dialog by app-dialogs.js. The class is removed by that script; a
   timeout in the injected boot snippet removes it if the script never loads,
   so a JavaScript failure can never hide a message permanently. */
html.app-dialogs-booting :is(.alert, .alert-custom, .coa-alert, .so-link-alert, .theme-alert, [role="alert"]):not([data-app-dialog="off"]) {
    visibility: hidden !important;
}

/* ---------- Bootstrap modals ----------
   Every legacy modal form gets the same centred, colour-headed treatment as
   the notification dialogs. */
.modal {
    padding: 24px 16px;
}

.modal-dialog {
    align-items: center;
    display: flex;
    margin: 0 auto;
    min-height: calc(100% - 48px);
}

.modal-content {
    border: 1px solid var(--app-border, #e2e8f0);
    border-radius: 14px;
    box-shadow: 0 30px 80px -24px rgba(2, 6, 23, .55), 0 2px 8px rgba(2, 6, 23, .08);
    overflow: hidden;
    width: 100%;
}

.modal-header {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .12) 0%, rgba(255, 255, 255, 0) 55%),
        linear-gradient(135deg, var(--app-primary, #2563eb) 0%, var(--app-primary-dark, #1e40af) 100%);
    border-bottom: 0;
    color: #fff;
    padding: 12px 16px;
}

.modal-header .modal-title {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -.1px;
}

.modal-header .btn-close {
    filter: invert(1) grayscale(1) brightness(2);
    opacity: .9;
}

.modal-header .btn-close:hover,
.modal-header .btn-close:focus {
    opacity: 1;
}

.modal-body {
    background: #fff;
    padding: 16px;
}

.modal-footer {
    background: #f8fafc;
    border-top: 1px solid var(--app-border, #e2e8f0);
    gap: 8px;
    padding: 10px 16px;
}

.modal-backdrop {
    background: #0f172a;
}

.modal-backdrop.show {
    opacity: .55;
}

@media (max-width: 576px) {
    .modal { padding: 10px; }
    .modal-dialog { min-height: calc(100% - 20px); }
    .modal-content { border-radius: 12px; }
    .modal-header { padding: 11px 13px; }
    .modal-body { padding: 13px; }
}

:root {
    --dlg-success: #059669;
    --dlg-success-bg: #ecfdf5;
    --dlg-error: #dc2626;
    --dlg-error-bg: #fef2f2;
    --dlg-warning: #d97706;
    --dlg-warning-bg: #fffbeb;
    --dlg-info: #2563eb;
    --dlg-info-bg: #eff6ff;
    --dlg-question: #7c3aed;
    --dlg-question-bg: #f5f3ff;
    --dlg-text: #0f172a;
    --dlg-muted: #475569;
    --dlg-border: #e2e8f0;
    --dlg-radius: 16px;
}

/* ---------- Overlay ---------- */
.app-dialog-overlay {
    align-items: center;
    animation: appDialogOverlayIn .18s ease-out;
    background: rgba(15, 23, 42, .48);
    backdrop-filter: blur(3px);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 20px;
    position: fixed;
    z-index: 2147483000;
}

/* Success and info messages inform without blocking the page. */
.app-dialog-overlay.is-passive {
    background: transparent;
    backdrop-filter: none;
    pointer-events: none;
}

.app-dialog-overlay.is-closing {
    animation: appDialogOverlayOut .16s ease-in forwards;
}

.app-dialog-overlay:not(.is-passive) { pointer-events: auto; }

/* ---------- Card ---------- */
[data-app-dialog-done="1"] { display: none !important; }

.app-dialog {
    --dlg-accent: var(--dlg-info);
    --dlg-tint: var(--dlg-info-bg);
    animation: appDialogIn .22s cubic-bezier(.2, .9, .3, 1.1);
    background: linear-gradient(155deg, var(--dlg-tint), #fff 70%);
    border: 1px solid var(--dlg-accent);
    border-radius: var(--dlg-radius);
    box-shadow: 0 32px 90px -22px rgba(2, 6, 23, .55), 0 2px 8px rgba(2, 6, 23, .08);
    max-width: min(480px, calc(100vw - 32px));
    max-height: 100%;
    overflow: auto;
    pointer-events: auto;
    position: relative;
    width: 100%;
}

.app-dialog-overlay.is-closing .app-dialog {
    animation: appDialogOut .16s ease-in forwards;
}

.app-dialog.is-success { --dlg-accent: var(--dlg-success); --dlg-tint: var(--dlg-success-bg); }
.app-dialog.is-error { --dlg-accent: var(--dlg-error); --dlg-tint: var(--dlg-error-bg); }
.app-dialog.is-warning { --dlg-accent: var(--dlg-warning); --dlg-tint: var(--dlg-warning-bg); }
.app-dialog.is-info { --dlg-accent: var(--dlg-info); --dlg-tint: var(--dlg-info-bg); }
.app-dialog.is-question { --dlg-accent: var(--dlg-question); --dlg-tint: var(--dlg-question-bg); }
.app-dialog.is-danger { --dlg-accent: var(--dlg-error); --dlg-tint: var(--dlg-error-bg); }

/* Colour band announces the message type before the text is read. */
.app-dialog::before {
    background: var(--dlg-accent);
    content: '';
    height: 4px;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
}

/* ---------- Head ---------- */
.app-dialog-head {
    align-items: flex-start;
    display: flex;
    gap: 13px;
    padding: 22px 22px 0;
}

.app-dialog-icon {
    align-items: center;
    background: var(--dlg-tint);
    border-radius: 12px;
    color: var(--dlg-accent);
    display: flex;
    flex: 0 0 42px;
    height: 42px;
    justify-content: center;
    width: 42px;
}

.app-dialog-icon svg {
    display: block;
    height: 22px;
    width: 22px;
}

.app-dialog-titles {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

.app-dialog-title {
    color: var(--dlg-text);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: -.2px;
    line-height: 1.3;
    margin: 0;
}

.app-dialog-subtitle {
    color: #64748b;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .04em;
    margin: 3px 0 0;
    text-transform: uppercase;
}

.app-dialog-close {
    align-items: center;
    background: #f1f5f9;
    border: 0;
    border-radius: 8px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    flex: 0 0 28px;
    height: 28px;
    justify-content: center;
    margin-left: 4px;
    transition: background .15s ease, color .15s ease;
    width: 28px;
}

.app-dialog-close:hover { background: #fee2e2; color: #dc2626; }

.app-dialog-close svg { height: 13px; width: 13px; }

/* ---------- Body ---------- */
.app-dialog-body {
    color: var(--dlg-muted);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 13.5px;
    line-height: 1.6;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    overflow-wrap: anywhere;
    padding: 12px 22px 0;
    white-space: pre-wrap;
}

.app-dialog-body--html { white-space: normal; }

.app-dialog-body p { margin: 0 0 8px; }
.app-dialog-body p:last-child { margin-bottom: 0; }

.app-dialog-body strong { color: #1e293b; font-weight: 700; }

.app-dialog-body ul,
.app-dialog-body ol {
    margin: 6px 0;
    padding-left: 20px;
}

.app-dialog-body li { margin: 3px 0; }

.app-dialog-body a {
    color: var(--dlg-info);
    font-weight: 600;
    text-decoration: underline;
}

.app-dialog-body .bi,
.app-dialog-body i { display: none; }

/* ---------- Actions ---------- */
.app-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    padding: 20px 22px 22px;
}

.app-dialog-btn {
    align-items: center;
    background: #fff;
    border: 1px solid var(--dlg-border);
    border-radius: 10px;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 12.5px;
    font-weight: 650;
    gap: 6px;
    justify-content: center;
    min-height: 38px;
    min-width: 92px;
    padding: 8px 16px;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}

.app-dialog-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

.app-dialog-btn:active { transform: translateY(1px); }

.app-dialog-btn.is-primary {
    background: var(--dlg-accent);
    border-color: var(--dlg-accent);
    box-shadow: 0 8px 18px -10px var(--dlg-accent);
    color: #fff;
}

.app-dialog-btn.is-primary:hover {
    background: color-mix(in srgb, var(--dlg-accent) 86%, black);
    border-color: color-mix(in srgb, var(--dlg-accent) 86%, black);
    color: #fff;
}

.app-dialog-btn.is-danger {
    background: var(--dlg-error);
    border-color: var(--dlg-error);
    color: #fff;
}

.app-dialog-btn.is-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.app-dialog-btn:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dlg-accent) 24%, white);
    outline: none;
}

/* ---------- Auto-dismiss progress ---------- */
.app-dialog-progress {
    background: color-mix(in srgb, var(--dlg-accent) 14%, white);
    bottom: 0;
    height: 3px;
    left: 0;
    position: absolute;
    right: 0;
}

.app-dialog-progress span {
    background: var(--dlg-accent);
    display: block;
    height: 100%;
    transform-origin: left center;
    animation: appDialogProgress linear forwards;
}

@keyframes appDialogProgress {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* ---------- Motion ---------- */
@keyframes appDialogOverlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes appDialogOverlayOut { from { opacity: 1; } to { opacity: 0; } }

@keyframes appDialogIn {
    from { opacity: 0; transform: translateY(10px) scale(.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes appDialogOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(6px) scale(.98); }
}

@media (prefers-reduced-motion: reduce) {
    .app-dialog,
    .app-dialog-overlay,
    .app-dialog-overlay.is-closing,
    .app-dialog-overlay.is-closing .app-dialog { animation-duration: .01ms; }
}

/* ---------- Small screens ---------- */
@media (max-width: 520px) {
    .app-dialog-overlay { padding: 14px; }

    .app-dialog-head { padding: 18px 16px 0; gap: 11px; }
    .app-dialog-icon { flex-basis: 38px; height: 38px; width: 38px; }
    .app-dialog-title { font-size: 14.5px; }
    .app-dialog-body { padding: 10px 16px 0; font-size: 13px; }
    .app-dialog-actions { padding: 16px; gap: 8px; }
    .app-dialog-btn { flex: 1 1 100%; }
}

/* ---------- Printing ---------- */
@media print {
    .app-dialog-overlay { display: none !important; }
}
