/* =============================================================================
   STABLES HUB PAGE - "Find Your Herd"
   Social discovery page for course-based playing groups.
   Dawn-to-dusk energy: Morning / Noon / Afternoon time periods.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   CUSTOM PROPERTIES
   ----------------------------------------------------------------------------- */
:root {
    /* Stables-specific tokens */
    --stable-card-radius: 14px;
    --stable-pill-radius: 20px;
    --stable-grid-gap: 1.25rem;

    /* Time-period colors (dawn to dusk progression) */
    --stable-morning: #f59e0b;
    --stable-morning-bg: rgba(245, 158, 11, 0.08);
    --stable-noon: var(--theme-primary);
    --stable-noon-bg: rgba(var(--flipt-primary-rgb), 0.08);
    --stable-afternoon: #8b5cf6;
    --stable-afternoon-bg: rgba(139, 92, 246, 0.08);

    /* Active pill glow intensities */
    --stable-morning-glow: rgba(245, 158, 11, 0.25);
    --stable-noon-glow: rgba(var(--flipt-primary-rgb), 0.25);
    --stable-afternoon-glow: rgba(139, 92, 246, 0.25);

    /* Hero gradient — sunrise-to-sunset sweep */
    --stable-hero-gradient: linear-gradient(
        135deg,
        rgba(var(--flipt-primary-rgb), 0.12) 0%,
        rgba(var(--flipt-secondary-rgb), 0.08) 50%,
        rgba(139, 92, 246, 0.06) 100%
    );

    /* Surfaces */
    --stable-card-bg: var(--theme-surface-1);
    --stable-card-border: var(--theme-border-color);
    --stable-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --stable-card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.1);

    /* Timing */
    --stable-transition: 0.2s ease;
    --stable-transition-lift: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-bs-theme="dark"],
body.dark-mode {
    --stable-morning-bg: rgba(245, 158, 11, 0.12);
    --stable-noon-bg: rgba(var(--flipt-primary-rgb), 0.12);
    --stable-afternoon-bg: rgba(139, 92, 246, 0.12);

    --stable-morning-glow: rgba(245, 158, 11, 0.35);
    --stable-noon-glow: rgba(var(--flipt-primary-rgb), 0.35);
    --stable-afternoon-glow: rgba(139, 92, 246, 0.35);

    --stable-hero-gradient: linear-gradient(
        135deg,
        rgba(var(--flipt-primary-rgb), 0.15) 0%,
        rgba(var(--flipt-secondary-rgb), 0.10) 50%,
        rgba(139, 92, 246, 0.08) 100%
    );

    --stable-card-bg: var(--theme-surface-1);
    --stable-card-border: var(--theme-border-color);
    --stable-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    --stable-card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* -----------------------------------------------------------------------------
   PAGE CONTAINER
   ----------------------------------------------------------------------------- */
.stables-hub {
    position: relative;
    min-height: 100vh;
    padding-bottom: 4rem;
}

/* -----------------------------------------------------------------------------
   HERO HEADER
   ----------------------------------------------------------------------------- */
.stables-hero {
    position: relative;
    padding: 3.5rem 1.5rem 2.5rem;
    text-align: center;
    background: var(--stable-hero-gradient);
    border-bottom: 1px solid var(--theme-border-color);
    overflow: hidden;
}

/* Atmospheric noise texture overlay */
.stables-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

.stables-hero__content {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 0 auto;
}

.stables-hero__title {
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 800;
    font-size: 2.25rem;
    letter-spacing: -0.03em;
    color: var(--theme-text-primary);
    margin: 0 0 0.5rem;
    line-height: 1.1;
}

.stables-hero__tagline {
    font-size: 1.05rem;
    color: var(--theme-text-secondary);
    margin: 0;
    line-height: 1.5;
    max-width: 480px;
    margin-inline: auto;
}

/* -----------------------------------------------------------------------------
   SECTION LAYOUT
   ----------------------------------------------------------------------------- */
.stables-section {
    max-width: 1120px;
    margin: 0 auto;
    padding: 2rem 1.5rem 0;
}

.stables-section__title {
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: -0.02em;
    color: var(--theme-text-primary);
    margin: 0 0 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--theme-border-color);
}

/* -----------------------------------------------------------------------------
   STABLES GRID - Responsive card layout
   ----------------------------------------------------------------------------- */
.stables-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--stable-grid-gap);
}

@media (min-width: 576px) {
    .stables-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .stables-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* -----------------------------------------------------------------------------
   MY STABLES CARD (stable-card--mine)
   Compact cards linking to stables the user has joined.
   ----------------------------------------------------------------------------- */
.stable-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1rem 1.25rem;
    background: var(--stable-card-bg);
    border: 1px solid var(--stable-card-border);
    border-radius: var(--stable-card-radius);
    box-shadow: var(--stable-card-shadow);
    text-decoration: none;
    color: var(--theme-text-primary);
    transition:
        transform var(--stable-transition-lift),
        box-shadow var(--stable-transition),
        border-color var(--stable-transition);
}

.stable-card:hover,
.stable-card:focus-visible {
    transform: translateY(-3px);
    box-shadow: var(--stable-card-shadow-hover);
    border-color: var(--theme-primary);
    color: var(--theme-text-primary);
    text-decoration: none;
}

.stable-card:focus-visible {
    outline: 2px solid var(--theme-info);
    outline-offset: 2px;
}

.stable-card--mine {
    border-left: 3px solid var(--theme-primary);
}

.stable-card__course {
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--theme-text-primary);
    line-height: 1.3;
}

.stable-card__period {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--theme-primary);
}

.stable-card__activity {
    font-size: 0.78rem;
    color: var(--theme-text-muted);
    margin-top: auto;
}

/* -----------------------------------------------------------------------------
   COURSE STABLE CARD (nearby discovery cards)
   Premium feel: shadow, structured layout, period pills.
   ----------------------------------------------------------------------------- */
.stable-course-card {
    display: flex;
    flex-direction: column;
    background: var(--stable-card-bg);
    border: 1px solid var(--stable-card-border);
    border-radius: var(--stable-card-radius);
    box-shadow: var(--stable-card-shadow);
    overflow: hidden;
    transition:
        transform var(--stable-transition-lift),
        box-shadow var(--stable-transition),
        border-color var(--stable-transition);
}

.stable-course-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--stable-card-shadow-hover);
    border-color: var(--theme-primary);
}

.stable-course-card__header {
    padding: 1.1rem 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.stable-course-card__name {
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--theme-text-primary);
    margin: 0;
    line-height: 1.3;
}

.stable-course-card__location {
    font-size: 0.82rem;
    color: var(--theme-text-secondary);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.stable-course-card__location::before {
    content: "\f3c5";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 0.72rem;
    color: var(--theme-text-muted);
}

.stable-course-card__distance {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--theme-primary);
}

/* -----------------------------------------------------------------------------
   TIME PERIOD PILLS
   Dawn-to-dusk color coding: Morning (amber), Noon (teal), Afternoon (violet).
   Active pills get a subtle glow to signal life.
   ----------------------------------------------------------------------------- */
.stable-course-card__periods {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem 0.75rem;
}

.stable-period-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    padding: 0.5rem 0.4rem;
    border-radius: var(--stable-pill-radius);
    background: var(--theme-surface-2);
    border: 1px solid var(--theme-border-color);
    text-decoration: none;
    color: var(--theme-text-muted);
    transition:
        background var(--stable-transition),
        border-color var(--stable-transition),
        color var(--stable-transition),
        box-shadow var(--stable-transition),
        transform var(--stable-transition-lift);
    cursor: pointer;
}

.stable-period-pill:hover {
    transform: translateY(-1px);
    text-decoration: none;
}

.stable-period-pill:focus-visible {
    outline: 2px solid var(--theme-info);
    outline-offset: 2px;
}

/* Morning period */
.stable-period-pill--morning,
.stable-period-pill--active:nth-child(1) {
    /* Specificity fallback for server-rendered active state */
}

/* Active state — applied when member count > 0 */
.stable-period-pill--active {
    color: var(--theme-text-primary);
    border-color: var(--theme-primary);
    background: var(--stable-noon-bg);
}

/* Period-specific active colors via nth-child targeting pill order */
.stable-period-pill--active:nth-child(1) {
    border-color: var(--stable-morning);
    background: var(--stable-morning-bg);
    box-shadow: 0 0 0 3px var(--stable-morning-glow);
}

.stable-period-pill--active:nth-child(2) {
    border-color: var(--stable-noon);
    background: var(--stable-noon-bg);
    box-shadow: 0 0 0 3px var(--stable-noon-glow);
}

.stable-period-pill--active:nth-child(3) {
    border-color: var(--stable-afternoon);
    background: var(--stable-afternoon-bg);
    box-shadow: 0 0 0 3px var(--stable-afternoon-glow);
}

.stable-period-pill--active:hover {
    transform: translateY(-2px);
}

.stable-period-pill__name {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
}

.stable-period-pill__count {
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    line-height: 1.2;
    margin-top: 0.15rem;
}

/* Count-specific color inheritance for active pills */
.stable-period-pill--active:nth-child(1) .stable-period-pill__count {
    color: var(--stable-morning);
}

.stable-period-pill--active:nth-child(2) .stable-period-pill__count {
    color: var(--stable-noon);
}

.stable-period-pill--active:nth-child(3) .stable-period-pill__count {
    color: var(--stable-afternoon);
}

/* Subtle pulse animation on active pills with members */
@keyframes stablePulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--pulse-color); }
    50% { box-shadow: 0 0 0 5px var(--pulse-color), 0 0 12px 2px var(--pulse-color); }
}

.stable-period-pill--active:nth-child(1) {
    --pulse-color: var(--stable-morning-glow);
}

.stable-period-pill--active:nth-child(2) {
    --pulse-color: var(--stable-noon-glow);
}

.stable-period-pill--active:nth-child(3) {
    --pulse-color: var(--stable-afternoon-glow);
}

.stable-period-pill--active {
    animation: stablePulse 3s ease-in-out infinite;
}

/* Last active timestamp */
.stable-course-card__last-active {
    padding: 0.5rem 1.25rem 0.85rem;
    font-size: 0.75rem;
    color: var(--theme-text-muted);
    border-top: 1px solid var(--theme-border-color);
    margin-top: auto;
}

.stable-course-card__last-active::before {
    content: "\f017";
    font-family: "Font Awesome 6 Free";
    font-weight: 400;
    margin-right: 0.35rem;
    font-size: 0.7rem;
}

/* -----------------------------------------------------------------------------
   LOCATION PROMPT
   Prominent, inviting section for location acquisition.
   ----------------------------------------------------------------------------- */
.stables-location-prompt {
    padding: 2rem 1.75rem;
    background: var(--stable-hero-gradient);
    border: 1px solid var(--theme-border-color);
    border-radius: var(--stable-card-radius);
    text-align: center;
    margin-bottom: var(--stable-grid-gap);
}

.stables-location-prompt > p {
    font-size: 1rem;
    color: var(--theme-text-secondary);
    margin: 0 0 1.25rem;
    line-height: 1.5;
}

.stables-location-prompt__actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.stables-location-prompt__divider {
    font-size: 0.85rem;
    color: var(--theme-text-muted);
    font-weight: 600;
    text-transform: lowercase;
}

.stables-location-prompt__zip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stables-location-prompt__zip .form-control {
    max-width: 140px;
    border-radius: 8px;
    font-size: 0.9rem;
}

/* Loading state overlay for the nearby section */
.stables-nearby--loading .stables-grid {
    position: relative;
    min-height: 120px;
    pointer-events: none;
    opacity: 0.4;
    transition: opacity 0.2s ease;
}

.stables-nearby--loading .stables-grid::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border: 3px solid var(--theme-border-color);
    border-top-color: var(--theme-primary);
    border-radius: 50%;
    animation: stablesSpin 0.7s linear infinite;
}

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

/* Button loading state */
.stables-location-prompt .btn[disabled] {
    opacity: 0.7;
    pointer-events: none;
}

/* -----------------------------------------------------------------------------
   EMPTY STATE
   ----------------------------------------------------------------------------- */
.stables-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--theme-text-muted);
}

.stables-empty p {
    font-size: 0.95rem;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Error state styling for location denial */
.stables-location-error {
    font-size: 0.85rem;
    color: var(--theme-danger);
    margin-top: 0.75rem;
}

/* -----------------------------------------------------------------------------
   CARD ENTRANCE ANIMATION
   Staggered reveal as cards appear (used for both server and client renders)
   ----------------------------------------------------------------------------- */
@keyframes stablesCardIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stable-course-card,
.stable-card {
    animation: stablesCardIn 0.35s ease-out both;
}

/* Stagger children in the grid */
.stables-grid > :nth-child(1) { animation-delay: 0s; }
.stables-grid > :nth-child(2) { animation-delay: 0.05s; }
.stables-grid > :nth-child(3) { animation-delay: 0.1s; }
.stables-grid > :nth-child(4) { animation-delay: 0.15s; }
.stables-grid > :nth-child(5) { animation-delay: 0.2s; }
.stables-grid > :nth-child(6) { animation-delay: 0.25s; }
.stables-grid > :nth-child(7) { animation-delay: 0.3s; }
.stables-grid > :nth-child(8) { animation-delay: 0.35s; }
.stables-grid > :nth-child(9) { animation-delay: 0.4s; }

/* AJAX-inserted cards get the animation class */
.stable-course-card--entering {
    animation: stablesCardIn 0.3s ease-out both;
}

/* -----------------------------------------------------------------------------
   RESPONSIVE REFINEMENTS
   ----------------------------------------------------------------------------- */

/* Small screens: tighten spacing */
@media (max-width: 575.98px) {
    .stables-hero {
        padding: 2.5rem 1rem 2rem;
    }

    .stables-hero__title {
        font-size: 1.75rem;
    }

    .stables-hero__tagline {
        font-size: 0.95rem;
    }

    .stables-section {
        padding: 1.5rem 1rem 0;
    }

    .stables-section__title {
        font-size: 1.15rem;
    }

    .stables-location-prompt {
        padding: 1.5rem 1.25rem;
    }

    .stables-location-prompt__actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .stables-location-prompt__zip {
        width: 100%;
    }

    .stables-location-prompt__zip .form-control {
        max-width: none;
        flex: 1;
    }

    .stable-course-card__periods {
        gap: 0.35rem;
        padding: 0.5rem 1rem 0.75rem;
    }

    .stable-period-pill {
        padding: 0.4rem 0.25rem;
    }

    .stable-period-pill__name {
        font-size: 0.62rem;
    }

    .stable-period-pill__count {
        font-size: 0.95rem;
    }
}

/* Medium screens: 2-column polish */
@media (min-width: 576px) and (max-width: 991.98px) {
    .stables-hero__title {
        font-size: 2rem;
    }
}

/* Large screens: extra breathing room */
@media (min-width: 1200px) {
    .stables-section {
        padding-top: 2.5rem;
    }

    .stables-hero {
        padding: 4rem 2rem 3rem;
    }

    .stables-hero__title {
        font-size: 2.5rem;
    }
}

/* -----------------------------------------------------------------------------
   REDUCED MOTION
   ----------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .stable-course-card,
    .stable-card,
    .stable-course-card--entering {
        animation: none;
    }

    .stable-period-pill--active {
        animation: none;
    }

    .stable-course-card:hover,
    .stable-card:hover,
    .stable-period-pill:hover,
    .stable-period-pill--active:hover {
        transform: none;
    }

    .stables-nearby--loading .stables-grid::after {
        animation-duration: 1.5s;
    }
}

/* -----------------------------------------------------------------------------
   FOCUS STATES (Accessibility)
   ----------------------------------------------------------------------------- */
.stable-course-card:focus-within {
    outline: 2px solid var(--theme-info);
    outline-offset: 2px;
}

.stables-location-prompt .btn:focus-visible,
.stables-location-prompt .form-control:focus-visible {
    outline: 2px solid var(--theme-info);
    outline-offset: 2px;
}
