/**
 * 🏛️ MoR EIMS Enterprise Fiscal Toast Notification System
 * Directive 1142/2018 E.C., MoR Technical Specification & INSA PKI Standards
 *
 * Micro-interactions, Calming Failure UX, Glassmorphism, Dual-Language (EN/AM)
 */

/* Container */
#fiscal-toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 2147483647 !important;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 460px;
    width: calc(100vw - 32px);
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@keyframes fiscalToastSlideIn {
    0% {
        transform: translateX(110%) scale(0.95);
        opacity: 0;
    }
    100% {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

/* Base Card */
.fiscal-toast {
    position: relative;
    pointer-events: auto;
    border-radius: 16px;
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.18),
                0 0 0 1px rgba(226, 232, 240, 0.9),
                0 4px 6px -2px rgba(15, 23, 42, 0.05);
    overflow: hidden;
    animation: fiscalToastSlideIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform: translateX(0) scale(1);
    opacity: 1;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.35s ease-out,
                box-shadow 0.2s ease;
}

.fiscal-toast.show {
    transform: translateX(0) scale(1) !important;
    opacity: 1 !important;
}

.fiscal-toast.hide,
.fiscal-toast.fiscal-toast-leaving {
    transform: translateX(110%) scale(0.92) !important;
    opacity: 0 !important;
}

.fiscal-toast:hover {
    box-shadow: 0 24px 48px -10px rgba(15, 23, 42, 0.22),
                0 0 0 1px rgba(203, 213, 225, 0.9);
}

/* ── Status Variant: SUCCESS ── */
.fiscal-toast.toast-success,
.fiscal-toast.fiscal-toast-success {
    border-left: 6px solid #10b981;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(240, 253, 244, 0.95) 100%);
}

.fiscal-toast.toast-success .toast-icon-wrapper {
    background: #dcfce7;
    color: #10b981;
    border: 1px solid #bbf7d0;
}

.fiscal-toast.toast-success .toast-status-badge {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

/* ── Status Variant: FAILED (User-Calming UX) ── */
/* Calm, non-threatening rose & crimson tones instead of aggressive neon red */
.fiscal-toast.toast-failed {
    border-left: 6px solid #e11d48;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.99) 0%, rgba(255, 241, 242, 0.95) 100%);
}

.fiscal-toast.toast-failed .toast-icon-wrapper {
    background: #ffe4e6;
    color: #e11d48;
    border: 1px solid #fecdd3;
    animation: calming-pulse 3s infinite ease-in-out;
}

.fiscal-toast.toast-failed .toast-status-badge {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* ── Status Variant: WARNING / OFFLINE WORM QUEUE ── */
.fiscal-toast.toast-warning {
    border-left: 6px solid #f59e0b;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(254, 243, 199, 0.92) 100%);
}

.fiscal-toast.toast-warning .toast-icon-wrapper {
    background: #fef3c7;
    color: #d97706;
    border: 1px solid #fde68a;
}

.fiscal-toast.toast-warning .toast-status-badge {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Header & Flex Layout */
.fiscal-toast-body {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.toast-icon-wrapper {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.toast-content-wrapper {
    flex: 1;
    min-width: 0;
}

/* Top Meta Row (Status Code Badges + Time) */
.toast-meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
    flex-wrap: wrap;
}

.toast-status-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.toast-http-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.toast-mor-code-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 9999px;
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.toast-time-text {
    margin-left: auto;
    font-size: 0.72rem;
    color: #94a3b8;
    font-weight: 500;
}

/* Title & Description */
.toast-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #0f172a;
    line-height: 1.35;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toast-title-amharic {
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 4px;
}

.toast-message {
    font-size: 0.84rem;
    color: #475569;
    line-height: 1.45;
    margin-bottom: 8px;
    word-break: break-word;
}

/* ── Interactive IRN / Document Identifier Pill ── */
.toast-irn-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.76rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: #1e293b;
    margin-top: 4px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: all;
    max-width: 100%;
}

.toast-irn-pill:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}

.toast-irn-pill .copy-icon {
    font-size: 0.78rem;
    color: #64748b;
    transition: color 0.15s ease, transform 0.15s ease;
}

.toast-irn-pill:hover .copy-icon {
    color: #2563eb;
    transform: scale(1.1);
}

.toast-irn-pill.copied {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}

.toast-irn-pill.copied .copy-icon {
    color: #10b981;
}

/* ── Diagnostic Breakdown Box (Calming Failure) ── */
.toast-diagnosis-box {
    margin-top: 8px;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid #fecdd3;
    border-radius: 10px;
    font-size: 0.78rem;
    box-shadow: 0 2px 4px rgba(225, 29, 72, 0.03);
}

.toast-cause-header {
    font-weight: 700;
    color: #9f1239;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.toast-cause-desc {
    color: #475569;
    line-height: 1.4;
    margin-bottom: 6px;
}

.toast-remediation-box {
    background: #f0fdf4;
    border-left: 3px solid #22c55e;
    padding: 6px 10px;
    border-radius: 4px 6px 6px 4px;
    color: #166534;
    font-size: 0.76rem;
    line-height: 1.4;
}

.toast-remediation-title {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 1px;
}

/* Interactive Action Buttons inside Toast */
.toast-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.toast-btn {
    border: none;
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s ease;
    text-decoration: none;
}

.toast-btn-primary {
    background: #10b981;
    color: #ffffff;
}

.toast-btn-primary:hover {
    background: #059669;
}

.toast-btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.toast-btn-secondary:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.toast-btn-danger-outline {
    background: transparent;
    color: #e11d48;
    border: 1px solid #fecdd3;
}

.toast-btn-danger-outline:hover {
    background: #ffe4e6;
}

/* Close Button */
.toast-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.15s ease;
}

.toast-close-btn:hover {
    background: #f1f5f9;
    color: #334155;
}

/* Progress Countdown Bar */
.toast-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #cbd5e1;
    width: 100%;
    transform-origin: left;
    transition: transform linear;
}

.toast-success .toast-progress-bar {
    background: linear-gradient(90deg, #10b981, #059669);
}

.toast-failed .toast-progress-bar {
    background: linear-gradient(90deg, #f43f5e, #e11d48);
}

.toast-warning .toast-progress-bar {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

/* ── SVG Animated Checkmark Stroke ── */
.svg-checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2.5;
    stroke-miterlimit: 10;
    stroke: #10b981;
    fill: none;
    animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.svg-checkmark-check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke-width: 3;
    stroke: #10b981;
    fill: none;
    animation: stroke 0.4s cubic-bezier(0.65, 0, 0.45, 1) 0.3s forwards;
}

@keyframes stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

@keyframes calming-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.2);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(225, 29, 72, 0);
    }
}

/* ── Von Restorff Error Field Isolation (Directive 1142 Rules 7008, 7006, 7021, 7030) ── */
.fiscal-isolate-pulsing-ring {
    border-color: #ef4444 !important;
    outline: none !important;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.35), 0 0 14px rgba(239, 68, 68, 0.4) !important;
    animation: fiscal-pulse-ring 1.4s cubic-bezier(0.4, 0, 0.6, 1) infinite !important;
    transition: box-shadow 0.2s ease, border-color 0.2s ease !important;
}

@keyframes fiscal-pulse-ring {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.4), 0 0 12px rgba(239, 68, 68, 0.3);
    }
    50% {
        box-shadow: 0 0 0 7px rgba(239, 68, 68, 0.18), 0 0 22px rgba(239, 68, 68, 0.55);
    }
}

/* Responsive adjustment */
@media (max-width: 576px) {
    #fiscal-toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
        width: auto;
    }
    .fiscal-toast {
        padding: 12px 14px;
    }
}

/* ── Specific .fiscal-toast-* Element Rules ── */
.fiscal-toast-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.fiscal-toast-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.fiscal-toast-icon-wrapper {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.fiscal-toast-icon-error {
    background: #ffe4e6;
    color: #e11d48;
    border: 1px solid #fecdd3;
}

.fiscal-toast-alert-svg {
    width: 22px !important;
    height: 22px !important;
    max-width: 22px !important;
    max-height: 22px !important;
    min-width: 22px !important;
    min-height: 22px !important;
    stroke: #e11d48 !important;
    display: block !important;
}

.fiscal-toast-titles {
    flex: 1;
    min-width: 0;
    padding-right: 18px;
}

.fiscal-toast-tag-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 5px;
}

.fiscal-toast-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
}

.fiscal-toast-badge-status {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.fiscal-toast-badge-mor {
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.fiscal-toast-badge-light {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.fiscal-toast-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 2px 0;
    line-height: 1.3;
}

.fiscal-toast-title-error {
    color: #991b1b;
}

.fiscal-toast-amharic-sub {
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    margin: 0;
    line-height: 1.35;
}

.fiscal-toast-calming-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 0.75rem;
    color: #1e40af;
    line-height: 1.4;
}

.fiscal-toast-calming-icon {
    font-size: 1rem;
    flex-shrink: 0;
    line-height: 1.2;
}

.fiscal-toast-cause-box {
    background: #fff5f5;
    border: 1px solid #fecdd3;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 0.75rem;
}

.fiscal-toast-cause-header {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    color: #9f1239;
    margin-bottom: 4px;
}

.fiscal-toast-cause-desc {
    margin: 0 0 3px 0;
    color: #475569;
    line-height: 1.4;
}

.fiscal-toast-cause-am {
    margin: 0;
    color: #64748b;
    font-size: 0.73rem;
    line-height: 1.35;
}

.fiscal-toast-fix-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-left: 3px solid #16a34a;
    border-radius: 4px 8px 8px 4px;
    padding: 8px 11px;
    font-size: 0.75rem;
}

.fiscal-toast-fix-header {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    color: #166534;
    margin-bottom: 3px;
}

.fiscal-toast-fix-text {
    margin: 0;
    color: #15803d;
    line-height: 1.4;
}

.fiscal-toast-actions-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.fiscal-toast-copy-diag-btn {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #475569;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.15s ease;
}

.fiscal-toast-copy-diag-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.fiscal-toast-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.fiscal-toast-close:hover {
    background: #f1f5f9;
    color: #334155;
}
