/**
 * Country Page Styles
 * Styles for individual country stamp collection pages
 */

/* ===== COUNTRY PAGE LAYOUT ===== */
.country-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.country-page main {
    flex: 1;
}

/* ===== COUNTRY HERO SECTION ===== */
.country-hero {
    background: var(--hp-white, #ffffff);
    color: var(--hp-black, #0a0a0a);
    padding: var(--space-6) 0;
    position: relative;
    overflow: hidden;
}

.country-hero .container {
    position: relative;
    z-index: 1;
}

.country-hero__content {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.country-hero__flag {
    font-size: 4rem;
    line-height: 1;
}

.country-hero__flag img {
    height: 60px;
    width: auto;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-md);
}

.country-hero__text {
    flex: 1;
    min-width: 200px;
}

.country-hero__title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 700;
    margin: 0 0 0.75rem;
    color: var(--hp-black, #0a0a0a);
    line-height: 1.1;
}

.country-hero__subtitle {
    font-family: var(--font-body);
    font-size: clamp(0.9375rem, 1.5vw, 1.0625rem);
    color: var(--hp-text-light, #57534e);
    margin: 0;
    line-height: 1.7;
}

.country-hero__stats {
    display: flex;
    gap: var(--space-6);
    margin-left: auto;
}

.country-hero__stat {
    text-align: center;
}

.country-hero__stat-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-secondary);
}

.country-hero__stat-label {
    font-size: var(--font-size-sm);
    color: var(--hp-text-light, #57534e);
}

/* ===== COUNTRY NAVIGATION (Previous/Next) =====
 * Now uses shared prev-next-nav.css component (.year-prev-next / .bottom-nav)
 * Country pages share the same nav style as year pages.
 */

/* Container width + padding now in prev-next-nav.css component */

/* ===== COUNTRY CONTENT LAYOUT ===== */
.country-content {
    display: block;
    padding: var(--space-6) 0;
}

.country-sidebar {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.country-main {
    min-width: 0;
}

/* ===== TABLE OF CONTENTS =====
 * Base TOC styles now in css/components/toc.css
 * Only country-specific layout overrides remain here.
 *
 * Width "prop": set --toc-width on .country-sidebar to control TOC width.
 *   - TOC alone (no video/companion): defaults to 100% (full width)
 *   - TOC with companion: defaults to 50%, override with --toc-width
 *   Examples:
 *     style="--toc-width: 50%"  → 50/50 split (India)
 *     style="--toc-width: 66%"  → 2/3 + 1/3 split
 *     (no style needed)         → full width when TOC is alone (Germany)
 */
.country-sidebar > .toc:only-child {
    flex: 0 1 100%;
    min-width: 0;
}

.country-sidebar > .toc:not(:only-child) {
    flex: 0 1 var(--toc-width, 50%);
    min-width: 0;
}

/* ===== SIDEBAR COMPANION (video, promo, etc.) ===== */
.sidebar-video {
    flex: 1 1 0%;
    min-width: 0;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    aspect-ratio: 475 / 300;
}

.sidebar-video iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
}

/* ===== CONTENT SECTIONS ===== */
.country-section {
    margin-bottom: var(--space-8);
    scroll-margin-top: 160px;
}

.country-section__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
}

.country-section__title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    margin: 0;
    color: var(--color-text-primary);
}

.country-section__icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    color: var(--color-white);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-lg);
}

.country-section__content {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

.country-section__content p {
    margin-bottom: var(--space-4);
}

.country-section__content a {
    color: var(--color-primary);
}

.country-section__content a:hover {
    text-decoration: underline;
}

/* ===== STAMP GALLERY GRID ===== */
.stamp-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
}

.stamp-gallery--compact {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
}

.stamp-gallery--large {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

/* ===== STAMP ITEM ===== */
.stamp-item {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    transition: all var(--transition-fast);
}

.stamp-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary);
}

.stamp-item__image-wrapper {
    display: block;
    position: relative;
    aspect-ratio: 4/3;
    background: var(--color-background-alt);
    overflow: hidden;
}

.stamp-item__image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: var(--space-2);
    cursor: pointer;
    transition: transform var(--transition-normal);
}

.stamp-item:hover .stamp-item__image {
    transform: scale(1.05);
}

.stamp-item__zoom {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    color: var(--color-white);
    border-radius: var(--border-radius-full);
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.stamp-item:hover .stamp-item__zoom {
    opacity: 1;
}

.stamp-item__content {
    padding: var(--space-3);
}

.stamp-item__date {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-bottom: var(--space-1);
}

.stamp-item__title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-2);
    line-height: var(--line-height-tight);
}

.stamp-item__title a {
    color: inherit;
    text-decoration: none;
}

.stamp-item__title a:hover {
    color: var(--color-primary);
}

.stamp-item__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
}

.stamp-item__tag {
    display: inline-block;
    padding: 2px var(--space-2);
    background: var(--color-background-alt);
    color: var(--color-text-secondary);
    border-radius: var(--border-radius-sm);
}

.stamp-item__tag--year {
    background: var(--color-primary);
    color: var(--color-white);
}

/* ===== STAMP TABLE (Legacy Support) ===== */
.stamp-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--space-4);
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.stamp-table th,
.stamp-table td {
    padding: var(--space-3);
    text-align: center;
    border-bottom: 1px solid var(--color-border);
}

.stamp-table th {
    background: var(--color-background-alt);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.stamp-table tr:last-child td {
    border-bottom: none;
}

.stamp-table img {
    max-width: 100%;
    height: auto;
    transition: transform var(--transition-fast);
}

.stamp-table a:hover img {
    transform: scale(1.05);
}

/* ===== YEAR SECTION ===== */
.year-section {
    margin-bottom: var(--space-6);
}

.year-section__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.year-section__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: var(--space-2) var(--space-3);
    background: var(--color-primary);
    color: var(--color-white);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    border-radius: var(--border-radius-sm);
}

.year-section__title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    margin: 0;
}

.year-section__count {
    margin-left: auto;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* ===== NOTES AND REFERENCES ===== */
.notes-box {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-left: 4px solid #ffc107;
    border-radius: var(--border-radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}

.notes-box__title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: #f57c00;
    margin: 0 0 var(--space-2);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.notes-box__title::before {
    content: '\2139';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: #ffc107;
    color: var(--color-white);
    border-radius: var(--border-radius-full);
    font-size: var(--font-size-xs);
}

.notes-box__content {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
    overflow: hidden; /* contain floated figures */
}

.notes-box__content p:last-child {
    margin-bottom: 0;
}

/* Float figures inside notes — constrain width so text wraps alongside */
.notes-box__content > figure {
    max-width: 45%;
}

.notes-box__content > figure img {
    max-width: 100%;
    height: auto;
}

/* ===== INLINE QUOTES (<q>) ===== */
.country-main q {
    display: block;
    overflow: hidden;
    border-left: 3px solid var(--hp-yellow, #d4a72c);
    padding: 0.75rem 1rem 0.75rem 2.25rem;
    margin: 0.75rem 0;
    background: #fdfaf3;
    border-radius: 0 4px 4px 0;
    line-height: 1.65;
    font-style: italic;
    quotes: none;
    position: relative;
}

.country-main q::before {
    content: '\201C';
    position: absolute;
    left: 0.6rem;
    top: 0.4rem;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--hp-yellow, #d4a72c);
    font-style: normal;
    font-family: Georgia, serif;
}

.country-main q em {
    font-style: italic;
}

/* ===== HORIZONTAL RULE (<hr>) ===== */
.country-main hr {
    border: none;
    height: 0;
    border-top: 2px solid var(--hp-yellow, #d4a72c);
    margin: 2.5rem auto;
    max-width: 100%;
    position: relative;
    overflow: visible;
}

.country-main hr::before {
    content: "\25C6";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--hp-cream, #faf9f7);
    padding: 0 0.75rem;
    color: var(--hp-yellow, #d4a72c);
    font-size: 0.75rem;
    line-height: 1;
}

/* ===== NOTES PARAGRAPH (<p class="notes">) ===== */
.country-main .notes {
    background: #f4f6f7;
    border-left: 3px solid #90a4ae;
    padding: 0.5rem 1rem 0.5rem 2.25rem;
    border-radius: 0 4px 4px 0;
    margin: 0.75rem 0;
    overflow: hidden;
    position: relative;
}

.country-main .notes::before {
    content: '\2139';
    position: absolute;
    left: 0.65rem;
    top: 0.45rem;
    font-size: 0.875rem;
    line-height: 1;
    color: #607d8b;
    font-weight: 700;
}

/* References List */
.references-list {
    list-style: decimal;
    padding-left: var(--space-5);
    margin: 0;
}

.references-list li {
    margin-bottom: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

.references-list a {
    color: var(--color-primary);
    word-break: break-all;
}

/* Acknowledgements */
.acknowledgements {
    background: var(--color-background-alt);
    border-radius: var(--border-radius-md);
    padding: var(--space-4);
}

.acknowledgements__title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--space-3);
    color: var(--color-text-primary);
}

.acknowledgements__content {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

/* ===== POSTMARKS & POSTAL STATIONERY ===== */
.postmarks-grid,
.stationery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-4);
}

.postmark-item,
.stationery-item {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: var(--space-3);
    text-align: center;
    transition: all var(--transition-fast);
}

.postmark-item:hover,
.stationery-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.postmark-item__image,
.stationery-item__image {
    max-width: 100%;
    height: auto;
    margin-bottom: var(--space-2);
}

.postmark-item__caption,
.stationery-item__caption {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

/* ===== RELATED COUNTRIES ===== */
.related-countries {
    background: var(--color-background-alt);
    padding: var(--space-5) 0;
    margin-top: var(--space-6);
}

.related-countries__title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--space-4);
    text-align: center;
}

.related-countries__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
}

.related-country-card {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    text-decoration: none;
    color: var(--color-text-primary);
    transition: all var(--transition-fast);
}

.related-country-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

.related-country-card__flag {
    font-size: var(--font-size-xl);
}

.related-country-card__name {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

/* ===== H2 HEADINGS (Year-Page Style) ===== */
.country-main h2:not(.column-box__title) {
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2.5vw, 1.75rem);
    font-weight: 600;
    color: var(--hp-black, #0a0a0a);
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid var(--hp-yellow, #d4a72c);
    line-height: 1.3;
}

/* ===== COUNTRY-SPECIFIC FLOAT TABLE OVERRIDES =====
 * Base float table fixes, link styling, br collapse, and float clearing
 * are now in common-style.css (scoped to .legacy-content).
 * Only country-specific refinements remain here.
 */

/* Float table base (width:min-content, img max-width:none) now in common-style.css */

/* ===== STAMP PREVIEW GRID TABLES (Year/2025 Stamp-Entry Card Style) =====
 * Legacy grid tables styled to match .stamp-entry cards from year pages.
 * Title row + image row form a connected card (header + body).
 * Zero vertical border-spacing so header/body cells connect seamlessly. */

/* Grid table base — no vertical gap so title+image cells connect */
.country-main > table:not([align]) {
    table-layout: auto;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0.75rem 0;
}

/* Non-card tables (no .slist images) — collapse borders for tight layout.
   The border-spacing above is only needed for stamp-card grids. */
.country-main > table:not([align]):not(:has(img.slist)) {
    border-collapse: collapse;
}

/* Default TD styling */
.country-main > table:not([align]) td {
    padding: 0.25rem 0.375rem;
    vertical-align: top;
    background: transparent;
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--hp-text-light, #57534e);
}

/* Spacer rows — create gap between card groups */
.country-main > table:not([align]) td[style*="height"] {
    height: 2.5rem !important;
}

/* Section headers — colspan cells as full-width section dividers.
   Exclude caption cells (containing <small>) — those are descriptive text, not headers. */
.country-main > table:not([align]) td[colspan]:not(:has(small)) {
    padding: 0.625rem 0.75rem;
    background: var(--hp-warm-white, #faf8f5);
    border-bottom: 3px solid var(--hp-yellow, #d4a72c);
    border-radius: 6px 6px 0 0;
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--hp-black, #1a1a1a);
    text-align: center;
}

/* ---- CARD HEADER: title cells in rows immediately before image rows ---- */
.country-main > table:not([align]) tr:has(+ tr > td > a > img.slist) > td:not([colspan]):not(:empty) {
    background: var(--hp-warm-white, #faf8f5);
    border: 1px solid var(--hp-gray, #e5e4e1);
    border-bottom: 3px solid var(--hp-yellow, #d4a72c);
    border-radius: 8px 8px 0 0;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--hp-black, #0a0a0a);
    text-align: left;
}

/* ---- CARD BODY: image cells — connects to header above ---- */
.country-main > table:not([align]) td:has(> a > img.slist) {
    background: var(--hp-cream, #f8f6f0);
    border: 1px solid var(--hp-gray, #e5e4e1);
    border-top: none;
    border-radius: 0 0 8px 8px;
    padding: 0.375rem;
    transition: all 0.25s ease;
}

.country-main > table:not([align]) td:has(> a > img.slist):hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
    border-color: var(--hp-yellow, #d4a72c);
}

/* Remove redundant card styling from img.slist inside card body */
.country-main > table:not([align]) td:has(> a > img.slist) img.slist {
    border: none;
    background: transparent;
    padding: 0;
}

/* Colspan cells: let img.slist fill the wider cell instead of fixed 300px */
.country-main > table:not([align]) td[colspan] img.slist {
    width: 100%;
    height: auto;
}

/* Google Ads inside stamp grid tables: visible, constrained to cell.
   Override section-header styling (td[colspan] gets border-bottom/background)
   so ad cells stay clean. */
.country-main > table:not([align]) td:has(amp-ad),
.country-main > table:not([align]) td:has(.adsbygoogle) {
    vertical-align: middle;
    text-align: center;
    overflow: hidden;
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    font-weight: normal;
}

.country-main > table:not([align]) td ins.adsbygoogle,
.country-main > table:not([align]) td amp-ad {
    max-width: 100%;
}

/* Non-card images with inline height (e.g. comparison tables) — preserve aspect ratio.
   Inline style="height:240px" + base.css max-width:100% squishes images when cell is
   narrower than natural width. Remove max-width cap so table auto-layout distributes
   column widths proportionally based on each image's natural aspect ratio. */
.country-main > table:not([align]) td > a > img:not(.slist),
.country-main > table:not([align]) td > img:not(.slist) {
    max-width: none;
    width: auto;
}

/* Remove padding/gaps from cells that only contain an image link (e.g. postmark grids) */
.country-main > table:not([align]) td:has(> a > img:not(.slist)):not(:has(br)) {
    padding: 0;
    line-height: 0;
    font-size: 0;
}
.country-main > table:not([align]) td:has(> a > img:not(.slist)):not(:has(br)) img:not([style*="height"]) {
    width: 100%;
    height: auto;
}

/* Link styling now in common-style.css via .legacy-content */

/* Float table images — consistent with Year/2025 */
.country-main table[align="right"] td img[height],
.country-main table[align="left"] td img[height] {
    height: 280px;
    width: auto;
    object-fit: contain;
}

/* Image captions in float tables — tight above, breathing room below */
.country-main table[align="right"] small,
.country-main table[align="left"] small {
    padding-top: 0;
    padding-bottom: 0.5rem;
}

/* ===== TABLE OF CONTENTS =====
 * Floating TOC FAB + popup styles in css/components/toc-fab.css
 */

/* ===== AD CONTAINER ===== */
.ad-container {
    margin: var(--space-6) 0;
    text-align: center;
    min-height: 100px;
}

/* ===== RESPONSIVE STYLES ===== */
@media (max-width: 1024px) {
    /* Stack sidebar TOC + video vertically on tablets */
    .country-sidebar {
        flex-direction: column;
    }

    .sidebar-video {
        flex: 0 0 auto;
        width: 100%;
        max-width: 475px;
    }

    .country-hero__content {
        flex-direction: column;
        text-align: center;
    }

    .country-hero__stats {
        margin-left: 0;
        justify-content: center;
    }

    /* Unfloat image tables on tablets */
    .country-main table[align="right"],
    .country-main table[align="left"] {
        float: none;
        margin: 1rem 0;
        width: 100%;
        max-width: 100%;
    }

    .country-main table[align="right"] img,
    .country-main table[align="left"] img {
        max-width: 100%;
    }

    .country-main table[align="right"] small,
    .country-main table[align="left"] small {
        text-align: center;
    }
}

@media (max-width: 768px) {
    .country-hero {
        padding: var(--space-4) 0;
    }

    .country-hero__title {
        font-size: var(--font-size-2xl);
    }

    .country-hero__subtitle {
        font-size: var(--font-size-base);
    }

    .country-hero__flag {
        font-size: 3rem;
    }

    .country-hero__flag img {
        height: 45px;
    }

    .stamp-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .stamp-item__content {
        padding: var(--space-2);
    }

    .country-section__title {
        font-size: var(--font-size-lg);
    }

    .year-section__badge {
        min-width: 50px;
        font-size: var(--font-size-base);
    }

    .postmarks-grid,
    .stationery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Plain stamp/postmark grid tables: horizontal scroll on small screens */
    .country-main > table:not([align]),
    .country-main > h2 + table:not([align]) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .country-main > table:not([align]) tbody {
        display: table;
        width: 100%;
        min-width: 600px;
    }

    /* Headings sized down */
    .country-main h2:not(.column-box__title) {
        font-size: var(--font-size-lg, 1.125rem);
        line-height: 1.3;
    }

    /* Sidebar video responsive */
    .sidebar-video {
        aspect-ratio: 16 / 9;
    }
}

@media (max-width: 480px) {
    .stamp-gallery {
        grid-template-columns: 1fr;
    }

    .country-hero {
        padding: var(--space-3) 0;
    }

    .country-hero__title {
        font-size: var(--font-size-xl);
    }

    .country-hero__stats {
        flex-wrap: wrap;
        gap: var(--space-4);
    }

    .breadcrumb__list {
        font-size: var(--font-size-xs);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .country-sidebar,
    .back-to-top,
    .stamp-item__zoom {
        display: none !important;
    }

    .country-hero {
        background: #faf9f6;
        color: #0a0a0a;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .stamp-gallery {
        grid-template-columns: repeat(3, 1fr);
    }

    .stamp-item {
        break-inside: avoid;
    }
}
