/**
 * UI Enhancements - IRO WCH
 * Toast notifications, skeleton loaders, animations, and visual improvements
 */

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.2), 0 4px 6px -4px rgb(0 0 0 / 0.2);
    padding: 16px;
    min-width: 320px;
    max-width: 400px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
    overflow: hidden;
    pointer-events: auto;
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast-show {
    transform: translateX(0);
    opacity: 1;
}

.toast-hide {
    transform: translateX(400px);
    opacity: 0;
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-message {
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.toast-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: currentColor;
    opacity: 0.3;
    transform-origin: left;
    animation: toast-progress linear forwards;
}

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

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

.toast-success .toast-icon {
    color: var(--success-color);
}

.toast-success .toast-progress {
    background: var(--success-color);
}

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

.toast-error .toast-icon {
    color: var(--error-color);
}

.toast-error .toast-progress {
    background: var(--error-color);
}

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

.toast-warning .toast-icon {
    color: var(--warning-color);
}

.toast-warning .toast-progress {
    background: var(--warning-color);
}

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

.toast-info .toast-icon {
    color: var(--primary-color);
}

.toast-info .toast-progress {
    background: var(--primary-color);
}

.toast-loading .toast-icon i {
    animation: spin 1s linear infinite;
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-hover) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

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

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
}

.skeleton-text:last-child {
    width: 80%;
}

.skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-table-row {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-table-cell {
    height: 1rem;
    flex: 1;
    border-radius: var(--radius-sm);
}

/* ============================================
   PODIUM VISUALIZATION
   ============================================ */

.podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    margin: 2rem 0;
}

.podium-place {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: podium-rise 0.6s ease-out backwards;
}

.podium-place.first {
    order: 2;
    animation-delay: 0.2s;
}

.podium-place.second {
    order: 1;
    animation-delay: 0.1s;
}

.podium-place.third {
    order: 3;
    animation-delay: 0s;
}

@keyframes podium-rise {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.podium-medal {
    font-size: 3rem;
    line-height: 1;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    animation: medal-float 3s ease-in-out infinite;
}

/* The metal lives here rather than in the markup, and matches the bar across
   the top of the card below it. */
.podium-place.first .podium-medal {
    animation-delay: 0s;
    color: #e8a90c;
}

.podium-place.second .podium-medal {
    animation-delay: 0.5s;
    color: #a8a8a8;
}

.podium-place.third .podium-medal {
    animation-delay: 1s;
    color: #cd7f32;
}

@keyframes medal-float {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    50% {
        transform: translateY(-10px) rotate(5deg);
    }
}

.podium-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    text-align: center;
    min-width: 200px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.podium-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.podium-place.first .podium-card {
    transform: scale(1.1);
}

.podium-place.first .podium-card::before {
    background: linear-gradient(90deg, #FFD700, #FFA500);
}

.podium-place.second .podium-card::before {
    background: linear-gradient(90deg, #C0C0C0, #A8A8A8);
}

.podium-place.third .podium-card::before {
    background: linear-gradient(90deg, #CD7F32, #B8732D);
}

.podium-card:hover {
    transform: scale(1.05);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.2);
}

.podium-place.first .podium-card:hover {
    transform: scale(1.15);
}

.podium-rank {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    /* Solid navy. This was clipped gradient text, which on a navy-to-sand ramp
       passes through a dead grey in the middle — and the metal colour of the
       place is already carried by the bar across the top of the card. */
    color: var(--primary-color);
}

.podium-competitor {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.podium-dog {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 1rem;
}

/* Second line for a subject that has no dog — a country's competitor count, a
   team's line-up size. Upright and unstyled where .podium-dog is italic, so the
   two never read as the same kind of fact. */
.podium-sub {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.podium-country {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.podium-team {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.podium-score {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.podium-score-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

/* ============================================
   SECTION NAV ("Continue browsing")

   Sits at the foot of every full-results page. Those pages used to end on the
   last table row with no way onward but the back button.
   ============================================ */

.section-nav {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.section-nav-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* auto-fit rather than a fixed column count: the list is as long as the
   category list, which the admin panel can change at any time. */
.section-nav-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.section-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.section-nav-link:hover {
    background: var(--bg-hover);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.section-nav-link > i:first-child {
    font-size: 1.25rem;
    color: var(--primary-color);
    flex: 0 0 auto;
}

.section-nav-link span {
    flex: 1 1 auto;
    overflow-wrap: anywhere;
}

.section-nav-arrow {
    flex: 0 0 auto;
    color: var(--text-muted);
}

@media (max-width: 480px) {
    .section-nav-links {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .section-nav-link {
        transition: none;
    }

    .section-nav-link:hover {
        transform: none;
    }
}

/* ============================================
   PROGRESS BARS
   ============================================ */

.score-progress {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.score-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: 999px;
    transition: width 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
}

.score-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: progress-shine 2s ease-in-out infinite;
}

@keyframes progress-shine {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.score-progress.excellent .score-progress-bar {
    background: linear-gradient(90deg, #1f7a5c, #2f9e74);
}

.score-progress.good .score-progress-bar {
    background: linear-gradient(90deg, #092552, #1d4e8f);
}

.score-progress.fair .score-progress-bar {
    background: linear-gradient(90deg, #b5822a, #d9a441);
}

.score-progress.poor .score-progress-bar {
    background: linear-gradient(90deg, #c2272c, #e5343a);
}

.score-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.score-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.score-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   ENHANCED HOVER EFFECTS
   ============================================ */

.nav-card {
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
}

.nav-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent, rgb(9 37 82 / 0.05));
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: var(--radius-xl);
    pointer-events: none;
}

.nav-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 10px 10px -5px rgb(0 0 0 / 0.08);
}

.nav-card:hover::before {
    opacity: 1;
}

.nav-card:active {
    transform: translateY(-2px) scale(1.01);
}

/* Stat Cards Animation */
.stat-card {
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.stat-number {
    transition: all 0.3s ease;
}

.stat-card:hover .stat-number {
    transform: scale(1.1);
}

/* Button Loading State */
.btn {
    position: relative;
    transition: all 0.2s ease;
}

.btn.loading {
    color: transparent;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
    color: white;
}

.btn-secondary.loading::after {
    color: var(--text-primary);
}

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

/* Pulse Animation for Live Updates */
.pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.pulse-ring {
    position: relative;
}

.pulse-ring::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--primary-color);
    opacity: 0.4;
    transform: translate(-50%, -50%) scale(1);
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.4;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

/* ============================================
   CATEGORY COLOR CODING
   ============================================ */

:root {
    --category-rubble: #059669;
    --category-rubble-light: #10b981;
    --category-area: #2563eb;
    --category-area-light: #3b82f6;
    --category-trace: #d97706;
    --category-trace-light: #f59e0b;
}

.category-indicator {
    width: 4px;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.category-rubble .category-indicator {
    background: linear-gradient(180deg, var(--category-rubble), var(--category-rubble-light));
}

.category-area .category-indicator {
    background: linear-gradient(180deg, var(--category-area), var(--category-area-light));
}

.category-trace .category-indicator {
    background: linear-gradient(180deg, var(--category-trace), var(--category-trace-light));
}

/* Category Badges Enhanced */
.category-badge {
    position: relative;
    overflow: hidden;
}

.category-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.category-badge:hover::before {
    left: 100%;
}

/* ============================================
   IMPROVED TYPOGRAPHY & SPACING
   ============================================ */

.hero-card {
    padding: 2.5rem;
}

/* The title used to be clipped gradient text (text-primary -> primary). Both
   ends of that gradient are now navy and the hero card is navy too, so it
   painted the heading invisible; it takes the card's own white instead. */
.competition-info h2 {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.025em;
}

.section-header h2 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

/* Better Focus States */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Smooth Page Transitions */
.fade-in {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    .toast-container {
        left: 10px;
        right: 10px;
    }

    .toast {
        min-width: 0;
        max-width: 100%;
    }

    /* The podium stops being a podium on a phone.
       Three stacked 300px cards, each with a 3rem medal and 1.5rem of padding,
       filled the whole first screen before a visitor reached the list below —
       and the standings are why they opened the page. Same information, laid
       out as three compact rows: medal, who, score, with the supporting lines
       wrapping underneath. The stepped heights that made it read as a podium
       cannot survive a single column anyway, so the medal and the coloured
       edge carry the placing instead. */
    .podium-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.5rem 0;
        margin: 1rem 0;
    }

    /* Natural DOM order is 1, 2, 3 — the desktop `order` that puts first in the
       middle is exactly what must not apply here. */
    .podium-place {
        order: unset !important;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        max-width: none;
    }

    .podium-medal {
        font-size: 1.75rem;
        flex: 0 0 auto;
        animation: none;
    }

    .podium-card {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 0.25rem 0.5rem;
        padding: 0.625rem 0.875rem;
        text-align: left;
        border-width: 1px;
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
    }

    /* The placing stripe moves from the top edge to the leading edge, where a
       row can still show it. */
    .podium-card::before {
        top: 0;
        bottom: 0;
        right: auto;
        width: 4px;
        height: auto;
    }

    /* No scaling: in a single column it only makes the first row overflow. */
    .podium-place.first .podium-card,
    .podium-card:hover,
    .podium-place.first .podium-card:hover {
        transform: none;
    }

    /* The medal already says which place this is. */
    .podium-rank {
        display: none;
    }

    .podium-country {
        order: 1;
        font-size: 1rem;
        margin-bottom: 0;
    }

    .podium-competitor {
        order: 2;
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.9375rem;
        margin-bottom: 0;
        overflow-wrap: anywhere;
    }

    .podium-score {
        order: 3;
        margin-left: auto;
        margin-bottom: 0;
        font-size: 1.25rem;
        font-variant-numeric: tabular-nums;
    }

    /* Second line: whatever this subject actually carries — a dog, a line-up
       size, a club — set small and left to wrap on its own. */
    .podium-dog {
        order: 4;
        flex-basis: 100%;
        font-size: 0.75rem;
        margin-bottom: 0;
    }

    /* Also 100%: a country and a team carry a subtitle and no dog, so this is
       the item that has to open the second line for them. Whichever of the two
       an entry has breaks the line, and .podium-team then follows it inline. */
    .podium-sub {
        order: 5;
        flex-basis: 100%;
        font-size: 0.75rem;
        margin-bottom: 0;
    }

    .podium-team {
        order: 6;
        font-size: 0.75rem;
        margin-bottom: 0;
    }

    .podium-score-detail {
        order: 7;
        flex-basis: 100%;
        justify-content: flex-start;
        font-size: 0.6875rem;
    }
}

/* ============================================
   DARK THEME ADJUSTMENTS
   ============================================ */

[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        rgba(255, 255, 255, 0.05) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
}

[data-theme="dark"] .toast {
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
}

[data-theme="dark"] .podium-card {
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

/* The mobile podium is a flat row, so it takes the small shadow like every
   other row on the page; the rule above is written for the tall desktop card
   and is more specific, so it has to be answered here rather than in the
   mobile block. */
@media (max-width: 768px) {
    [data-theme="dark"] .podium-card {
        box-shadow: var(--shadow-sm);
    }
}

/* ============================================
   REDUCED MOTION

   Nothing in this file honoured the preference, while it runs four infinite
   animations — a floating medal, a shimmering skeleton, a shining progress bar
   and two pulses. An infinite animation is the one a visitor who asked for
   less motion most needs stopped, so those are removed outright; the one-shot
   entrances are only shortened to nothing, which keeps every element visible.
   The loading spinners deliberately keep turning: a frozen spinner reads as a
   hung page.
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .podium-medal,
    .score-progress-bar::after,
    .pulse,
    .pulse-ring::before {
        animation: none;
    }

    .podium-place,
    .skeleton,
    .fade-in {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
    }

    .podium-card,
    .toast {
        transition: none;
    }

    .podium-card:hover,
    .podium-place.first .podium-card:hover {
        transform: none;
    }
}
