/* ===== UI System — Toast, Loading, Transitions ===== */

/* ---------- Toast Notifications ---------- */
.toast-container {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 380px;
    width: 100%;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.45;
    box-shadow: 0 8px 32px rgba(15, 23, 42, .16), 0 2px 8px rgba(15, 23, 42, .08);
    border: 1px solid var(--border);
    pointer-events: all;
    transform: translateX(120%);
    opacity: 0;
    transition: transform .35s cubic-bezier(.4, 0, .2, 1), opacity .35s ease;
    position: relative;
    overflow: hidden;
}
.toast.show {
    transform: translateX(0);
    opacity: 1;
}
.toast.hide {
    transform: translateX(120%);
    opacity: 0;
}

/* Progress bar at bottom */
.toast::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: .3;
    animation: toast-progress linear forwards;
    width: 100%;
    transform-origin: left;
}

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

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-top: 1px;
}

.toast-content { flex: 1; min-width: 0; }
.toast-title {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 2px;
}
.toast-message {
    color: var(--text-muted);
    font-size: 12px;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-faint);
    padding: 2px;
    font-size: 16px;
    line-height: 1;
    transition: color .15s;
}
.toast-close:hover { color: var(--text); }

/* Toast variants */
.toast-success { border-left: 4px solid var(--success); color: var(--success); }
.toast-success .toast-title { color: var(--success); }

.toast-error { border-left: 4px solid var(--danger); color: var(--danger); }
.toast-error .toast-title { color: var(--danger); }

.toast-warning { border-left: 4px solid var(--warning); color: var(--warning); }
.toast-warning .toast-title { color: var(--warning); }

.toast-info { border-left: 4px solid var(--brand); color: var(--brand); }
.toast-info .toast-title { color: var(--brand); }

/* ---------- Button Loading State ---------- */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btn-spin .6s linear infinite;
}
.btn-secondary.loading::after,
.btn:not(.btn-primary):not(.btn-danger).loading::after {
    border-color: rgba(67, 97, 238, .2);
    border-top-color: var(--brand);
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Skeleton Loader ---------- */
.skeleton {
    background: linear-gradient(90deg,
        var(--border-light) 25%,
        var(--bg) 50%,
        var(--border-light) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------- Page Transition ---------- */
.container {
    animation: page-enter .3s ease-out;
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- Enhanced Form Focus ---------- */
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-glow);
    transform: translateY(-1px);
}

/* ---------- Table Row Click Effect ---------- */
.table tbody tr {
    cursor: pointer;
    transition: background .12s, transform .1s;
}
.table tbody tr:active {
    transform: scale(.995);
}

/* ---------- Card Hover ---------- */
.form-card {
    transition: box-shadow .2s, transform .15s;
}
.form-card:hover {
    box-shadow: var(--shadow-lg);
}

/* ---------- Photo Upload Progress ---------- */
.upload-progress-ring {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}
.upload-progress-ring .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: btn-spin .6s linear infinite;
}

/* ---------- Empty State Enhanced ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.empty-state-icon {
    font-size: 48px;
    opacity: .3;
    margin-bottom: 8px;
}

/* ---------- Tooltip ---------- */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(.9);
    padding: 5px 10px;
    border-radius: 6px;
    background: #0f172a;
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s, transform .15s;
    z-index: 50;
}
[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ---------- Badge Pulse (new items) ---------- */
.badge-pulse {
    animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(67, 97, 238, .4); }
    70% { box-shadow: 0 0 0 6px rgba(67, 97, 238, 0); }
    100% { box-shadow: 0 0 0 0 rgba(67, 97, 238, 0); }
}

/* ---------- Mobile Toast ---------- */
@media (max-width: 480px) {
    .toast-container {
        right: 8px;
        left: 8px;
        max-width: unset;
    }
}

/* ---------- Photo Upload Components ---------- */
.defect-photo-btn {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px dashed var(--border);
    color: var(--brand);
    font-size: 14px;
    opacity: .7;
    flex-shrink: 0;
    transition: opacity .2s, border-color .2s, transform .15s;
}
.defect-photo-btn:hover {
    opacity: 1;
    border-color: var(--brand);
    transform: scale(1.1);
}
.defect-photo-btn.uploading { opacity: .4; pointer-events: none; }

.defect-photos-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 12px 10px;
}

.defect-photo-thumb {
    width: 80px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    display: block;
}
.defect-photo-thumb:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}

.photo-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.photo-delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid var(--surface);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 1;
    transition: transform .1s, background .15s;
}
.photo-delete-btn:hover {
    background: #b91c1c;
    transform: scale(1.15);
}
.photo-wrap:hover .photo-delete-btn { display: flex; }

.photo-filename-label {
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 8px;
    border: 1px dashed var(--border);
    border-radius: 4px;
    align-self: center;
}

.photo-cloud-link {
    font-size: 12px;
    color: var(--brand);
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    align-self: center;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    transition: background .15s;
}
.photo-cloud-link:hover { background: var(--bg); text-decoration: none; }

.qr-card { text-align: center; padding: 24px; }
.qr-card img { border-radius: 8px; border: 1px solid var(--border); }

/* Photo upload status indicators */
.photo-wrap[data-upload-status="pending"]::after,
.photo-wrap[data-upload-status="uploading"]::after {
    content: '⏳';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 11px;
    line-height: 1;
    background: rgba(255, 255, 255, .85);
    border-radius: 3px;
    padding: 1px 3px;
    pointer-events: none;
}
.photo-wrap[data-upload-status="uploading"]::after {
    animation: pulse-ring 1.5s ease-in-out infinite;
}
.photo-wrap[data-upload-status="failed"]::after {
    content: '✗';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 12px;
    line-height: 1;
    color: var(--danger);
    font-weight: bold;
    background: rgba(255, 255, 255, .85);
    border-radius: 3px;
    padding: 1px 3px;
    pointer-events: none;
}

/* ---------- Dark Theme Overrides ---------- */
[data-theme="dark"] .toast {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .4);
}
[data-theme="dark"] .toast-close { color: #64748b; }
[data-theme="dark"] .toast-close:hover { color: #e2e8f0; }
[data-theme="dark"] .toast-message { color: #94a3b8; }
[data-theme="dark"] [data-tooltip]::before { background: #e2e8f0; color: #0f172a; }
