/*
 * Copyright (c) 2025 Alexander Lakhin | alexander.lakhin@smart-design-hub.com
 */

/* ─── Design tokens ─────────────────────────────────────────────────────── */
/*
 * Left strip accent + coloured icon; neutral card background.
 * Severity mapping:
 *   info    → status-complete  (blue)
 *   success → status-ontrack   (green)
 *   warning → status-atrisk    (amber)
 *   error   → status-offtrack  (red)
 *   danger  → status-offtrack  (red)
 */

:where(.toast-container, .toast) {
    --toast-radius: var(--ui-radius, 10px);
    --toast-gap: 8px;
    /* Neutral card background — no status-tint fill */
    --toast-bg: var(--shd-card-bg-base, rgba(28, 30, 36, 0.92));
    --toast-bg-hover: color-mix(in srgb, var(--toast-bg) 88%, var(--toast-status-border) 12%);
    --toast-fg: var(--shd-card-text, var(--ui-text));
    --toast-fg-soft: var(--shd-card-text-soft, var(--ui-text-muted, var(--ui-text-dim)));
    --toast-border-neutral: var(--ui-border, rgba(255, 255, 255, 0.1));
    --toast-shadow: 0 2px 8px rgba(0, 0, 0, 0.18), 0 8px 24px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.055);
    --toast-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.22), 0 12px 30px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    --toast-action-bg: rgba(255, 255, 255, 0.09);
    --toast-action-border: rgba(255, 255, 255, 0.15);
    --toast-action-hover: rgba(255, 255, 255, 0.14);
    /* severity accent — default: info → status-complete */
    --toast-status-tint: var(--status-complete-tint);
    --toast-status-border: var(--status-complete-border);
    --toast-status-border-hover: color-mix(in srgb, var(--toast-status-border) 80%, #fff 20%);
}

/* ─── Container ─────────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    z-index: 100001;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    display: grid;
    grid-auto-rows: max-content;
    gap: var(--toast-gap);
    width: min(380px, calc(100vw - 24px));
    max-height: min(580px, calc(100vh - 32px));
    padding: 4px;
    overflow: visible;
    box-sizing: border-box;
    pointer-events: none;
}

/* ─── Toast base ────────────────────────────────────────────────────────── */

.toast {
    position: relative;
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 11px 13px;
    /* accent left strip: 4px coloured, other sides thin neutral */
    border: 1px solid var(--toast-border-neutral);
    border-left: 4px solid var(--toast-status-border);
    border-radius: var(--toast-radius);
    box-sizing: border-box;
    background: var(--toast-bg);
    color: var(--toast-fg);
    box-shadow: var(--toast-shadow);
    font: 400 12.5px/1.45 'Artifakt Element', system-ui, -apple-system, sans-serif;
    pointer-events: auto;
    cursor: pointer;
    overflow: hidden;
    touch-action: pan-y;
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    backdrop-filter: blur(12px) saturate(1.4);
    animation: toast-enter 200ms cubic-bezier(0.25, 0.8, 0.35, 1) both;
    transition:
        border-color 0.15s ease,
        background 0.15s ease,
        box-shadow 0.15s ease,
        opacity 150ms ease-out,
        transform 150ms ease-out;
}

/* hover: subtle glow through left strip brightening, no fill tint */
.toast:not(.dragging):not(.leaving):hover {
    border-left-color: var(--toast-status-border-hover);
    background: var(--toast-bg-hover);
    box-shadow: var(--toast-shadow-hover);
    transform: translateY(-1px);
}

/* ─── Severity modifiers ─────────────────────────────────────────────────── */

.toast.info {
    --toast-status-tint: var(--status-complete-tint);
    --toast-status-border: var(--status-complete-border);
}

.toast.success {
    --toast-status-tint: var(--status-ontrack-tint);
    --toast-status-border: var(--status-ontrack-border);
}

.toast.warning {
    --toast-status-tint: var(--status-atrisk-tint);
    --toast-status-border: var(--status-atrisk-border);
}

.toast.error {
    --toast-status-tint: var(--status-offtrack-tint);
    --toast-status-border: var(--status-offtrack-border);
}

.toast.danger {
    --toast-status-tint: var(--status-offtrack-tint);
    --toast-status-border: var(--status-offtrack-border);
}

.toast[data-shd-zabbix-severity="0"],
.toast[data-shd-zabbix-severity="1"],
.toast[data-shd-zabbix-severity="2"],
.toast[data-shd-zabbix-severity="3"],
.toast[data-shd-zabbix-severity="4"],
.toast[data-shd-zabbix-severity="5"] {
    --toast-status-border: var(--shd-zabbix-severity-0);
    --toast-status-tint: var(--shd-zabbix-severity-0);
}

.toast[data-shd-zabbix-severity="1"] { --toast-status-border: var(--shd-zabbix-severity-1); --toast-status-tint: var(--shd-zabbix-severity-1); }
.toast[data-shd-zabbix-severity="2"] { --toast-status-border: var(--shd-zabbix-severity-2); --toast-status-tint: var(--shd-zabbix-severity-2); }
.toast[data-shd-zabbix-severity="3"] { --toast-status-border: var(--shd-zabbix-severity-3); --toast-status-tint: var(--shd-zabbix-severity-3); }
.toast[data-shd-zabbix-severity="4"] { --toast-status-border: var(--shd-zabbix-severity-4); --toast-status-tint: var(--shd-zabbix-severity-4); }
.toast[data-shd-zabbix-severity="5"] { --toast-status-border: var(--shd-zabbix-severity-5); --toast-status-tint: var(--shd-zabbix-severity-5); }

/* ─── State & animations ─────────────────────────────────────────────────── */

@keyframes toast-enter {
    from {
        opacity: 0;
        transform: translateX(-12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.toast.leaving {
    opacity: 0;
    transform: translateX(24px) scale(0.96) !important;
    animation: none;
    pointer-events: none;
}

.toast.dragging {
    transition: none;
    animation: none;
}


/* ─── Icon ───────────────────────────────────────────────────────────────── */

.toast-icon,
.toast-content {
    position: relative;
    z-index: 1;
}

.toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 0px;
    padding: 0;
    border: 0;
    background: transparent;
    /* icon: vivid accent — brighter than border for contrast on dark bg */
    color: color-mix(in srgb, var(--toast-status-border) 60%, #fff 40%);
    cursor: copy;
    transition: color 0.15s ease, opacity 0.15s ease;
}

.toast-icon:hover {
    color: #fff;
    opacity: 0.85;
}

.toast-icon svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.65;
}

/* ─── Content ────────────────────────────────────────────────────────────── */

.toast-content {
    display: grid;
    gap: 5px;
    min-width: 0;
    padding-top: 1px;
}

/* ─── Progress bar ───────────────────────────────────────────────────────── */

.toast-progress {
    position: absolute;
    z-index: 2;
    right: 0;
    bottom: 0;
    left: 0;
    height: 2px;
    overflow: hidden;
    pointer-events: none;
}

.toast-progress::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--toast-status-border) 0%, color-mix(in srgb, var(--toast-status-border) 60%, #fff 40%) 100%);
    opacity: 0.7;
    transform: scaleX(1);
    transform-origin: left center;
}

.toast-progress.running::after {
    animation: toast-countdown var(--toast-duration) linear forwards;
}

.toast.paused .toast-progress.running::after {
    animation-play-state: paused;
}

@keyframes toast-countdown {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ─── Message row ────────────────────────────────────────────────────────── */

.toast-message-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.toast-message {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--toast-fg);
    font: inherit;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* count badge */
.toast-count {
    flex: 0 0 auto;
    min-width: 1.5em;
    margin-left: auto;
    padding: 1px 5px;
    border: 1px solid color-mix(in srgb, var(--toast-status-border) 55%, transparent 45%);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.07);
    color: color-mix(in srgb, var(--toast-status-border) 60%, #fff 40%);
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
}

/* ─── Action button ──────────────────────────────────────────────────────── */

.toast-action {
    justify-self: start;
    padding: 4px 8px;
    border: 1px solid var(--toast-action-border);
    border-radius: 6px;
    background: var(--toast-action-bg);
    color: var(--toast-fg);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.toast-action:hover {
    border-color: var(--toast-status-border);
    background: var(--toast-action-hover);
}

/* ─── Focus ring ─────────────────────────────────────────────────────────── */

.toast:focus-visible,
.toast-action:focus-visible,
.toast-icon:focus-visible {
    outline: 2px solid var(--app-focus-border, currentColor);
    outline-offset: 2px;
}

/* ─── Rich message structures ────────────────────────────────────────────── */

/* Status block */
.toast-message .toast-status-block {
    display: grid;
    gap: 3px;
}

.toast-message .toast-status-badge {
    width: max-content;
    padding: 2px 5px;
    border-radius: 4px;
    background: color-mix(in srgb, var(--toast-status-tint) 80%, var(--toast-status-border) 20%);
    color: var(--toast-fg-soft);
    font-size: 11px;
    line-height: 1.2;
}

.toast-message .toast-status-name {
    color: var(--toast-fg);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.toast-message .toast-status-meta {
    color: var(--toast-fg-soft);
    font-size: 11px;
    line-height: 1.3;
}

/* Notification block */
.toast-message .toast-notification {
    display: grid;
    gap: 3px;
    min-width: 0;
    white-space: normal;
}

.toast-message .toast-notification-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.toast-message .toast-notification-title {
    min-width: 0;
    color: var(--toast-fg);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.toast-message .toast-notification-time {
    flex: 0 0 auto;
    color: var(--toast-fg-soft);
    font-size: 11px;
    line-height: 1.2;
}

.toast-message .toast-notification-body {
    color: var(--toast-fg);
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.toast-message .toast-notification-context {
    color: var(--toast-fg-soft);
    font-size: 11px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
    .toast-container {
        left: max(8px, env(safe-area-inset-left));
        right: max(8px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
        width: auto;
    }
}

/* ─── Reduced motion ─────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .toast,
    .toast-action {
        transition: none;
        animation: none;
    }

    .toast.leaving {
        transform: none;
    }

    .toast-progress.running::after {
        animation: none;
    }
}

/* ─── Legacy element hide ────────────────────────────────────────────────── */

#notification {
    display: none;
}
