/**
 * Notices (SPEC §4 «Varsler og feilmeldinger»): toast, field error, alert box,
 * confirmation dialog and empty state. Shared by the theme and all plugins.
 * JS: js/dh-toast.js (dhToast, dhConfirm, dhField, dhAlert). Tokens only.
 */

/* -----------------------------------------
   Toast
   ----------------------------------------- */
.dh-toasts {
    position: fixed;
    right: max(20px, env(safe-area-inset-right, 0px));
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 100001; /* above the mini-cart drawer and date selector dialog */
    display: grid;
    gap: 8px;
    width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}

.dh-toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 12px 12px 14px;
    background: var(--dh-card);
    color: var(--dh-foreground);
    border: 1px solid var(--dh-border);
    border-radius: 1.2rem;
    box-shadow: var(--dh-shadow-pop);
    font-family: var(--dh-font-sans);
    pointer-events: auto;
    animation: dh-toast-in 160ms ease-out;
}

.dh-toast.is-leaving {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 140ms ease-out, transform 140ms ease-out;
}

@keyframes dh-toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .dh-toast { animation: none; }
    .dh-toast.is-leaving { transition: none; }
}

.dh-toast__icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--dh-radius-full);
    background: var(--dh-muted);
    color: var(--dh-muted-foreground);
}

.dh-toast--ok .dh-toast__icon {
    background: color-mix(in oklch, var(--dh-status-ok) 15%, transparent);
    color: var(--dh-status-ok);
}

.dh-toast--warn .dh-toast__icon {
    background: color-mix(in oklch, var(--dh-status-warn) 15%, transparent);
    color: var(--dh-status-warn);
}

.dh-toast--bad .dh-toast__icon {
    background: color-mix(in oklch, var(--dh-status-bad) 14%, transparent);
    color: var(--dh-status-bad);
}

.dh-toast__body {
    display: grid;
    flex: 1;
    min-width: 0;
}

.dh-toast__title {
    font-size: 0.90625rem;
    font-weight: 500;
    line-height: 1.35;
}

.dh-toast__text {
    font-size: 0.8125rem;
    color: var(--dh-muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dh-toast__action {
    all: unset;
    flex: none;
    padding: 6px 8px;
    border-radius: 0.7rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--dh-foreground);
    text-decoration: underline;
    text-underline-offset: 3px;
    white-space: nowrap;
    cursor: pointer;
}

.dh-toast__close {
    all: unset;
    flex: none;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--dh-radius-full);
    color: var(--dh-muted-foreground);
    cursor: pointer;
}

.dh-toast__action:hover,
.dh-toast__close:hover {
    background: var(--dh-accent);
}

.dh-toast__action:focus-visible,
.dh-toast__close:focus-visible {
    outline: 3px solid color-mix(in oklch, var(--dh-ring) 50%, transparent);
}

/* Tablet and mobile: above the tab bar (shown up to 1024px) */
@media (max-width: 1024px) {
    .dh-toasts {
        bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 600px) {
    .dh-toasts {
        left: 16px;
        right: 16px;
        width: auto;
    }
}

/* -----------------------------------------
   Field error (input wrapped by .dh-field or any input)
   ----------------------------------------- */
.dh-field-error {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.84375rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--dh-status-bad);
}

.dh-field-error svg {
    flex: none;
}

.dh-field-error a,
.dh-field-error button {
    all: unset;
    margin-left: 2px;
    color: var(--dh-status-bad);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"],
.dh-field.is-invalid {
    border-color: var(--dh-status-bad) !important;
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--dh-status-bad) 18%, transparent) !important;
}

.dh-field.is-valid::after {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    border-radius: var(--dh-radius-full);
    background: var(--dh-status-ok);
}

/* -----------------------------------------
   Alert box (in the page)
   ----------------------------------------- */
.dh-alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0;
    padding: 14px 16px;
    border-radius: 1.2rem;
    font-family: var(--dh-font-sans);
    font-size: 0.875rem;
    line-height: 1.45;
    list-style: none;
}

.dh-alert > svg {
    flex: none;
    margin-top: 2px;
}

.dh-alert__body {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.dh-alert__title {
    font-size: 0.90625rem;
    font-weight: 500;
}

.dh-alert__text {
    color: var(--dh-foreground);
}

.dh-alert__text a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.dh-alert__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.dh-alert--bad {
    background: color-mix(in oklch, var(--dh-status-bad) 10%, transparent);
    color: var(--dh-status-bad);
}

.dh-alert--warn {
    background: color-mix(in oklch, var(--dh-status-warn) 12%, transparent);
    color: var(--dh-status-warn);
}

.dh-alert--info {
    background: var(--dh-muted);
    color: var(--dh-foreground);
}

.dh-alert--info > svg,
.dh-alert--info .dh-alert__text {
    color: var(--dh-muted-foreground);
}

.dh-alerts {
    display: grid;
    gap: 8px;
}

/* -----------------------------------------
   Confirmation dialog (only for what cannot be undone)
   ----------------------------------------- */
.dh-confirm {
    width: min(420px, calc(100vw - 32px));
    margin: auto;
    padding: 20px;
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius-2xl);
    background: var(--dh-card);
    color: var(--dh-foreground);
    box-shadow: var(--dh-shadow-pop);
    font-family: var(--dh-font-sans);
}

.dh-confirm::backdrop {
    background: oklch(0.2 0.02 150 / 40%);
}

.dh-confirm__title {
    margin: 0 0 8px;
    font: 600 1rem/1.4 var(--dh-font-heading);
}

.dh-confirm__text {
    margin: 0;
    font-size: 0.875rem;
    color: var(--dh-muted-foreground);
}

.dh-confirm__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* -----------------------------------------
   Empty state
   ----------------------------------------- */
.dh-empty {
    display: grid;
    justify-items: center;
    gap: 4px;
    padding: 28px 16px;
    border: 1px dashed var(--dh-border);
    border-radius: 1.2rem;
    text-align: center;
    font-size: 0.9375rem;
}

.dh-empty__title {
    font-weight: 500;
}

.dh-empty__text {
    color: var(--dh-muted-foreground);
    font-size: 0.875rem;
}

.dh-empty .dh-btn {
    margin-top: 8px;
}

/* WooCommerce notices handed to the toast are never shown in place */
.dh-notice-data {
    display: none !important;
}
