/* ============================================
   Reimagined Alert System
   Two bespoke themes (admin + user)
   Responsive down to sub-360px
   ============================================ */

:root {
    --alert-radius: 18px;
    --alert-shadow: 0 24px 80px rgba(12, 20, 33, 0.35);
    --alert-border: rgba(255, 255, 255, 0.08);
    --alert-backdrop: rgba(7, 12, 22, 0.58);
    --text-primary: #0f172a;
    --text-secondary: #1f2937;
    --text-muted: #4b5563;
    --surface: #0b1220;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Base layout */
.app-alert {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(10px, 2vw, 28px);
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.app-alert.is-visible {
    opacity: 1;
}

.app-alert.hiding {
    opacity: 0;
}

.app-alert-overlay {
    position: fixed;
    inset: 0;
    background: var(--alert-backdrop);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1;
}

.app-alert-container {
    position: relative;
    width: min(540px, 100%);
    z-index: 2;
    display: flex;
    justify-content: center;
}

.app-alert-content {
    width: 100%;
    background: linear-gradient(140deg, rgba(255, 255, 255, 0.98), rgba(249, 251, 255, 0.96));
    border-radius: var(--alert-radius);
    border: 1px solid var(--alert-border);
    box-shadow: var(--alert-shadow);
    padding: clamp(20px, 3vw, 32px);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.app-alert[data-theme="admin"] .app-alert-content {
    background: radial-gradient(circle at 20% 20%, rgba(46, 67, 101, 0.35), transparent 40%), linear-gradient(150deg, #0e1829, #0a101c);
    border: 1px solid rgba(71, 85, 105, 0.4);
    color: #e7ecf6;
}

.app-alert[data-theme="user"] .app-alert-content {
    background: radial-gradient(circle at 12% 18%, rgba(46, 160, 110, 0.14), transparent 40%), linear-gradient(160deg, #ffffff, #f8fafc);
    border: 1px solid rgba(28, 125, 76, 0.14);
    color: var(--text-primary);
}

/* Header */
.app-alert-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    align-items: center;
}

.app-alert-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-alert-icon {
    width: clamp(60px, 10vw, 78px);
    height: clamp(60px, 10vw, 78px);
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    position: relative;
    isolation: isolate;
}

.app-alert-icon::after {
    content: "";
    position: absolute;
    inset: -14%;
    border-radius: 22px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent);
    z-index: -1;
}

.app-alert-icon i {
    font-size: clamp(28px, 5vw, 38px);
}

.app-alert-titles {
    min-width: 0;
}

.app-alert-context {
    margin: 0 0 4px;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
}

.app-alert[data-theme="user"] .app-alert-context {
    color: #0f5132;
}

.app-alert-title {
    margin: 0;
    font-size: clamp(20px, 3vw, 26px);
    font-weight: 800;
    line-height: 1.25;
    color: currentColor;
}

.app-alert-message {
    margin: 6px 0 0;
    font-size: clamp(14px, 2.7vw, 16px);
    line-height: 1.6;
    color: rgba(231, 236, 246, 0.92);
}

.app-alert[data-theme="user"] .app-alert-message {
    color: var(--text-secondary);
}

/* Details */
.app-alert-details {
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.08);
    border: 1px dashed rgba(255, 255, 255, 0.2);
}

.app-alert[data-theme="user"] .app-alert-details {
    background: rgba(23, 145, 0, 0.08);
    border-color: rgba(23, 145, 0, 0.25);
    color: #0f5132;
}

.alert-details-list {
    margin: 0;
    padding-left: 18px;
}

.alert-details-list li {
    margin-bottom: 6px;
}

.alert-details-list li:last-child {
    margin-bottom: 0;
}

/* Variants */
.app-alert[data-variant="success"] {
    --accent: #16a34a;
    --accent-strong: #0f5132;
}

.app-alert[data-variant="error"] {
    --accent: #ef4444;
    --accent-strong: #7f1d1d;
}

.app-alert[data-variant="warning"] {
    --accent: #f59e0b;
    --accent-strong: #92400e;
}

.app-alert[data-variant="info"],
.app-alert[data-variant="system"],
.app-alert[data-variant="confirmation"] {
    --accent: #2563eb;
    --accent-strong: #0f2f75;
}

.app-alert[data-theme="admin"] .app-alert-icon {
    background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.09), transparent 50%), linear-gradient(160deg, var(--accent, #2563eb), var(--accent-strong, #0f2f75));
}

.app-alert[data-theme="user"] .app-alert-icon {
    background: radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.22), transparent 55%), linear-gradient(160deg, var(--accent, #179100), #0f5132);
}

.app-alert[data-theme="user"][data-variant="info"] .app-alert-icon {
    background: linear-gradient(160deg, #1d4ed8, #0f3a8a);
}

.app-alert[data-theme="user"][data-variant="warning"] .app-alert-icon {
    background: linear-gradient(160deg, #f59e0b, #b45309);
}

.app-alert[data-theme="user"][data-variant="error"] .app-alert-icon {
    background: linear-gradient(160deg, #ef4444, #b91c1c);
}

.app-alert[data-theme="user"][data-variant="success"] .app-alert-icon {
    background: linear-gradient(160deg, #16a34a, #0f5132);
}

/* Actions */
.app-alert-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.app-alert-button {
    flex: 1 1 180px;
    min-width: 140px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
}

.app-alert[data-theme="user"] .app-alert-button {
    border-color: rgba(15, 81, 50, 0.25);
    background: #f5f8f4;
    color: #0f172a;
}

.app-alert-button-primary {
    background: linear-gradient(135deg, var(--accent, #179100), var(--accent-strong, #0f5132));
    color: #fff;
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
}

.app-alert[data-theme="user"] .app-alert-button-primary {
    box-shadow: 0 14px 32px rgba(15, 81, 50, 0.25);
}

.app-alert-button-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
}

.app-alert[data-theme="user"] .app-alert-button-secondary {
    background: #ffffff;
    color: #0f172a;
}

.app-alert-button:hover {
    transform: translateY(-1px);
}

.app-alert-button:focus-visible {
    outline: 3px solid var(--accent, #2563eb);
    outline-offset: 2px;
}

/* Close */
.app-alert-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.app-alert[data-theme="user"] .app-alert-close {
    background: #ffffff;
    border-color: rgba(15, 81, 50, 0.2);
    color: #0f172a;
}

.app-alert-close:hover {
    transform: translateY(-1px) scale(1.02);
    background: rgba(255, 255, 255, 0.22);
}

.app-alert-close:focus-visible {
    outline: 3px solid var(--accent, #2563eb);
    outline-offset: 2px;
}

/* Inline form alerts */
.inline-form-alert {
    position: fixed;
    inset: auto 50% 20px 50%;
    transform: translate(-50%, 0);
    z-index: 9999;
    width: min(520px, calc(100% - 20px));
    animation: slideDownInline 0.3s ease;
}

.inline-form-alert-content {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 14px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.16);
}

.inline-form-alert-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: #2563eb;
    color: #fff;
    font-size: 18px;
}

.inline-form-alert-message {
    font-size: 14px;
    color: #1f2937;
    margin: 0;
    line-height: 1.5;
}

.inline-form-alert-close {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 8px;
    background: #f3f4f6;
    cursor: pointer;
    color: #111827;
}

.inline-form-alert.success .inline-form-alert-content {
    border-color: rgba(22, 163, 74, 0.25);
    background: #f0fdf4;
}

.inline-form-alert.error .inline-form-alert-content {
    border-color: rgba(239, 68, 68, 0.25);
    background: #fef2f2;
}

.inline-form-alert.warning .inline-form-alert-content {
    border-color: rgba(245, 158, 11, 0.25);
    background: #fffbeb;
}

.inline-form-alert.info .inline-form-alert-content {
    border-color: rgba(37, 99, 235, 0.25);
    background: #eff6ff;
}

/* Animations */
@keyframes slideDownInline {
    from {
        opacity: 0;
        transform: translate(-50%, -8px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.app-alert.loading .app-alert-icon i {
    animation: spin 1s linear infinite;
}

/* Responsive */
@media (max-width: 768px) {
    .app-alert {
        padding: 12px;
    }
    .app-alert-actions {
        flex-direction: column;
    }
    .app-alert-button {
        width: 100%;
        flex: 1;
    }
    .app-alert-header {
        grid-template-columns: 1fr;
        text-align: left;
    }
    .app-alert-icon {
        width: 64px;
        height: 64px;
        margin-bottom: 6px;
    }
    .app-alert-close {
        top: 10px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    .app-alert {
        padding: 8px;
    }
    .app-alert-content {
        padding: 18px 16px 16px;
        border-radius: 14px;
    }
    .app-alert-title {
        font-size: 18px;
    }
    .app-alert-message {
        font-size: 13.5px;
    }
    .app-alert-button {
        min-width: 0;
        padding: 12px 14px;
    }
    .inline-form-alert {
        inset: auto 8px 14px 8px;
        transform: none;
        width: auto;
    }
}

@media (max-width: 360px) {
    .app-alert {
        padding: 6px;
    }
    .app-alert-content {
        padding: 16px 14px 14px;
    }
    .app-alert-title {
        font-size: 17px;
    }
    .app-alert-message {
        font-size: 13px;
    }
    .app-alert-icon {
        width: 56px;
        height: 56px;
    }
}

/* High contrast */
@media (prefers-contrast: high) {
    .app-alert-content {
        border-width: 2px;
    }
    .app-alert-button,
    .app-alert-close {
        outline: 2px solid currentColor;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .app-alert,
    .app-alert-overlay,
    .app-alert-content,
    .app-alert-button,
    .app-alert-close {
        animation: none !important;
        transition: none !important;
    }
}
