/* In-page popups that replace the browser's native alert()/confirm() boxes.
   Used by js/app-dialogs.js - the markup (a <dialog> plus a toast stack) is
   created lazily by that file on first use.
   Dark is the default; every light-theme rule is explicit under
   [data-theme="light"] - same convention as rule-of-one.css.
   Only class names starting with app-dialog or app-toast are used, so
   page-level rules for p, span, label, .modal, .btn-primary,
   button[type=submit] and input cannot leak in. */

/* ---------------- dialog box ---------------- */

.app-dialog {
    box-sizing: border-box;   /* the 24px padding counts inside the width cap */
    border: none;
    padding: 0;
    margin: auto;
    color: inherit;
    background: #333;
    border-radius: 10px;
    /* Percentages, not vw/vh: a modal dialog is laid out against the viewport
       WITHOUT its scrollbars, so the 16px side margins survive a scrollbar. */
    width: min(460px, calc(100% - 32px));
    max-height: calc(100% - 64px);
    max-width: calc(100% - 32px);
    overflow: hidden;
}
.app-dialog[open] {
    display: flex;
    flex-direction: column;
    padding: 24px;
}
.app-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

/* While armed (250 ms after opening) clicks and Enter/Space are ignored, so a
   held Enter or double-click that opened the popup cannot also answer it. */
.app-dialog[data-arming] .app-dialog-actions {
    pointer-events: none;
}

#appDialog .app-dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin: 0 0 12px;
    padding: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
    user-select: text;
}
#appDialog .app-dialog-title[hidden] { display: none; }

#appDialog .app-dialog-message {
    font-size: 14.5px;
    line-height: 1.5;
    color: #ddd;
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-y: auto;
    min-height: 0;
    flex: 0 1 auto;
    user-select: text;
}

#appDialog .app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

#appDialog .app-dialog-btn {
    font-family: inherit;
    width: auto;
    margin: 0;
    min-width: 88px;
    border: none;
    border-radius: 6px;
    padding: 9px 20px;
    font-size: 14px;
    line-height: 1.4;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
    text-transform: none;
}
#appDialog .app-dialog-btn:focus-visible {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}
#appDialog .app-dialog-confirm {
    background: #4CAF50;
    color: #fff;
}
#appDialog .app-dialog-confirm:hover:not(:disabled) { background: #45a049; }
#appDialog[data-variant="danger"] .app-dialog-confirm { background: #dc3545; }
#appDialog[data-variant="danger"] .app-dialog-confirm:hover:not(:disabled) { background: #c82333; }
#appDialog .app-dialog-cancel {
    background: transparent;
    color: #ccc;
    border: 1px solid #666;
}
#appDialog .app-dialog-cancel:hover:not(:disabled) {
    border-color: #999;
    color: #fff;
}
#appDialog .app-dialog-btn[hidden] { display: none; }

/* ---------------- toasts ---------------- */

.app-toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}
.app-toast {
    pointer-events: auto;
    background: #222;
    color: #fff;
    border: 1px solid #4CAF50;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 360px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    cursor: pointer;
    user-select: text;
}
.app-toast[data-kind="error"] { border-color: #dc3545; }
.app-toast[data-kind="info"] { border-color: #666; }
.app-toast.app-toast-show {
    opacity: 1;
    transform: translateY(0);
}

/* ---------------- light theme ---------------- */

[data-theme="light"] .app-dialog { background: #ffffff; }
[data-theme="light"] #appDialog .app-dialog-title { color: #111827; }
[data-theme="light"] #appDialog .app-dialog-message { color: #374151; }
[data-theme="light"] #appDialog .app-dialog-cancel {
    color: #4b5563;
    border-color: #d1d5db;
}
[data-theme="light"] #appDialog .app-dialog-cancel:hover:not(:disabled) {
    border-color: #9ca3af;
    color: #111827;
}
[data-theme="light"] .app-toast {
    background: #ffffff;
    color: #111827;
}
