/**
 * Toasts cápsula (iOS): píldora, icono circular pastel, título + texto.
 * Posición: arriba a la derecha.
 * Clases: .toast-container, .toast-item, #toast.toast
 */

.toast-container,
#toast-container {
    position: fixed;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    bottom: auto !important;
    transform: none !important;
    z-index: 999999 !important;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    width: min(calc(100vw - 24px), 360px) !important;
    max-width: min(calc(100vw - 24px), 360px) !important;
    box-sizing: border-box;
}

/* DOM legado: los toasts reales van a #toast-container */
#toast.toast:not(.toast-item),
.lp-toast {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.toast-item,
#toast.toast,
.toast.toast-item,
.e1-page .toast,
.ev-page .toast {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 12px !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 8px 18px 8px 8px !important;
    border-radius: 999px !important;
    border: 1px solid rgba(60, 60, 67, 0.08) !important;
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(22px) saturate(180%);
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    box-shadow:
        0 10px 28px -8px rgba(15, 23, 42, 0.14),
        0 2px 8px -2px rgba(15, 23, 42, 0.06) !important;
    color: var(--app-text, #1c1c1e) !important;
    font-weight: 400 !important;
    font-size: 14px !important;
    text-align: left !important;
    line-height: 1.25 !important;
    box-sizing: border-box !important;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
    transition: opacity 0.28s ease, transform 0.28s ease;
    z-index: 999999 !important;
}

#toast.toast,
.e1-page #toast.toast,
.ev-page .toast {
    position: fixed !important;
    right: max(12px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    top: max(12px, env(safe-area-inset-top, 0px)) !important;
    bottom: auto !important;
    transform: translateY(-8px) scale(0.98) !important;
    width: min(calc(100vw - 24px), 360px) !important;
}

.toast-item.toast-show,
#toast.toast.show,
.toast.show {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
}

#toast.toast.show,
.ev-page .toast.show,
.e1-page .toast.show {
    transform: translateY(0) scale(1) !important;
}

.toast-item.toast-hide {
    opacity: 0 !important;
    transform: translateY(-8px) scale(0.98) !important;
}

.toast-item::before,
#toast.toast::before {
    display: none !important;
    content: none !important;
}

.toast-icon,
.toast-ico {
    flex-shrink: 0 !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    margin: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 17px !important;
    line-height: 1 !important;
    box-shadow: none !important;
    color: inherit !important;
    background: #f2f2f7 !important;
}

.toast-icon svg,
.toast-ico svg {
    width: 18px !important;
    height: 18px !important;
    display: block !important;
    stroke: currentColor;
}

.toast-icon i,
.toast-icon .bi,
.toast-ico i,
.toast-ico .bi {
    font-size: 17px !important;
    line-height: 1 !important;
    color: inherit !important;
    font-weight: 400 !important;
}

.toast-content,
.toast-body {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    gap: 2px !important;
    padding: 0 !important;
    background: transparent !important;
}

.toast-title {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    letter-spacing: -0.02em !important;
    line-height: 1.25 !important;
    color: #1c1c1e !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.toast-message,
.toast-msg {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12px !important;
    font-weight: 400 !important;
    line-height: 1.35 !important;
    color: #8e8e93 !important;
    opacity: 1 !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.toast-message:empty,
.toast-msg:empty {
    display: none !important;
}

.toast-close,
.toast-progress {
    display: none !important;
}

/* Tonos de icono (círculo pastel + trazo) */
.toast-item.toast-success .toast-icon,
.toast.ok .toast-ico,
.toast.ok .toast-icon {
    background: #e8f8ee !important;
    color: #248a3d !important;
}

.toast-item.toast-warning .toast-icon,
.toast.warn .toast-ico,
.toast.warn .toast-icon {
    background: #fff1e6 !important;
    color: #c93400 !important;
}

.toast-item.toast-error .toast-icon,
.toast-item.toast-delete .toast-icon,
.toast.err .toast-ico,
.toast.err .toast-icon {
    background: #ffe9e9 !important;
    color: #d70015 !important;
}

.toast-item.toast-neutral-blue .toast-icon,
.toast-item.toast-info .toast-icon {
    background: #e8f1ff !important;
    color: #0b57d0 !important;
}

.toast-item.toast-neutral .toast-icon {
    background: #f0e8ff !important;
    color: #5e5ce6 !important;
}

html[data-theme="dark"] .toast-item,
html[data-theme="dark"] #toast.toast,
html[data-theme="dark"] .e1-page .toast,
html[data-theme="dark"] .ev-page .toast {
    background: rgba(44, 44, 46, 0.92) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow:
        0 12px 32px -8px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.3) !important;
    color: #ffffff !important;
}

html[data-theme="dark"] .toast-title {
    color: #ffffff !important;
}

html[data-theme="dark"] .toast-icon,
html[data-theme="dark"] .toast-ico {
    background: rgba(255, 255, 255, 0.08) !important;
}

html[data-theme="dark"] .toast-message,
html[data-theme="dark"] .toast-msg {
    color: rgba(255, 255, 255, 0.62) !important;
}

html[data-theme="dark"] .toast-item.toast-success .toast-icon,
html[data-theme="dark"] .toast.ok .toast-ico {
    background: rgba(52, 199, 89, 0.18) !important;
    color: #30d158 !important;
}

html[data-theme="dark"] .toast-item.toast-warning .toast-icon,
html[data-theme="dark"] .toast.warn .toast-ico {
    background: rgba(255, 159, 10, 0.18) !important;
    color: #ffd60a !important;
}

html[data-theme="dark"] .toast-item.toast-error .toast-icon,
html[data-theme="dark"] .toast-item.toast-delete .toast-icon,
html[data-theme="dark"] .toast.err .toast-ico {
    background: rgba(255, 69, 58, 0.18) !important;
    color: #ff6b6b !important;
}

html[data-theme="dark"] .toast-item.toast-neutral-blue .toast-icon,
html[data-theme="dark"] .toast-item.toast-info .toast-icon {
    background: rgba(10, 132, 255, 0.2) !important;
    color: #64d2ff !important;
}

html[data-theme="dark"] .toast-item.toast-neutral .toast-icon {
    background: rgba(191, 90, 242, 0.2) !important;
    color: #bf5af2 !important;
}

@media (max-width: 768px) {
    .toast-container,
    #toast-container {
        top: max(10px, env(safe-area-inset-top, 0px));
        right: max(10px, env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
        width: min(calc(100vw - 20px), 340px) !important;
        max-width: min(calc(100vw - 20px), 340px) !important;
        transform: none !important;
    }
}
