/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-card: #1c2128;
    --border: #30363d;
    --border-light: #484f58;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --accent-muted: #1f6feb33;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --purple: #bc8cff;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --filter-bar-height: 52px;
    --stamp-scale: 1.0;
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    display: flex;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
img { display: block; }
button { cursor: pointer; border: none; background: none; color: var(--text-primary); }
select, input { font-family: inherit; font-size: 0.85rem; }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: transform var(--transition), width var(--transition);
    overflow: hidden;
}
.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo { font-size: 1.2rem; font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 0.4rem; }
.logo-icon { height: 1.4em; width: auto; vertical-align: middle; }
.sidebar-header .sidebar-toggle { display: none; font-size: 1.2rem; }
.nav-links { list-style: none; flex: 1; overflow-y: auto; padding: 0.5rem 0; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-radius: 6px;
    margin: 0 0.5rem;
    transition: all var(--transition);
    text-decoration: none;
}
.nav-link:hover { background: var(--bg-tertiary); color: var(--text-primary); text-decoration: none; }
.nav-link.active { background: var(--accent-muted); color: var(--accent); font-weight: 500; }
.nav-icon { font-size: 1.1rem; width: 1.4rem; text-align: center; }
.nav-divider { height: 1px; background: var(--border); margin: 0.5rem 1rem; }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }
.sidebar-footer .site-credit { font-size: 0.75rem; color: var(--text-muted); }
.sidebar-footer .site-credit a { color: var(--text-muted); text-decoration: none; }
.sidebar-footer .site-credit a:hover { color: var(--accent); }

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: margin-left var(--transition);
}

/* ===== Top Bar ===== */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: 1rem;
    flex-shrink: 0;
}
.topbar .sidebar-toggle { font-size: 1.3rem; }
.page-title { font-size: 1.1rem; font-weight: 600; white-space: nowrap; }
.topbar-controls { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.zoom-control {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-tertiary);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.zoom-control.hidden { display: none; }
.zoom-label { font-size: 0.85rem; }
#zoom-slider { width: 80px; accent-color: var(--accent); cursor: pointer; }
.zoom-value { font-size: 0.75rem; color: var(--text-secondary); min-width: 2.5rem; text-align: center; }
.search-wrapper { position: relative; }
#collection-search {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 0.4rem 0.75rem;
    width: 200px;
    transition: border-color var(--transition);
}
#collection-search:focus { outline: none; border-color: var(--accent); }

/* ===== Filter Bar ===== */
.filter-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.filter-bar:empty { display: none; min-height: 0; padding: 0; }

.filter-row-primary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    flex-wrap: wrap;
}

.filter-row-detail {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1.25rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--border);
}

.filter-row-detail .filter-group {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    flex: 1;
}

.filter-row-detail .filter-actions {
    display: flex;
    gap: 0.35rem;
    margin-left: auto;
}

.filter-bar .filter-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
    max-width: 180px;
}
.filter-bar .filter-select:focus { outline: none; border-color: var(--accent); }

.filter-bar .filter-select option.no-matches {
    color: #666;
}

.filter-bar .clear-btn {
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.filter-bar .clear-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.filter-bar .clear-btn:disabled { opacity: 0.4; cursor: default; }

.filter-bar .permalink-btn {
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    cursor: pointer;
}
.filter-bar .permalink-btn:hover { border-color: var(--accent); color: var(--accent); }

.filter-count {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

/* ===== Content ===== */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}
.loading { text-align: center; padding: 3rem; color: var(--text-muted); }

/* ===== Period Header ===== */
.period-header {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin: 1.25rem 0 0.75rem 0;
    position: relative;
}
.period-header:first-child { margin-top: 0; }
.period-header .period-title {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-primary);
}
.period-header .period-title a {
    color: inherit;
    text-decoration: none;
}
.period-header .period-title a:hover {
    color: var(--accent);
}
.period-header .period-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}
.period-header .period-subtitle .unofficial { color: var(--danger); font-weight: 600; }
.period-header .cross-link {
    position: absolute;
    top: 0.6rem;
    right: 0.75rem;
    font-size: 0.72rem;
}
.period-header .cross-link a {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid rgba(88,166,255,0.3);
    text-decoration: none;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.period-header .cross-link a:hover {
    background: var(--accent);
    color: var(--bg-primary);
}

/* ===== Emission Header ===== */
.emission-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.4rem 0;
    margin: 0.75rem 0 0.4rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.emission-header .complete-badge {
    font-size: 0.65rem;
    color: var(--success);
    background: rgba(63,185,80,0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 8px;
    border: 1px solid rgba(63,185,80,0.3);
    vertical-align: super;
}
.emission-continued {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-muted);
    padding: 0.3rem 0;
    margin-bottom: 0.4rem;
}

/* ===== Stamp Grid ===== */
.stamp-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.stamp-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: opacity var(--transition);
}
.stamp-card.faded { opacity: 0.25; }
.stamp-card.wanted {
    border: 2px dashed var(--accent);
    background: var(--bg-secondary);
}
.wanted-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent);
    background: rgba(0, 0, 0, 0.6);
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    letter-spacing: 0.1em;
    pointer-events: none;
    z-index: 1;
}
.wanted-badge {
    color: var(--accent);
    font-weight: 600;
    border: 1px dashed var(--accent);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85rem;
}
.stamp-card .stamp-img-wrap {
    cursor: pointer;
    position: relative;
}
.stamp-card .stamp-img-wrap img {
    /* Divide viewport cap by zoom so the zoomed result fits the content area.
       Normal images stay at natural size; only oversized ones get constrained. */
    max-width: calc((100vw - 280px) / var(--stamp-scale, 1));
    height: auto;
    zoom: var(--stamp-scale);
    border-radius: 2px;
    transition: transform 0.15s ease;
}
.stamp-card .stamp-img-wrap img:hover { transform: scale(1.05); }
.stamp-card .stamp-info {
    margin-top: 0.3rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.stamp-card .stamp-info .catalog-hint {
    cursor: help;
    border-bottom: 1px dotted var(--text-muted);
    color: var(--text-primary);
    font-weight: 500;
}
.stamp-card .stamp-info .stamp-code { color: var(--text-primary); }
.stamp-card .stamp-info .stamp-code.stamp-detail-link { cursor: pointer; color: var(--accent); }
.stamp-card .stamp-info .stamp-code.stamp-detail-link:hover { text-decoration: underline; }
.stamp-card .stamp-info .stamp-condition {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.05rem 0.3rem;
    border-radius: 8px;
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid rgba(88,166,255,0.3);
}
.stamp-card .stamp-info .stamp-value { color: var(--success); font-weight: 500; }
.stamp-card .stamp-info .stamp-value.no-value { color: var(--text-muted); font-style: italic; }
.stamp-card .stamp-info .stamp-counter { color: var(--warning); font-weight: 600; }
.stamp-card .stamp-info .stamp-detail-link {
    cursor: pointer;
    font-size: 0.8rem;
}
.stamp-card .stamp-info .stamp-more-link { color: var(--purple); font-size: 0.7rem; }
.stamp-card .stamp-info .country-link { font-weight: 600; color: var(--accent); font-size: 0.72rem; }

/* ===== Swap Selection ===== */
.stamp-card[data-swap-path] { border-left: 3px solid transparent; }
.stamp-card[data-swap-path] .stamp-img-wrap { position: relative; }
.swap-checkbox {
    position: absolute; top: 2px; left: 2px; z-index: 3;
    cursor: pointer; font-size: 1.2rem; line-height: 1;
    color: #ccc; user-select: none;
    background: rgba(0, 0, 0, 0.55); border-radius: 3px;
    padding: 1px 3px;
}
.swap-checkbox:hover { color: #fff; background: rgba(0, 0, 0, 0.75); }
.stamp-card.swap-selected {
    border-left-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--bg-tertiary));
}
.stamp-card.swap-selected .swap-checkbox { color: var(--accent); }

#swap-action-bar {
    position: fixed; bottom: 0; left: var(--sidebar-width); right: 0;
    background: var(--bg-secondary); border-top: 2px solid var(--accent);
    padding: 0.6rem 1.25rem; display: flex; align-items: center; gap: 0.75rem;
    z-index: 50; font-size: 0.85rem;
}
.swap-count { color: var(--accent); font-weight: 600; margin-right: auto; }
.swap-btn {
    padding: 0.35rem 0.75rem; border-radius: 6px; border: 1px solid var(--border);
    cursor: pointer; font-size: 0.8rem; background: var(--bg-tertiary); color: var(--text-primary);
}
.swap-btn:hover { background: var(--accent); color: #fff; }
.swap-btn-clear { border-color: var(--danger, #e55); color: var(--danger, #e55); }
.swap-btn-clear:hover { background: var(--danger, #e55); color: #fff; }
.swap-btn-view { border-color: var(--accent); color: var(--accent); }
.swap-btn-view:hover { background: var(--accent); color: #fff; }
.main-content.has-action-bar { padding-bottom: 3rem; }

/* ===== Swap Summary Modal ===== */
.swap-summary h3 { margin: 0 0 1rem; font-size: 1rem; color: var(--text-primary); }
.swap-summary-entity {
    font-weight: 700; font-size: 0.8rem; color: var(--accent);
    padding: 0.5rem 0 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 0.4rem;
}
.swap-summary-list { max-height: 60vh; overflow-y: auto; }
.swap-summary-item {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.4rem 0; border-bottom: 1px solid var(--border);
}
.swap-summary-thumb { width: 40px; height: auto; flex-shrink: 0; border-radius: 2px; }
.swap-summary-info { flex: 1; font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; }
.swap-summary-code { color: var(--text-primary); font-weight: 500; }
.swap-summary-emission { color: var(--text-muted); font-size: 0.7rem; font-style: italic; }
.swap-summary-remove {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 0.9rem; padding: 0.2rem 0.4rem; flex-shrink: 0;
}
.swap-summary-remove:hover { color: var(--danger, #e55); }
.swap-summary-link {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 0.8rem; padding: 0.2rem 0.4rem; flex-shrink: 0;
}
.swap-summary-link:hover { color: var(--accent); }
.detail-actions { margin-top: 0.8rem; text-align: right; }
.detail-copy-link {
    background: none; border: 1px solid var(--border); color: var(--text-secondary);
    cursor: pointer; padding: 0.3rem 0.6rem; border-radius: 4px; font-size: 0.78rem;
}
.detail-copy-link:hover { color: var(--accent); border-color: var(--accent); }
.swap-summary-footer { margin-top: 0.8rem; text-align: right; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.swap-btn-email { border-color: var(--accent); color: var(--accent); }
.swap-btn-email:hover { background: var(--accent); color: #fff; }

/* Swap email confirmation */
.swap-email-confirm {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center;
}
.swap-email-confirm-content {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
    padding: 1.5rem; max-width: 400px; text-align: center;
}
.swap-email-confirm-content h3 { margin: 0 0 0.8rem; color: var(--accent); }
.swap-email-confirm-content p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; margin: 0 0 1rem; }
.swap-email-confirm-actions { display: flex; gap: 0.6rem; justify-content: center; }

/* ===== Compact Grid View ===== */
.stamp-grid.compact { gap: 0.4rem; }

/* ===== Pagination ===== */
.pagination {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    font-size: 0.8rem;
}
.pagination:empty { display: none; }
.pagination .page-info { color: var(--text-secondary); }
.pagination .page-info b { color: var(--text-primary); }
.pagination .page-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.pagination .page-controls button {
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.8rem;
}
.pagination .page-controls button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pagination .page-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-controls select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
}
.pagination .page-totals { color: var(--text-muted); }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    font-size: 1.3rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
}
.modal-close:hover { color: var(--text-primary); background: var(--border); }

/* Detail layout: hero image + metadata side by side */
.modal-body .detail-layout {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-body .detail-hero-img {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}
.modal-body .detail-hero-img img {
    max-height: 250px;
    max-width: 250px;
    object-fit: contain;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid var(--border);
}
.modal-body .detail-meta {
    flex: 1;
    min-width: 0;
}
.modal-body .detail-meta h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 0.75rem 0;
    text-transform: uppercase;
}
.modal-body .detail-meta h2 .detail-country-link {
    color: var(--accent);
    text-decoration: none;
}
.modal-body .detail-meta h2 .detail-country-link:hover { text-decoration: underline; }
.modal-body .meta-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 0.75rem;
    font-size: 0.82rem;
}
.modal-body .meta-row {
    display: contents;
}
.modal-body .meta-label {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    padding-top: 0.1rem;
}
.modal-body .meta-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* Instances sections */
.modal-body .instances-section {
    margin-bottom: 1rem;
}
.modal-body .instances-header {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.modal-body .instances-count {
    display: inline-block;
    background: var(--accent-muted);
    color: var(--accent);
    font-size: 0.68rem;
    padding: 0.1rem 0.4rem;
    border-radius: 8px;
    font-weight: 600;
}
.modal-body .stamp-instances { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.modal-body .stamp-instance {
    text-align: center;
    padding: 0.6rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}
.modal-body .stamp-instance img {
    max-height: 150px;
    width: auto;
    cursor: pointer;
    border-radius: 2px;
}
.modal-body .stamp-instance .instance-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    justify-content: center;
    align-items: center;
}
.modal-body .instance-condition {
    display: inline-block;
    font-size: 0.68rem;
    padding: 0.1rem 0.4rem;
    border-radius: 8px;
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid rgba(88,166,255,0.3);
    font-weight: 500;
}
.modal-body .instance-value {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--success);
}
.modal-body .instance-value.no-val {
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
}
.modal-body .instance-swap {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--warning);
}

/* ===== Lightbox ===== */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 300;
    align-items: center;
    justify-content: center;
}
.lightbox.active { display: flex; }
.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    color: white;
    z-index: 301;
}
#lightbox-img { max-width: 90vw; max-height: 90vh; object-fit: contain; }

/* ===== Country Cards (countries/colonies view) ===== */
.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.75rem;
}
.country-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    transition: border-color var(--transition);
}
.country-card:hover { border-color: var(--accent); }
.country-card .country-name { font-weight: 600; font-size: 0.9rem; }
.country-card .country-parent { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.country-card .country-counts { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.25rem; }
.country-card .country-dates { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }
.country-card .country-periods { font-size: 0.7rem; color: var(--text-secondary); opacity: 0.7; margin-top: 0.15rem; }
.continent-section { margin-bottom: 1.5rem; }
.continent-section.collapsed .country-grid { display: none; }
.continent-section h3 .continent-count { font-weight: 400; font-size: 0.8rem; opacity: 0.7; }
.continent-header {
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 0.6rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}
.continent-header::before {
    content: "▾ ";
    font-size: 0.75rem;
}
.continent-section.collapsed .continent-header::before {
    content: "▸ ";
}
.continent-section.collapsed .continent-header {
    margin-bottom: 0;
    border-bottom: none;
}

/* ===== Stamp Issuers ===== */
.stamp-issuers .detail-hero {
    margin-bottom: 1.25rem;
}
.stamp-issuers .detail-hero h2 {
    font-size: 1.6rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-primary);
    margin: 0;
}
.stamp-issuers .detail-hero .detail-subtitle {
    margin-top: 0.3rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.stamp-issuers .detail-hero .detail-subtitle a {
    color: var(--accent);
}
.stamp-issuers .detail-hero .detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.stamp-issuers .detail-action-btn {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--transition);
}
.stamp-issuers .detail-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.stamp-issuers .detail-action-btn.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* Tracking stats */
.stamp-issuers .tracking-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.stamp-issuers .tracking-stat {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.78rem;
    background: var(--accent-muted);
    color: var(--text-secondary);
    border: 1px solid rgba(88,166,255,0.2);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}
.stamp-issuers .tracking-stat:hover {
    background: var(--accent);
    color: #fff;
}

/* History table */
.stamp-issuers .history-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.stamp-issuers .history-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: center;
    font-weight: 500;
    width: 33.33%;
}
.stamp-issuers .history-table td {
    padding: 0.6rem 0.75rem;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}
.stamp-issuers .history-table td:first-child { border-radius: 8px 0 0 8px; }
.stamp-issuers .history-table td:last-child { border-radius: 0 8px 8px 0; }
.stamp-issuers .history-table td.current-cell {
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-secondary);
}
.stamp-issuers .history-table a { color: var(--accent); text-decoration: none; }
.stamp-issuers .history-table a:hover { text-decoration: underline; }

/* Political row — side by side */
.stamp-issuers .political-row {
    margin-bottom: 1.25rem;
}
.stamp-issuers .political-block {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.stamp-issuers .political-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    user-select: none;
}
.stamp-issuers .political-header:hover { background: var(--bg-secondary); }
.stamp-issuers .political-label {
    padding: 0.55rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.stamp-issuers .political-header .chevron {
    color: var(--text-muted);
    font-size: 0.65rem;
    transition: transform 0.2s ease;
}
.stamp-issuers .political-block.open .political-header .chevron {
    transform: rotate(90deg);
}
.stamp-issuers .political-body {
    display: none;
    padding: 0.5rem 0.85rem 0.65rem;
    border-top: 1px solid var(--border);
}
.stamp-issuers .political-block.open .political-body {
    display: block;
}
.stamp-issuers .tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.stamp-issuers .tag {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    font-size: 0.78rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.stamp-issuers .tag a { color: var(--accent); text-decoration: none; }
.stamp-issuers .tag a:hover { text-decoration: underline; }
.stamp-issuers .tag .tag-note {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-left: 0.2rem;
}
.stamp-issuers .none-text {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Periods table */
.stamp-issuers .periods-section {
    margin-bottom: 1.5rem;
}
.stamp-issuers .periods-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 0.6rem 0;
}
.stamp-issuers .periods-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.stamp-issuers .periods-table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
}
.stamp-issuers .periods-table th.num,
.stamp-issuers .periods-table td.num {
    text-align: center;
    width: 5rem;
}
.stamp-issuers .periods-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.stamp-issuers .periods-table td.period-name {
    font-weight: 600;
    color: var(--text-primary);
}
.stamp-issuers .periods-table td.period-note {
    font-size: 0.78rem;
    color: var(--text-muted);
}
.stamp-issuers .periods-table td a {
    color: var(--accent);
    text-decoration: none;
}
.stamp-issuers .periods-table td a:hover {
    text-decoration: underline;
}
.stamp-issuers .periods-table td .zero {
    color: var(--text-muted);
    opacity: 0.4;
}

/* ===== Timeline Chart ===== */
.chart-wrapper {
    position: relative;
    overflow-x: auto;
    margin: 1rem 0;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 1rem;
    --height: 200px;
}
.chart-wrapper .chart-values {
    list-style: none;
    display: flex;
    position: relative;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}
.chart-wrapper .chart-values li {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
    text-align: left;
    position: relative;
}
.chart-wrapper .chart-values li::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 0;
    width: 1px;
    height: var(--height);
    background: var(--border);
    opacity: 0.3;
}
.chart-wrapper .chart-bars {
    list-style: none;
    position: relative;
}
.chart-wrapper .chart-bars li {
    position: relative;
    height: 22px;
    margin: 3px 0;
    background: var(--accent-muted);
    border: 1px solid var(--accent);
    border-radius: 3px;
    font-size: 0.68rem;
    color: var(--text-primary);
    line-height: 22px;
    padding: 0 0.4rem;
    white-space: nowrap;
    overflow: visible;
    transition: background var(--transition);
}
.chart-wrapper .chart-bars li:hover {
    background: rgba(88,166,255,0.25);
}
.chart-wrapper .chart-bars li[data-open-end] {
    border-right: none;
    mask-image: linear-gradient(to right, black 70%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 70%, transparent 100%);
}
.chart-wrapper .chart-bars li a {
    color: inherit;
    text-decoration: none;
    display: block;
}
.chart-wrapper .chart-undated {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.chart-wrapper .chart-undated-entry {
    font-size: 0.72rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px dashed var(--border-light);
    border-radius: 3px;
    padding: 0.2rem 0.5rem;
}
.chart-wrapper .chart-undated-entry a {
    color: var(--text-secondary);
    text-decoration: none;
}
.chart-wrapper .chart-undated-entry a:hover {
    color: var(--accent);
}

/* ===== Values View ===== */
.values-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.values-table th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
}
.values-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
.values-table tr:hover { background: var(--bg-tertiary); }
.values-table .rank { color: var(--text-muted); font-weight: 600; }
.values-table .value-cell { color: var(--success); font-weight: 500; }
.values-totals {
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    display: flex;
    gap: 2rem;
}
.values-totals .total-item span { color: var(--success); font-weight: 600; }

/* ===== Firsts View ===== */
.firsts-section { margin-bottom: 1.5rem; }
.firsts-section h3 {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

/* ===== Thematics View ===== */
.thematic-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--purple);
    margin: 1.25rem 0 0.5rem 0;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
}

/* ===== About View ===== */
.about-section { margin-bottom: 1.5rem; }
.about-section h3 {
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.about-section p, .about-section li { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.about-section ul { list-style: disc; padding-left: 1.5rem; }
.about-section a { color: var(--accent); text-decoration: none; }
.about-section a:hover { text-decoration: underline; }
/* Help page */
.help-page { max-width: 720px; }
.help-section { margin-bottom: 1.5rem; }
.help-section h3 { font-size: 0.95rem; color: var(--accent); margin-bottom: 0.5rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); }
.help-section p, .help-section li { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; }
.help-section ul, .help-section ol { padding-left: 1.5rem; margin: 0.4rem 0; }
.help-section ul { list-style: disc; }
.help-section ol { list-style: decimal; }
.help-section code { background: var(--bg-card); border: 1px solid var(--border); border-radius: 3px; padding: 0.1rem 0.35rem; font-size: 0.8rem; }
.about-text { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.8; white-space: pre-line; }
.about-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
}
.about-stats .stat-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
}
.about-stats .stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.about-stats .stat-card .stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ===== Period Chips ===== */
.period-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.3rem;
    width: 100%;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    padding-bottom: 0.3rem;
    border-top: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.period-chip {
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.72rem;
    cursor: pointer;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
}
.period-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.period-chip.active {
    background: var(--accent-muted);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
}
.period-chip.related-toggle {
    border-style: dashed;
    color: var(--text-muted);
    font-style: italic;
}
.period-chip.related-chip { border-color: var(--purple); color: var(--purple); }
.period-chip.related-chip.active { background: rgba(163,113,247,0.15); border-color: var(--purple); color: var(--purple); }
.period-chip.hidden { display: none; }

/* ===== Wanted List ===== */
.wanted-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.2rem 1rem;
    margin-bottom: 0.75rem;
}
.wanted-item {
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-left: 2px solid var(--border);
}

/* ===== Wanted View ===== */
.wanted-stamp {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.4rem;
    opacity: 0.7;
}
.wanted-stamp .stamp-info { font-size: 0.72rem; color: var(--text-secondary); }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: var(--bg-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    z-index: 400;
    animation: fadeInOut 2s ease;
}
@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
    15% { opacity: 1; transform: translateX(-50%) translateY(0); }
    85% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ===== Collapsed Sidebar (Desktop) ===== */
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .logo { font-size: 1.2rem; justify-content: center; }
.sidebar.collapsed .logo-text { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 0.55rem; margin: 0 0.25rem; }
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .nav-icon { margin: 0; }
.sidebar.collapsed .nav-divider { margin: 0.5rem 0.5rem; }
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar.collapsed ~ .main-content { margin-left: 56px; }
.sidebar.collapsed ~ .main-content #swap-action-bar { left: 56px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-header .sidebar-toggle { display: block; }
    .main-content { margin-left: 0; }
    .sidebar.collapsed ~ .main-content { margin-left: 0; }
    #global-search { width: 140px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
