/* ═══════════════════════════════════════════════════════════════════
   PeeringDB Frontend — Design System
   Dark-mode, data-dense layout optimised for network operations data.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Reset & base ──────────────────────────────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Skip navigation ───────────────────────────────────────────── */

.skip-nav {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    z-index: 10000;
    padding: var(--space-sm) var(--space-md);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: top var(--transition-fast);
}

.skip-nav:focus {
    top: var(--space-sm);
}

/* ── Focus indicators ──────────────────────────────────────────── */

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Remove outline for mouse clicks but keep for keyboard */
:focus:not(:focus-visible) {
    outline: none;
}

:root {
    /* Neutrals (dark) */
    --bg-body:    hsl(220 14% 8%);
    --bg-surface: hsl(220 14% 12%);
    --bg-card:    hsl(220 14% 14%);
    --bg-hover:   hsl(220 14% 18%);
    --bg-input:   hsl(220 14% 10%);
    --border:     hsl(220 10% 22%);
    --border-subtle: hsl(220 10% 18%);

    /* Striped table rows */
    --bg-stripe:  hsl(220 14% 11%);

    /* Error message block */
    --error-bg:     hsl(0 30% 15%);
    --error-border: hsl(0 40% 25%);

    /* Text */
    --text-primary:   hsl(220 14% 90%);
    --text-secondary: hsl(220 10% 62%);
    --text-muted:     hsl(220 10% 45%);

    /* Accent */
    --accent:       hsl(200 80% 55%);
    --accent-hover: hsl(200 80% 65%);
    --accent-muted: hsl(200 40% 30%);

    /* Status */
    --status-ok:      hsl(145 60% 45%);
    --status-warn:    hsl(40 90% 55%);
    --status-error:   hsl(0 70% 55%);

    /* Entity-type accent colours */
    --type-net:     var(--accent);          /* blue — networks (same as accent) */
    --type-ix:      hsl(160 65% 45%);   /* teal — exchanges      */
    --type-fac:     hsl(35 85% 55%);    /* amber — facilities    */
    --type-org:     hsl(270 55% 60%);   /* purple — orgs         */
    --type-campus:  hsl(330 60% 55%);   /* pink — campuses       */
    --type-carrier: hsl(95 55% 48%);    /* green — carriers      */
    --type-asn:     hsl(45 90% 55%);    /* gold — ASN lookups    */

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px hsl(0 0% 0% / 0.3);
    --shadow-md: 0 2px 8px hsl(0 0% 0% / 0.25);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Layout */
    --content-max: 1280px;
    --sidebar-width: 340px;
    --header-height: 56px;
}

/* ── Light theme ──────────────────────────────────────────────── */
/* Applied via data-theme="light" attribute on <html>.            */

:root[data-theme="light"] {
    /* Neutrals */
    --bg-body:    hsl(220 14% 97%);
    --bg-surface: hsl(220 14% 94%);
    --bg-card:    hsl(0 0% 100%);
    --bg-hover:   hsl(220 14% 90%);
    --bg-input:   hsl(220 14% 96%);
    --border:     hsl(220 10% 82%);
    --border-subtle: hsl(220 10% 88%);

    /* Text (darker for legibility on white — WCAG AA 4.5:1 minimum) */
    --text-primary:   hsl(220 20% 10%);
    --text-secondary: hsl(220 10% 36%);
    --text-muted:     hsl(220 10% 42%);

    /* Accent (darker for readable contrast on white) */
    --accent:       hsl(200 80% 40%);
    --accent-hover: hsl(200 80% 32%);
    --accent-muted: hsl(200 40% 80%);

    /* Status (darkened for white backgrounds) */
    --status-ok:      hsl(145 60% 35%);
    --status-warn:    hsl(35 85% 42%);
    --status-error:   hsl(0 70% 48%);

    /* Entity-type accent colours (darkened for contrast) */
    --type-net:     var(--accent);
    --type-ix:      hsl(160 65% 35%);
    --type-fac:     hsl(35 85% 42%);
    --type-org:     hsl(270 55% 48%);
    --type-campus:  hsl(330 60% 45%);
    --type-carrier: hsl(95 55% 36%);
    --type-asn:     hsl(45 85% 42%);

    /* Shadows (softer for light BG) */
    --shadow-sm: 0 1px 2px hsl(220 10% 50% / 0.12);
    --shadow-md: 0 2px 8px hsl(220 10% 50% / 0.1);

    --bg-stripe:  hsl(220 14% 94%);
    --error-bg:     hsl(0 80% 96%);
    --error-border: hsl(0 50% 82%);
}

/* Light-mode font rendering: heavier weight to compensate for
   Inter's thin strokes on white, and subpixel AA for crispness. */
:root[data-theme="light"] body {
    font-weight: 450;
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    letter-spacing: -0.006em;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* ── Header ────────────────────────────────────────────────────── */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--space-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.site-header__inner {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    flex-wrap: wrap;
}

.site-logo {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    letter-spacing: -0.02em;
    transform: scaleX(-1);
}

.site-logo span {
    color: var(--accent);
}

/* Homepage header: larger centered logo, no search bar */
body[data-page="home"] .search-wrapper {
    display: none;
}

body[data-page="home"] .site-header__inner {
    justify-content: space-between;
}

body[data-page="home"] .site-logo {
    font-size: 1.5rem;
}

/* ── Header nav / auth UI ─────────────────────────────────────── */

.site-header__nav {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: auto;
    white-space: nowrap;
}

/* ── Stats ticker — compact entity counts below header ───────── */

.stats-ticker {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.25rem var(--space-md);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.6875rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow-x: auto;
}

.stats-ticker:empty {
    display: none;
}

.stats-ticker__item strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.stats-ticker__sep {
    color: var(--border);
}

.stats-ticker__link {
    color: inherit;
    text-decoration: none;
}

.stats-ticker__link:hover,
.stats-ticker__link:focus-visible {
    color: var(--accent);
    text-decoration: underline;
}

.auth-container {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8125rem;
}

/* Bordered pill button — used in account page modals and forms */
.auth-link {
    font-size: 0.75rem;
    color: var(--accent);
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.auth-link:hover {
    background: var(--bg-hover);
    border-color: var(--accent-muted);
    color: var(--accent-hover);
}


.header-nav-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast),
                background var(--transition-fast),
                border-color var(--transition-fast);
}

.header-nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--accent-muted);
}

/* ── API Key modal ─────────────────────────────────────────────── */

.key-modal-overlay {
    position: fixed;
    inset: 0;
    background: hsl(0 0% 0% / 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.key-modal {
    max-width: 520px;
    width: 90%;
}

/* ── Generic modal (API access, etc.) ─────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: hsl(0 0% 0% / 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal-card {
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.modal-card__title {
    font-weight: 600;
    color: var(--text-primary);
}

.modal-card__close {
    background: none;
    border: none;
    padding: var(--space-xs);
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-card__close:hover {
    color: var(--accent);
}

.modal-card__body {
    padding: var(--space-lg);
}

/* Labelled read-only value + copy button (API modal) */
.copy-block {
    margin-bottom: var(--space-lg);
}

.copy-block:last-child {
    margin-bottom: 0;
}

.copy-block__label {
    margin-bottom: var(--space-xs);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.copy-block__row {
    display: flex;
    align-items: stretch;
    gap: var(--space-sm);
}

.copy-block__value {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8125rem;
    color: var(--accent);
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
}

.copy-block__btn {
    flex: 0 0 auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 var(--space-sm);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.copy-block__btn:hover {
    border-color: var(--accent-muted);
}

.api-modal__note {
    margin: var(--space-md) 0 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Toast (brief clipboard confirmations, etc.) ──────────────────── */
.toast-host {
    position: fixed;
    left: 50%;
    bottom: var(--space-xl);
    transform: translateX(-50%);
    z-index: 11000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    padding: var(--space-sm) var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-primary);
    box-shadow: 0 4px 16px hsl(0 0% 0% / 0.3);
    animation: fadeIn 0.15s ease-out;
}

.toast--out {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.key-display {
    display: block;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8125rem;
    color: var(--accent);
    word-break: break-all;
    user-select: all;
}

.td-mono {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.key-label-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast);
}

.key-label-input:focus {
    border-color: var(--accent);
}

.key-label-input::placeholder {
    color: var(--text-muted);
}

/* ── Search ────────────────────────────────────────────────────── */

.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 560px;
}

.search-input {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-md) 0 2.25rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-muted);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 400px;
    overflow-y: auto;
    z-index: 200;
}

.search-dropdown.is-open {
    display: block;
}

.search-dropdown__group {
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.search-dropdown__group:last-child {
    border-bottom: none;
}

.search-dropdown__label {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.search-dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    font-size: 0.8125rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-dropdown__item:hover,
.search-dropdown__item.is-active {
    background: var(--bg-hover);
}

.search-dropdown__item a {
    color: var(--accent);
    text-decoration: none;
}

.search-dropdown__item a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

.search-dropdown__item-sub {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-left: auto;
}

/* ── Main content ──────────────────────────────────────────────── */

.main-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

/* ── Page transitions ──────────────────────────────────────────── */

.page-enter {
    opacity: 0;
    transform: translateY(4px);
}

.page-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

/* ── Cards ─────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
}

.card__title {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.card__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.25rem;
    padding: 0 var(--space-xs);
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: 100px;
    background: var(--accent-muted);
    color: var(--accent);
}

.card__body {
    padding: var(--space-lg);
}

/* ── Account page layout ──────────────────────────────────────── */

.account-top {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: var(--space-xl);
    align-items: start;
    margin-bottom: var(--space-xl);
}

.account-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    min-width: 0;
}

/* ── Detail page layout ───────────────────────────────────────── */

.detail-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: var(--space-xl);
    align-items: start;
}

.detail-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.detail-header__title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.detail-header__subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.detail-header__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.detail-header__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-xs) var(--space-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.detail-header__btn:hover {
    color: var(--accent);
    border-color: var(--accent-muted);
}

.detail-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.detail-sidebar__logo {
    max-width: 100%;
    max-height: 80px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: #fff;
    padding: 6px;
    align-self: flex-start;
}

:root[data-theme="light"] .detail-sidebar__logo {
    background: transparent;
    border-color: transparent;
}

.detail-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    min-width: 0; /* prevent table overflow */
}

/* ── Info fields (sidebar) ─────────────────────────────────────── */

.info-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.info-group__title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.info-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.info-field__label {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.info-field__value {
    font-size: 0.875rem;
    color: var(--text-primary);
    word-break: break-word;
}

.info-field__value--muted {
    color: var(--text-secondary);
}

/* ── Stats bar ─────────────────────────────────────────────────── */

.stats-bar {
    display: flex;
    gap: var(--space-lg);
    padding: var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-top: var(--space-xl);
    justify-content: center;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 120px;
    padding: var(--space-sm) var(--space-lg);
}

.stat-card__icon {
    font-size: 1.25rem;
    line-height: 1;
    opacity: 0.7;
}

.stat-card__value {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--accent);
}

.stat-card__label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* ── Data tables ───────────────────────────────────────────────── */

.data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    letter-spacing: -0.01em;
}

.data-table td {
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-fast);
}

.data-table th:hover {
    color: var(--text-secondary);
}

.data-table th[data-sort-dir="asc"]::after {
    content: " ▲";
    font-size: 0.5625rem;
}

.data-table th[data-sort-dir="desc"]::after {
    content: " ▼";
    font-size: 0.5625rem;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.data-table tr:nth-child(even) td {
    background: var(--bg-stripe);
}

.data-table tr:nth-child(even):hover td {
    background: var(--bg-hover);
}

.data-table td.td-wrap {
    white-space: normal;
    max-width: 300px;
}

.data-table td.td-mono {
    font-size: 0.75rem;
    letter-spacing: 0;
}

.ip-stack {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 0.6875rem;
    line-height: 1.3;
}

.data-table td.td-right {
    text-align: right;
}

/* Boolean / status indicators */
.bool-yes {
    color: var(--status-ok);
    font-weight: 600;
}

.bool-no {
    color: var(--text-muted);
}

/* ── Table filter ──────────────────────────────────────────────── */

.table-filter {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.table-filter__input {
    height: 28px;
    padding: 0 var(--space-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.75rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.table-filter__input:focus {
    border-color: var(--accent);
}

/* ── Column toggle dropdown ──────────────────────────────────── */

.col-toggle {
    position: relative;
}

.col-toggle__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: border-color var(--transition-fast), color var(--transition-fast);
}

.col-toggle__btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.col-toggle__menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    min-width: 140px;
    margin-top: 4px;
    padding: var(--space-xs) 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.col-toggle__menu.is-open {
    display: block;
}

.col-toggle__item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 8px var(--space-sm); /* increased for mobile touch targets */
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.col-toggle__item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.col-toggle__item input[type="checkbox"] {
    margin: 0;
}

/* ── Table pagination ─────────────────────────────────────────── */

.table-paging {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
}

.table-paging__btn {
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.table-paging__btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.table-paging__btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.table-paging__info {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Homepage layout ───────────────────────────────────────────── */

.home-heading {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
    padding: var(--space-lg) 0 var(--space-md);
    color: var(--text-primary);
}

.home-top {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: var(--space-2xl);
    margin-bottom: var(--space-xl);
}

.home-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* ── Hero section (left pane) ──────────────────────────────────── */

.home-hero__tagline {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-md);
    color: var(--text-primary);
}

.home-hero__desc {
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.home-hero__desc:last-child {
    margin-bottom: 0;
}

/* ── Recent updates ────────────────────────────────────────────── */

.home-recent {
    margin-bottom: var(--space-xl);
}

.home-recent__heading {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
}

.home-recent__heading--link {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.home-recent__heading--link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ── Homepage search ───────────────────────────────────────────── */

.home-search {
    padding: var(--space-sm) 0;
}

.home-search__input-wrapper {
    position: relative;
}

.home-search__input {
    width: 100%;
    height: 48px;
    padding: 0 var(--space-lg) 0 3rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.home-search__input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

/* ── Recent updates grid ───────────────────────────────────────── */

.recent-updates {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
}

.recent-updates__column {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 300px;
}

.recent-updates__title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--border);
    margin-bottom: var(--space-sm);
}

/* Colour the column border to match its entity type */
.recent-updates__title:has([data-type="ix"])      { border-color: var(--type-ix); }
.recent-updates__title:has([data-type="net"])     { border-color: var(--type-net); }
.recent-updates__title:has([data-type="fac"])     { border-color: var(--type-fac); }
.recent-updates__title:has([data-type="carrier"]) { border-color: var(--type-carrier); }

.recent-updates__item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-xs) 0;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--border-subtle);
}

.recent-updates__item a {
    overflow-wrap: break-word;
    word-break: break-word;
}

.recent-updates__item:last-child {
    border-bottom: none;
}

.recent-updates__time {
    font-size: 0.6875rem;
    color: var(--text-muted);
}


/* ── Search results page ───────────────────────────────────────── */

.search-results {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.search-results__heading {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.search-results__heading strong {
    color: var(--text-primary);
}

.search-results__section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.search-results__section-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.search-results__mode-toggle {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    margin-top: calc(-1 * var(--space-sm));
    transition: color var(--transition-fast);
}

.search-results__mode-toggle:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.search-results__mode-badge {
    display: inline-block;
    margin-left: var(--space-sm);
    padding: 2px var(--space-xs);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--accent-muted);
    color: var(--accent);
    border-radius: var(--radius-sm);
    vertical-align: middle;
}

/* ── Footer ────────────────────────────────────────────────────── */

.site-footer {
    padding: var(--space-xl) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.site-footer__grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: var(--space-xl);
    max-width: var(--content-max);
    margin: 0 auto;
}

.site-footer__col {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.site-footer__copyright {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.site-footer__copyright a {
    color: var(--text-secondary);
}

.site-footer__sync-line {
    margin-top: var(--space-sm);
}

.site-footer__sync {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.site-footer__sync-time {
    color: var(--text-secondary);
}

.site-footer__sync-time--ok {
    color: var(--status-ok);
}

.site-footer__sync-time--warn {
    color: var(--status-warn);
}

.site-footer__sync-time--error {
    color: var(--status-error);
    font-weight: 600;
}

.site-footer__lang-line {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
}

.site-footer__lang-label {
    font-size: 0.75rem;
    cursor: pointer;
}

.site-footer__lang-select {
    width: 80%;
    height: 22px;
    padding: 0 4px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.6875rem;
    text-align: right;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.site-footer__lang-select:focus {
    border-color: var(--accent);
}

.site-footer__lang-select:hover {
    color: var(--text-primary);
}

.site-footer__heading {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.site-footer__links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.site-footer__links li {
    padding: 2px 0;
}

.site-footer__links a {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

.site-footer__links a:hover {
    color: var(--accent-hover);
}

/* ── About page ────────────────────────────────────────────────── */

/* Deep-linked sections (/about#using-the-api) must clear the sticky header. */
.about-page [id] {
    scroll-margin-top: calc(var(--header-height) + var(--space-md));
}

.about-page {
    max-width: 720px;
}

.about-page__title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-xl);
}

.about-page__section {
    margin-bottom: var(--space-xl);
}

.about-page__section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.about-page__section p {
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.about-page__section p:last-child {
    margin-bottom: 0;
}

.about-page__code {
    display: block;
    padding: var(--space-md);
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8125rem;
    color: var(--accent);
    overflow-x: auto;
    margin-bottom: var(--space-md);
}

.about-page__code code {
    font-family: inherit;
}

/* ── Loading / error states ────────────────────────────────────── */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

.loading::after {
    content: "";
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: var(--space-sm);
}

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

.error-message {
    padding: var(--space-lg);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: var(--radius-md);
    color: var(--status-error);
    font-size: 0.875rem;
}

.empty-state {
    padding: var(--space-2xl);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ── Skeleton placeholders ─────────────────────────────────────── */

.skeleton {
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-hover) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton--text {
    height: 0.875rem;
    width: 60%;
    margin-bottom: var(--space-xs);
}

.skeleton--block {
    height: 2rem;
    width: 100%;
    margin-bottom: var(--space-sm);
}

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

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .detail-layout {
        grid-template-columns: 1fr;
    }

    .compare-grid {
        grid-template-columns: 1fr;
    }

    .account-top {
        grid-template-columns: 1fr;
    }

    .home-top {
        grid-template-columns: 1fr;
    }

    .recent-updates {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-bar {
        flex-wrap: wrap;
    }

    .site-footer__grid {
        grid-template-columns: 1fr 1fr;
    }

    .site-header {
        padding: var(--space-sm) var(--space-md);
    }

    /* Two-row header on mobile:
       Row 1: logo (order 1) + nav/auth (order 2)
       Row 2: search bar full-width (order 3) */
    .site-header__inner {
        gap: var(--space-sm);
    }

    .site-logo {
        order: 1;
    }

    .site-header__nav {
        order: 2;
        gap: var(--space-xs);
    }

    .search-wrapper {
        order: 3;
        flex: 1 0 100%;
        max-width: none;
    }

    /* On mobile the dropdown must break out of the sticky header's
       stacking context so it overlays main content. Use fixed
       positioning anchored below the header. */
    .search-dropdown {
        position: fixed;
        top: auto;
        left: var(--space-md);
        right: var(--space-md);
        max-height: 60vh;
    }

    .search-input {
        font-size: 0.8125rem;
        height: 32px;
    }

    .search-input::placeholder {
        font-size: 0.75rem;
    }

    /* Collapse user name on narrow screens, keep buttons */
    .auth-user {
        display: none;
    }

    .auth-link {
        font-size: 0.6875rem;
        padding: var(--space-xs) var(--space-sm);
    }

    /* Hide the peeringdb.com external link on mobile */
    .site-header__nav > a[target="_blank"] {
        display: none;
    }

    .main-content {
        padding: var(--space-lg) var(--space-md);
    }

    /* Constrain cards so tables don't push them off-screen */
    .card {
        max-width: calc(100vw - 2 * var(--space-md));
        overflow: hidden;
    }

    /* Ensure table wrapper scrolls horizontally within the card */
    .data-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* Scroll hint: fading gradient on the right edge */
        mask-image: linear-gradient(to right, #000 90%, transparent);
        -webkit-mask-image: linear-gradient(to right, #000 90%, transparent);
    }

    /* Remove scroll hint when user has scrolled (JS could toggle this,
       but for now this CSS-only solution covers the common case) */
    .data-table-wrapper:focus-within,
    .data-table-wrapper:active {
        mask-image: none;
        -webkit-mask-image: none;
    }
}

@media (max-width: 480px) {
    .recent-updates {
        grid-template-columns: 1fr;
    }

    .home-heading {
        font-size: 1.25rem;
    }

    .site-footer__grid {
        grid-template-columns: 1fr;
    }

    .detail-header__title {
        font-size: 1.25rem;
    }

    .site-logo {
        font-size: 0.9375rem;
    }

    body[data-page="home"] .site-logo {
        font-size: 1.125rem;
    }

    /* Compact table cells for very narrow screens */
    .data-table td {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }

    .data-table th {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.625rem;
    }

    .data-table td.td-mono {
        font-size: 0.6875rem;
    }

    /* Stats bar items stack more tightly */
    .stats-bar {
        gap: var(--space-sm);
        padding: var(--space-md);
    }

    .stats-bar__item {
        min-width: 0;
    }
}

/* ── Mobile table card layout ─────────────────────────────────── */
/* At narrow widths, each table row becomes a self-contained card
   with labelled fields instead of a horizontal scrolling table.
   Labels come from the data-label attribute set by pdb-table.js. */

@media (max-width: 640px) {
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr {
        display: block;
    }

    .data-table tr {
        padding: var(--space-sm) var(--space-md);
        margin-bottom: var(--space-xs);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        background: var(--bg-card);
    }

    .data-table tr:hover {
        border-color: var(--border);
    }

    /* Override the nth-child striping — cards use border instead */
    .data-table tr:nth-child(even) td {
        background: transparent;
    }

    .data-table tr:hover td {
        background: transparent;
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-sm);
        padding: 2px var(--space-xs);
        white-space: normal;
        border-bottom: none;
        text-align: right;
        max-width: none;
        overflow: visible;
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.625rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
        min-width: 5em;
    }

    /* IP address stacks should display inline in card mode */
    .data-table td .ip-stack {
        flex-direction: row;
        gap: var(--space-sm);
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    /* Mono cells don't need reduced font in card mode */
    .data-table td.td-mono {
        font-size: inherit;
    }

    /* Right-aligned cells align left in card mode (value is on the right via flex) */
    .data-table td.td-right {
        text-align: right;
    }

    /* Scroll hint not needed in card mode */
    .data-table-wrapper {
        mask-image: none;
        -webkit-mask-image: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   Debug Overlay (Ctrl+Shift+D)
   Hidden diagnostic panel for inspecting the distributed cache state.
   ═══════════════════════════════════════════════════════════════════ */

.debug-overlay {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 640px;
    max-height: 80vh;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px hsl(0 0% 0% / 0.4);
    border-radius: var(--radius-md);
    z-index: 9999;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.6875rem;
    color: var(--text-primary);
}

.debug-overlay__inner {
    padding: var(--space-md);
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-md);
}

.debug-header h3 {
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}

.debug-header__hint {
    font-size: 0.625rem;
    color: var(--text-muted);
    padding: 2px var(--space-xs);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.debug-section {
    margin-bottom: var(--space-md);
}

.debug-section h4 {
    font-family: 'Inter', sans-serif;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

/* Collapsible sections */
.debug-section__toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
    transition: color var(--transition-fast);
}

.debug-section__toggle:hover {
    color: var(--text-secondary);
}

.debug-chevron {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.debug-meta {
    font-size: 0.625rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.debug-meta--inline {
    font-weight: 400;
    font-size: 0.5625rem;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.debug-loading {
    color: var(--text-muted);
    font-style: italic;
}

.debug-error {
    color: var(--status-error);
}

.debug-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--space-sm);
}

.debug-table th,
.debug-table td {
    text-align: left;
    padding: 3px var(--space-xs);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

.debug-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.5625rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.debug-td--right {
    text-align: right;
}

.debug-td--truncate {
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.debug-td--muted {
    color: var(--text-muted);
    font-size: 0.5625rem;
}

/* Cache tier colour coding (edge) */
.debug-tier--L1   { color: var(--status-ok);    font-weight: 600; }
.debug-tier--L2   { color: var(--status-warn);  font-weight: 600; }
.debug-tier--MISS { color: var(--status-error); font-weight: 600; }
.debug-tier--N\/A { color: var(--text-muted); }

/* Browser SWR state colour coding */
.debug-swr--FRESH        { color: var(--status-ok);    font-weight: 600; }
.debug-swr--SWR          { color: var(--status-warn);  font-weight: 600; }
.debug-swr--REVALIDATING { color: hsl(210, 80%, 60%);  font-weight: 600; }
.debug-swr--EXPIRED      { color: var(--status-error); font-weight: 600; }

/* Active row — current page's cache entries */
.debug-row--active td {
    background: var(--accent-muted);
}

/* Staleness indicator for sync rows */
.debug-row--stale td {
    color: var(--status-error);
}

.debug-stale-badge {
    color: var(--status-error);
    font-size: 0.75rem;
    cursor: help;
}

/* Action buttons */
.debug-actions {
    display: flex;
    gap: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-subtle);
}

.debug-btn {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.625rem;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.debug-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.debug-btn--close {
    margin-left: auto;
    font-size: 0.75rem;
    line-height: 1;
}

/* Responsive: overlay goes full-width on narrow screens */
@media (max-width: 680px) {
    .debug-overlay {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
    }
}

/* ── Favorite toggle button (detail headers) ─────────────────────── */

.favorite-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 var(--space-xs);
    color: var(--text-muted);
    transition: color 0.15s ease, transform 0.15s ease;
    vertical-align: middle;
}

.favorite-btn:hover {
    color: hsl(45, 90%, 55%);
    transform: scale(1.15);
}

.favorite-btn--active {
    color: hsl(45, 90%, 55%);
}

.favorite-btn--active:hover {
    color: hsl(0, 60%, 55%);
}

.favorite-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

/* ── Account page favorites list ─────────────────────────────────── */

.favorites-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.favorites-list__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: border-color 0.15s ease;
}

.favorites-list__item:hover {
    border-color: var(--accent);
}

.favorites-list__item a {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorites-list__remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
    color: var(--text-muted);
    padding: 0 var(--space-xs);
    transition: color 0.15s ease;
    flex-shrink: 0;
}

.favorites-list__remove:hover {
    color: var(--status-error);
}

.favorites-list__remove:disabled {
    opacity: 0.3;
    cursor: default;
}

/* ── Homepage favorites grid ─────────────────────────────────────── */

.home-favorites {
    margin-bottom: var(--space-xl);
}

.home-signin .home-hero__desc {
    margin-bottom: var(--space-sm);
}

.home-signin .auth-link {
    display: inline-block;
}

.favorites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-sm);
}

.favorites-grid__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.favorites-grid__item:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-dim);
}

/* ── Account page affiliation tree ───────────────────────────────── */
/* Org-grouped tree: each org is a divider/header row, with child
   entities (networks, exchanges, facilities) listed beneath it.    */

.affiliation-tree {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.affiliation-tree__org {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    margin-top: var(--space-sm);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-body);
    border-top: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.affiliation-tree__org:first-child {
    margin-top: 0;
    border-top: none;
}

.affiliation-tree__entity {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md) var(--space-xs) var(--space-xl);
    font-size: 0.8125rem;
    transition: background var(--transition-fast);
}

.affiliation-tree__entity:hover {
    background: var(--bg-hover);
}

.affiliation-tree__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.affiliation-tree__compare {
    flex-shrink: 0;
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.affiliation-tree__compare:hover {
    color: var(--accent);
}

/* ── Compare page ──────────────────────────────────────────────── */
/* Side-by-side entity selector grid, submit button, and search
   wrapper positioning. All visual components (cards, tables, stats
   bars, badges, search dropdowns) use classes defined above.       */

.compare-intro {
    max-width: 720px;
    margin: 0 auto var(--space-lg);
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.compare-intro p + p {
    margin-top: var(--space-sm);
}

.compare-intro__lead {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

.compare-actions {
    display: flex;
    justify-content: center;
    padding-top: var(--space-md);
}

.compare-search-wrap {
    position: relative;
}

/* Locked state: A-side pre-filled from URL, not editable */
.compare-search-wrap--locked .search-input {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--text-secondary);
    cursor: default;
    opacity: 0.8;
}

.compare-search-wrap--locked .search-input:focus {
    border-color: var(--border-subtle);
    box-shadow: none;
}

.compare-selected {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.8125rem;
    min-height: 1.5em;
    margin-top: var(--space-xs);
    color: var(--text-secondary);
}

.compare-submit {
    padding: var(--space-sm) var(--space-xl);
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.compare-submit:hover {
    opacity: 0.85;
}

/* ── Compare results layout ────────────────────────────────────── */
/* Vertical space between successive result tables so they don't
   collide. Section headers get a prominent treatment with a top
   border and larger font so readers can orient at a glance.       */

.compare-section {
    margin-top: var(--space-xl);
}

.compare-section__header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
    border-bottom: 2px solid var(--border);
}

.compare-section__title {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

/* ── Map tile theming ──────────────────────────────────────────── */
/* Dark mode: invert + hue-rotate the OSM raster tile layer so
   the map blends with the dark UI chrome. The hue rotation
   undoes the colour shift introduced by the inversion.           */

:root:not([data-theme="light"]) .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) saturate(0.6) brightness(0.85);
}

/* Prevent the inversion from applying to marker icons and popups
   rendered inside the map — they already use themed CSS vars.    */
:root:not([data-theme="light"]) .leaflet-marker-pane,
:root:not([data-theme="light"]) .leaflet-popup-pane,
:root:not([data-theme="light"]) .leaflet-tooltip-pane {
    filter: none;
}

/* Map container: give it a themed background so the empty areas
   behind tiles (e.g. during load) match the page.                */
pdb-map .pdb-map-instance {
    background: var(--bg-surface);
}

/* ── Entity-type badge ─────────────────────────────────────────── */
/* Colour is set via --badge-color which maps to --type-<entity>.  */

.entity-badge {
    display: inline-block;
    min-width: 3.5em;
    text-align: center;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2em 0.6em;
    border-radius: 1em;
    background: var(--badge-color);
    color: var(--bg-body);
    flex-shrink: 0;
    line-height: 1.4;
}

/* Full-size badge for detail page headers */
.entity-badge--header {
    font-size: 0.75rem;
    padding: 0.25em 0.75em;
}

/* Per-type colour assignments */
.entity-badge[data-type="net"]     { --badge-color: var(--type-net); }
.entity-badge[data-type="ix"]      { --badge-color: var(--type-ix); }
.entity-badge[data-type="fac"]     { --badge-color: var(--type-fac); }
.entity-badge[data-type="org"]     { --badge-color: var(--type-org); }
.entity-badge[data-type="campus"]  { --badge-color: var(--type-campus); }
.entity-badge[data-type="carrier"] { --badge-color: var(--type-carrier); }
.entity-badge[data-type="asn"]     { --badge-color: var(--type-asn); }

.favorites-grid__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorites-grid__updated {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Form primitives ───────────────────────────────────────────── */
/* Shared input, select, textarea, label, button styles.           */
/* Used by advanced search, compare, and any future form.          */

.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.form-input,
.form-select,
.form-textarea {
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
}

.btn {
    padding: var(--space-xs) var(--space-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast),
                color var(--transition-fast),
                border-color var(--transition-fast);
}

.btn--primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn--primary:hover {
    opacity: 0.9;
}

.btn--secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.btn--secondary:hover {
    background: var(--bg-hover);
}

/* ── Rate-limit modal ───────────────────────────────────────────── */

.rate-limit-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.rate-limit-dialog {
    background: var(--bg-card);
    border: 1px solid var(--status-warn);
    border-radius: var(--radius-lg);
    padding: var(--space-xl) var(--space-2xl);
    max-width: 400px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.rate-limit-dialog h3 {
    margin: 0 0 var(--space-sm) 0;
    font-size: 1.125rem;
    color: var(--status-warn);
}

.rate-limit-dialog p {
    margin: 0 0 var(--space-lg) 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
}

.rate-limit-dismiss {
    padding: var(--space-xs) var(--space-xl);
    background: var(--status-warn);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.rate-limit-dismiss:hover {
    opacity: 0.85;
}

/* ── Advanced Search ───────────────────────────────────────────────── */
/* Layout-only styles — inputs, buttons, and tables reuse shared      */
/* .form-*, .btn, and .data-table primitives from the design system.  */

.adv-search {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
}

/* Tab bar */
.adv-search__tabs {
    display: flex;
    gap: var(--space-xs);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-lg);
    border-bottom: 2px solid var(--border);
}

.adv-search__tab {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast),
                background var(--transition-fast),
                border-color var(--transition-fast);
}

.adv-search__tab:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.adv-search__tab--active {
    color: var(--text-primary);
    background: var(--bg-surface);
    border-color: var(--border);
    font-weight: 600;
    margin-bottom: -2px;
    padding-bottom: calc(var(--space-xs) + 2px);
    border-bottom: 2px solid var(--bg-surface);
}

.adv-search__tab .entity-badge {
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
}

/* Form grid — two columns on desktop, single on mobile */
.adv-search__form  { margin-bottom: var(--space-lg); }

.adv-search__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md) var(--space-xl);
    margin-bottom: var(--space-lg);
}

/* Description text (ASN Connectivity) */
.adv-search__desc {
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    line-height: 1.5;
}

/* Action row */
.adv-search__actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

/* Results */
.adv-search__results { margin-top: var(--space-lg); }

.adv-search__summary {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.adv-search__export {
    margin-top: var(--space-md);
    display: flex;
    justify-content: flex-end;
}

.adv-search__missing-header {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: var(--space-lg);
    margin-bottom: var(--space-sm);
}

.adv-search__missing-list {
    color: var(--text-secondary);
    font-family: 'Inter', monospace;
    font-size: 0.8125rem;
    word-break: break-word;
}

/* ── Chip Select Component ─────────────────────────────────────────── */
/* Standalone reusable component — used wherever multi-select is       */
/* needed. Themed via CSS vars, no component-scoped overrides.         */

.chip-select {
    position: relative;
}

.chip-select__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px var(--space-xs);
    min-height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    cursor: text;
    transition: border-color var(--transition-fast);
    align-items: center;
}

.chip-select__chips:focus-within {
    border-color: var(--accent);
}

.chip-select__chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.4;
}

.chip-select__chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    margin-left: 2px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.1s;
}

.chip-select__chip-remove:hover {
    opacity: 1;
}

.chip-select__input {
    flex: 1;
    min-width: 80px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: inherit;
    outline: none;
    padding: 2px 0;
}

.chip-select__input::placeholder {
    color: var(--text-muted);
}

.chip-select__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
}

.chip-select__option {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8125rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s;
}

.chip-select__option:hover,
.chip-select__option--highlight {
    background: var(--bg-hover);
}

.chip-select__option--selected {
    font-weight: 600;
    color: var(--accent);
}

.chip-select__option--selected::before {
    content: '✓ ';
}

.chip-select__empty {
    padding: var(--space-sm);
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

/* ── Advanced Search Responsive ──────────────────────────────────── */

@media (max-width: 768px) {
    .adv-search__grid {
        grid-template-columns: 1fr;
    }

    .adv-search__tabs {
        gap: 2px;
    }

    .adv-search__tab {
        font-size: 0.75rem;
        padding: var(--space-xs) var(--space-xs);
    }

    .adv-search__tab .entity-badge {
        display: none;
    }

    .adv-search__actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-body);
        padding: var(--space-sm) 0;
        border-top: 1px solid var(--border);
    }
}

/* ── Favorites management page ─────────────────────────────────── */

.favorites-page {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
}

.favorites-page__subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.favorites-page__count {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-md);
}

.favorites-manage {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.favorites-manage__item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-sm);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast),
                box-shadow var(--transition-fast);
    cursor: grab;
}

.favorites-manage__item:hover {
    background: var(--bg-hover);
}

.favorites-manage__item--dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.favorites-manage__handle {
    color: var(--text-muted);
    font-size: 1rem;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

.favorites-manage__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.favorites-manage__delete {
    flex-shrink: 0;
    padding: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    transition: color var(--transition-fast),
                background var(--transition-fast);
}

.favorites-manage__delete:hover {
    color: var(--status-error);
    background: var(--error-bg);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
