/* =============================================================
   App dialog — the themed replacement for alert(), confirm() and
   prompt(). Built by app/components/dialog.js on a native <dialog>
   opened with showModal(), so the browser supplies the top layer,
   the focus trap and Esc; this file only supplies the look.

   Colours come from the --app-* tokens in app/themes/themes.css,
   so light, dark and calm all drive it. The backdrop blur is the
   shared dialog::backdrop rule in modals.css.
   ============================================================= */

.app-dialog {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    margin: auto;
    padding: 0;
    border: 1px solid var(--app-border, var(--border-color, #e5e7eb));
    border-radius: var(--modal-radius, 16px);
    background: var(--app-elevated, #fff);
    color: var(--app-text, #111827);
    box-shadow: var(--shadow-lg, 0 24px 64px rgba(15, 23, 42, .12));
    font-family: inherit;
    overflow: hidden;
}

.app-dialog::backdrop {
    background: rgb(15 23 42 / 42%);
}

.app-dialog[open] {
    display: flex;
    flex-direction: column;
    animation: app-dialog-in .16s ease-out;
}

@keyframes app-dialog-in {
    from { opacity: 0; transform: translateY(6px) scale(.98); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .app-dialog[open] { animation: none; }
}

.app-dialog-form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
}

.app-dialog-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 20px 20px 0;
}

.app-dialog-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--app-primary-subtle, #eff6ff);
    color: var(--app-primary-text-on-tint, #1d4ed8);
}

.app-dialog-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-dialog[data-tone="danger"] .app-dialog-icon {
    background: var(--app-danger-subtle, #fee2e2);
    color: var(--app-danger-text, #991b1b);
}

.app-dialog[data-tone="warning"] .app-dialog-icon {
    background: var(--app-warning-subtle, #fef3c7);
    color: var(--app-warning-text, #92400e);
}

.app-dialog[data-tone="success"] .app-dialog-icon {
    background: var(--app-success-subtle, #dcfce7);
    color: var(--app-success-text, #166534);
}

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

.app-dialog-title {
    margin: 0;
    font-size: var(--fs-lg, 16px);
    font-weight: var(--fw-semibold, 600);
    line-height: var(--lh-tight, 1.25);
    color: var(--app-text, #111827);
}

.app-dialog-close {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: -2px -6px 0 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--app-muted, #6b7280);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.app-dialog-close:hover {
    background: var(--app-surface-subtle, #f1f5f9);
    color: var(--app-text, #111827);
}

.app-dialog-body {
    padding: 10px 20px 4px 68px;
    overflow-y: auto;
    font-size: var(--fs-md, 14px);
    line-height: var(--lh-normal, 1.5);
    color: var(--app-muted, #6b7280);
}

.app-dialog-message {
    margin: 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.app-dialog-message:empty { display: none; }

.app-dialog-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 14px;
}

.app-dialog-label {
    margin: 0;
    font-size: var(--fs-sm, 13px);
    font-weight: var(--fw-medium, 500);
    color: var(--app-text, #111827);
}

.app-dialog-input {
    width: 100%;
    min-height: var(--control-height, 38px);
    padding: 8px 12px;
    border: 1px solid var(--app-border, #e5e7eb);
    border-radius: 10px;
    background: var(--app-surface-muted, #f8fafc);
    color: var(--app-text, #111827);
    font: inherit;
    font-size: var(--fs-md, 14px);
}

textarea.app-dialog-input {
    min-height: 84px;
    resize: vertical;
}

.app-dialog-input:focus {
    outline: none;
    border-color: var(--app-primary, #2563eb);
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(37, 99, 235, .15));
}

.app-dialog-error {
    margin: 0;
    font-size: 12.5px;
    color: var(--app-danger-text, #991b1b);
}

.app-dialog-error:empty { display: none; }

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 18px 20px 20px;
}

.app-dialog-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 88px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--app-border, #e5e7eb);
    border-radius: 10px;
    background: var(--app-elevated, #fff);
    color: var(--app-text, #111827);
    font: inherit;
    font-size: var(--fs-md, 14px);
    font-weight: var(--fw-medium, 500);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}

.app-dialog-btn:hover {
    background: var(--app-surface-subtle, #f1f5f9);
}

.app-dialog-btn:focus-visible,
.app-dialog-close:focus-visible {
    outline: 2px solid var(--app-primary, #2563eb);
    outline-offset: 2px;
}

.app-dialog-btn-primary {
    border-color: var(--app-primary, #2563eb);
    background: var(--app-primary, #2563eb);
    color: #fff;
}

.app-dialog-btn-primary:hover {
    border-color: var(--app-primary-hover, #1d4ed8);
    background: var(--app-primary-hover, #1d4ed8);
}

.app-dialog-btn-danger {
    border-color: var(--app-danger, #dc2626);
    background: var(--app-danger, #dc2626);
    color: #fff;
}

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

@media (max-width: 575.98px) {
    .app-dialog-body { padding-left: 20px; }
    .app-dialog-actions { flex-direction: column-reverse; }
    .app-dialog-btn { width: 100%; }
}
