/* Town cards page specific styles */

/* Scoped variable for consistent card height across grouped and normal tiles */
#town_Cards {
    --town-card-height: clamp(312px, 36vh, 420px);
}

/* Fixed media area for card tiles to restrict image height and keep layout compact */
.town-card-media-fixed {
    width: 100%;
    height: 160px; /* fixed visual height for tile images */
    max-height: 200px;
    background: var(--ui-surface-media);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* remove any extra bottom margin from images inside fixed media */
.town-card-media-fixed img { margin: 0; padding: 0; display: block; }

.town-card-media-fixed img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Ensure card header and actions don't expand - keep content area to fill */
.town-card-header {
    flex: 0 0 auto;
    min-height: 48px;
    box-sizing: border-box;
    padding: 8px 10px;
}

.town-card-actions {
    flex: 0 0 auto;
    box-sizing: border-box;
    padding: 8px 10px;
    align-items: center;
}

.town-card-preview .town-card-content {
    /* make sure content area can shrink and hide overflow */
    overflow: hidden;
}

.town-group-preview-card .town-card-header,
.town-group-preview-card .town-card-actions {
    padding-left: 8px;
    padding-right: 8px;
}

.town-cards-grid {
    align-items: stretch;
}

/* Controls used in virtualized view */
.town-scroll-controls-fab {
    position: fixed;
    right: 1rem;
    bottom: 1.25rem;
    z-index: 8300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}


.town-card-preview {
    /* Use scoped card height to keep tiles uniform */
    height: var(--town-card-height);
    max-height: calc(var(--town-card-height) + 40px);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--ui-town-card-preview-border);
    background: var(--ui-town-card-preview-bg);
    overflow: hidden;
    animation-duration: 420ms;
    animation-timing-function: cubic-bezier(.22, .61, .36, 1);
    animation-fill-mode: both;
    animation-delay: 0ms;
}

.row-slide-left {
    animation-name: slideFromLeft;
}

.row-slide-right {
    animation-name: slideFromRight;
}

.row-tone-even {
    border-color: var(--ui-town-row-even-border);
}

.row-tone-odd {
    border-color: var(--ui-town-row-odd-border);
}

.state-own-draft {
    border: 2px solid var(--ui-town-state-own-draft-border);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.18);
}

.state-verified {
    border: 2px solid #2563eb;
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.16);
}

.state-verified-premium {
    border: 2px solid #16a34a;
    box-shadow: 0 8px 22px rgba(22, 163, 74, 0.2);
}

.state-published-unverified {
    border: 2px solid var(--ui-town-state-unverified-border);
}

.town-card-top-row,
.town-card-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    gap: 6px;
    padding: 8px 10px;
    min-height: 42px;
    overflow-x: hidden;
    white-space: nowrap;
}

.town-card-name-with-icon {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 80px;
    overflow: hidden;
}

.town-card-name-with-icon > .mud-typography {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.town-card-name {
    flex: 1 1 auto;
    min-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-type-icon {
    font-size: 1.05rem;
    flex: 0 0 auto;
    min-width: 20px;
}

.town-card-subtitle-row {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 6px;
    padding: 2px 10px 8px 10px;
    min-height: 0;
    overflow-x: hidden;
    white-space: nowrap;
}

.town-card-subtitle-row > .mud-typography {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stage-inline-chip {
    height: 22px;
    flex: 0 0 auto;
}

.town-card-status-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.status-v-indicator {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.78rem;
    color: #ffffff;
    flex: 0 0 auto;
}

.status-v-blue {
    background: #2563eb;
}

.status-v-green {
    background: #16a34a;
}

.status-v-neutral {
    background: #111827;
    color: #f8fafc;
    border: 1px solid #94a3b8;
}

.town-card-media {
    /* Legacy media area - keep flexible but don't force expansion */
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    background: var(--ui-surface-media);
    overflow: hidden;
    cursor: zoom-in;
    position: relative;
}

.town-card-media img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: cover; /* preserve cover behaviour while keeping parent size fixed */
    display: block;
}

.town-card-carousel,
.town-card-carousel .mud-carousel,
.town-card-carousel .mud-carousel-container,
.town-card-carousel .mud-carousel-item,
.town-card-carousel .mud-swipearea,
.town-card-carousel .mud-paper {
    height: 100% !important;
    width: 100%;
    overflow: hidden;
}

.town-card-carousel .mud-carousel-item > * {
    height: 100%;
}

.town-card-carousel .mud-carousel-bullets {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    z-index: 2;
}

.town-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #607d8b;
}

/* Ensure main (non-grouped) card content reserves a fixed media area so images don't stretch
   This keeps image heights uniform between grouped and direct card views and ensures
   the action row (social links) stays visible at the bottom. */
.town-card-content {
    /* content area takes remaining vertical space between header and actions */
    flex: 1 1 auto;
    min-height: 0; /* allow flex children to shrink properly */
    display: flex;
    flex-direction: column;
}

.town-card-image-wrap,
.town-card-no-image {
    width: 100%;
    /* image area should fill available content space */
    flex: 1 1 auto;
    min-height: 0;
    background: var(--ui-surface-media);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}


.town-card-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.town-card-deferred-placeholder {
    background: linear-gradient(180deg, rgba(148, 163, 184, 0.16) 0%, rgba(148, 163, 184, 0.05) 100%);
    color: var(--mud-palette-text-secondary);
    animation: townCardDeferredPulse 1.6s ease-in-out infinite;
}

@keyframes townCardDeferredPulse {
    0% { opacity: 0.7; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

.town-card-bottom-row {
    border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.town-card-bottom-row .card-link-icons-row {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
}

/* Also apply to newer action container used on card tiles to ensure social links are visible */
.town-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px; /* tighten vertical padding */
    flex: 0 0 auto;
    border-top: 1px solid rgba(148, 163, 184, 0.08);
    background: transparent;
}

.town-card-actions .card-link-icons-row {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
}

.town-card-bottom-row .card-link-icons-row .mud-icon-button {
    margin-right: 2px;
}

/* Ensure social/icon buttons inside card bottom row are visible on all themes */
.town-card-bottom-row .card-link-icons-row .mud-icon-button,
.town-card-bottom-row .card-link-icons-row .mud-icon-button .mud-icon-root {
    color: var(--ui-page-text) !important;
}

.town-cards-search .mud-input-label,
.town-cards-search .mud-input-slot,
.town-cards-search .mud-input-adornment {
    color: var(--mud-palette-text-primary);
}

.town-cards-search .mud-outlined-input {
    background: var(--ui-input-bg);
}

.town-cards-searching-label {
    color: var(--mud-palette-text-primary);
    margin: 6px 0 4px;
}

/* Floating actions panel for quick access */
.town-cards-floating-actions {
    position: fixed;
    right: 1rem;
    bottom: 1.25rem;
    z-index: 8400; /* ensure above dialogs and appbar */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.town-cards-float-btn {
    background: rgba(33, 150, 243, 0.24);
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: rgba(255, 255, 255, 0.95);
    transition: background-color 0.2s ease, transform 0.2s ease;
    display: inline-flex !important;
}

.town-cards-float-btn:hover {
    background: rgba(33, 150, 243, 0.42);
    transform: translateY(-1px);
}

/* Ensure page-level action buttons on home and towns tiles are visible in black theme */
.black .town-card-action-button,
.black .home-action-button,
.black .page-town-button {
    color: var(--ui-page-text) !important;
    background: rgba(255,255,255,0.03) !important;
    border: 1px solid rgba(255,255,255,0.06) !important;
    padding: 6px 10px !important;
    border-radius: 8px !important;
}

/* Search anchor for scroll targeting */
#town-cards-search-anchor {
    scroll-margin-top: 5.5rem;
}

#town-cards-search-anchor.search-highlight {
    animation: town-search-highlight 900ms ease-in-out;
}

@keyframes town-search-highlight {
    0% { filter: drop-shadow(0 0 0 rgba(33,150,243,0)); }
    35% { filter: drop-shadow(0 0 8px rgba(33,150,243,0.65)); }
    100% { filter: drop-shadow(0 0 0 rgba(33,150,243,0)); }
}

.town-image-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.76);
    z-index: 8250; /* ensure image preview overlays top appbar */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.town-image-preview-dialog {
    width: min(92vw, 980px);
    max-height: 90vh;
    border-radius: 12px;
    background: var(--mud-palette-surface);
    border: 1px solid rgba(148, 163, 184, 0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.town-image-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.24);
}

.town-image-preview-carousel img,
.town-image-preview-single {
    width: 100%;
    height: 70vh;
    max-height: 70vh;
    object-fit: contain;
    background: #020617;
}

.town-image-preview-carousel,
.town-image-preview-carousel .mud-carousel,
.town-image-preview-carousel .mud-carousel-container,
.town-image-preview-carousel .mud-carousel-item,
.town-image-preview-carousel .mud-swipearea,
.town-image-preview-carousel .mud-paper {
    height: 70vh !important;
    max-height: 70vh;
    overflow: hidden;
}

@keyframes slideFromLeft {
    from {
        opacity: 0;
        transform: translateX(-18px) translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateX(0) translateY(0);
    }
}

@keyframes slideFromRight {
    from {
        opacity: 0;
        transform: translateX(18px) translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateX(0) translateY(0);
    }
}

/* Kept for compatibility with older markup variants */
.stage-chip {
    font-size: 0.65rem;
    height: 18px;
    padding: 0 6px;
}

.town-open-chip-manual {
    box-shadow: 0 0 0 1px rgba(21, 128, 61, 0.45), 0 0 14px rgba(22, 163, 74, 0.45);
}

.town-open-chip-timing {
    border-color: rgba(22, 163, 74, 0.55) !important;
}

.town-open-chip-closed {
    border-color: rgba(245, 158, 11, 0.45) !important;
}

/* Loader / decorative icons ring */
.town-loader-card {
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(25, 118, 210, .08), rgba(76, 175, 80, .08));
}

.town-loader-icon-ring {
    position: relative;
    width: 104px;
    height: 104px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.town-loader-icon {
    position: absolute;
    font-size: 22px;
    color: var(--mud-palette-primary);
    animation: town-loader-float 1.7s ease-in-out infinite;
}

.town-loader-icon-1 { top: 2px; left: 42px; animation-delay: 0s; }
.town-loader-icon-2 { right: 2px; top: 42px; animation-delay: .2s; }
.town-loader-icon-3 { bottom: 2px; left: 42px; animation-delay: .4s; }
.town-loader-icon-4 { left: 2px; top: 42px; animation-delay: .6s; }

@keyframes town-loader-float {
    0%, 100% { transform: scale(.9); opacity: .55; }
    50% { transform: scale(1.18); opacity: 1; }
}

/* Group preview row: single horizontal row with no visible scrollbar but scrollable by JS */
.town-group-preview-row {
    display: flex;
    gap: 10px;
    overflow-x: scroll;
    overflow-y: hidden;
    padding: 6px 2px 10px 2px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Group expanded row: same styling as preview row for consistency */
.town-group-expanded-row {
    display: flex;
    gap: 10px;
    overflow-x: scroll;
    overflow-y: hidden;
    padding: 6px 2px 10px 2px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
}

.town-group-preview-nav-container {
    width: 100%;
    margin-bottom: 8px;
}

.town-group-preview-row-wrapper {
    position: relative;
    flex: 1 1 auto;
    overflow: hidden;
    display: flex;
    align-items: center;
    min-width: 0;
}

.town-group-nav-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    backdrop-filter: blur(2px);
    background: rgba(255, 255, 255, 0.86);
}

.town-group-nav-button-left {
    left: 6px;
}

.town-group-nav-button-right {
    right: 6px;
}

.town-group-nav-button.town-group-nav-hidden {
    visibility: hidden;
    pointer-events: none;
}

.town-group-nav-button:hover {
    background-color: rgba(33, 150, 243, 0.08);
}

.town-group-preview-card {
    min-width: calc((100% - (10px * (var(--visible-cards-per-row) - 1))) / var(--visible-cards-per-row));
    max-width: calc((100% - (10px * (var(--visible-cards-per-row) - 1))) / var(--visible-cards-per-row));
    flex: 0 0 auto;
    height: var(--town-card-height);
}

.town-group-preview-card > .town-card-preview {
    height: 100%;
}

.town-group-preview-card.town-group-preview-card-compact {
    height: auto;
    align-self: stretch;
}

.town-card-preview.town-card-preview-no-image {
    height: auto;
    min-height: 0;
}

.town-group-preview-action-card {
    flex: 0 0 auto;
    width: auto;
    display: flex;
    align-items: center;
}

.town-group-preview-action-button {
    width: auto;
    min-width: 132px;
    height: auto;
    border-style: dashed;
    white-space: nowrap;
}

/* Hidden scrollbar for horizontal rows; overflow-x must remain scroll for JS to work */
.town-group-horizontal-row {
    overflow-x: scroll;
    overflow-y: hidden;
    scrollbar-width: none;
}

.town-group-horizontal-row::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

/* Virtual scroll row and card-preview depth effect */
.town-cards-virtual-scroll::-webkit-scrollbar { width: 0; height: 0; display: none; }
.town-card-virtual-row { height: auto; box-sizing: border-box; overflow: hidden; }

/* Ensure virtual row collapses when no cards in row to avoid extra whitespace */
.town-card-virtual-row:empty { height: 0; padding: 0; margin: 0; }

/* slight image slide animation for cards with multiple images */
@keyframes town-card-fade-slide { 0% { opacity: 0; } 8% { opacity: 1; } 42% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 0; } }

/* Dialog styles moved to global app.css (.app-backdrop, .app-dialog, .app-dialog-header, .app-dialog-close-btn)
   Use these classes for consistent styling across all dialogs in the application */

/* Open/closed chip color helpers */
.town-open-chip-manual, .town-open-chip-timing { background-color: #e6f4ea; color: #137333; }
.town-open-chip-closed { background-color: #fce8e6; color: #a50e0e; }

/* Responsive tweaks for group rows */
@media (max-width: 600px) {
    .town-group-preview-row {
        padding-left: 0;
        padding-right: 0;
        gap: 0;
    }

    .town-group-preview-row-wrapper {
        padding-left: 0;
        padding-right: 0;
    }

    /* Full-width single-card viewport on mobile */
    .town-group-preview-card {
        min-width: 100%;
        max-width: 100%;
    }

    /* Keep arrows overlaid on card image area so they don't consume layout width */
    .town-group-preview-nav-container-mobile .town-group-nav-button {
        width: 28px;
        height: 28px;
        min-width: 28px;
        padding: 2px;
        top: 132px;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.74);
    }

    .town-group-preview-nav-container-mobile .town-group-nav-button .mud-icon-root {
        font-size: 18px;
    }

    .town-group-preview-nav-container-mobile .town-group-nav-button-left { left: 6px; }
    .town-group-preview-nav-container-mobile .town-group-nav-button-right { right: 6px; }

    .town-scroll-controls-fab { right: 8px; opacity: 0.6; }
    .town-scroll-controls-fab:hover { opacity: 1; }
}
