/* plan pony — Fira Code, teal system, light + dark (prefers-color-scheme) */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;500;600;700&display=swap');

/* CSS Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Dark theme default (:root); light via media query */
:root {
    --color-bg: #0f1a17;
    --color-bg-elevated: #265243;
    --color-text: #E1F5EE;
    --color-heading: #f0faf9;
    --color-accent: #1D9E75;
    --color-accent-hover: #1D9E75;
    --color-on-accent: #0a1012;
    --color-link: #1D9E75;
    --color-text-muted: #7d9491;
    --color-background-alt: #161f23;
    --color-border: #3d524f;
    --color-success: #9FE1CB;
    --color-warning: #fbbf24;
    --color-error: #f87171;
    --color-pending: #22d3ee;
    --color-white: #ffffff;
    --color-tagline: #1D9E75;
    --color-overlay: rgba(255, 255, 255, 0.06);
    --color-focus-ring: rgba(45, 212, 191, 0.25);
    --color-success-dim: rgba(52, 211, 153, 0.15);
    --color-success-border: rgba(52, 211, 153, 0.35);
    --color-pending-dim: rgba(34, 211, 238, 0.15);
    --color-pending-border: rgba(34, 211, 238, 0.35);
    --color-warning-dim: rgba(251, 191, 36, 0.15);
    --color-warning-border: rgba(251, 191, 36, 0.35);
    --color-error-dim: rgba(248, 113, 113, 0.15);
    --color-highlight-mark: rgba(250, 204, 21, 0.35);
    --color-accent-dim: rgba(45, 212, 191, 0.12);
    --color-accent-dim-border: rgba(45, 212, 191, 0.22);
    --color-filters-panel-bg: rgba(0, 0, 0, 0.18);

    /* Leaflet / map markers (read by map.js) */
    --map-marker-app: #1D9E75;
    --map-marker-home: #e8a045;
    --map-line-muted: #64748b;
    --map-tooltip-bg: var(--color-bg-elevated);
    --map-tooltip-border: var(--color-border);
    --map-tooltip-text: var(--color-text);
    --map-tile-placeholder-bg: var(--color-bg);

    /* Typography */
    --font-primary: 'Fira Code', monospace;
    --font-secondary: 'Fira Sans', sans-serif;

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

    /* Geometric corners (minimal radius) */
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-dropdown: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: light) {
    :root {
        --color-bg: #f4f8f8;
        --color-bg-elevated: #eef4f4;
        --color-text: #1e293b;
        --color-heading: #0f172a;
        --color-accent: #1D9E75;
        --color-accent-hover: #1D9E75;
        --color-on-accent: #ffffff;
        --color-link: #1D9E75;
        --color-text-muted: #64748b;
        --color-background-alt: #e8f0f0;
        --color-border: #cbd5d1;
        --color-success: #059669;
        --color-warning: #d97706;
        --color-error: #dc2626;
        --color-pending: #0891b2;
        --color-tagline: #1D9E75;
        --color-overlay: rgba(15, 23, 42, 0.04);
        --color-focus-ring: rgba(13, 148, 136, 0.35);
        --color-success-dim: rgba(5, 150, 105, 0.12);
        --color-success-border: rgba(5, 150, 105, 0.35);
        --color-pending-dim: rgba(8, 145, 178, 0.12);
        --color-pending-border: rgba(8, 145, 178, 0.35);
        --color-warning-dim: rgba(217, 119, 6, 0.12);
        --color-warning-border: rgba(217, 119, 6, 0.35);
        --color-error-dim: rgba(220, 38, 38, 0.12);
        --color-highlight-mark: rgba(250, 204, 21, 0.45);
        --color-accent-dim: rgba(13, 148, 136, 0.1);
        --color-accent-dim-border: rgba(13, 148, 136, 0.25);
        --color-filters-panel-bg: rgba(15, 23, 42, 0.04);
        --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
        --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
        --shadow-dropdown: 0 8px 24px rgba(15, 23, 42, 0.12);

        --map-marker-app: #1D9E75;
        --map-marker-home: #d97706;
        --map-line-muted: #64748b;
        --map-tooltip-bg: var(--color-bg-elevated);
        --map-tooltip-border: var(--color-border);
        --map-tooltip-text: var(--color-text);
        --map-tile-placeholder-bg: var(--color-bg);
    }
}

html {
    color-scheme: dark light;
    font-size: 16px;
    line-height: 1.5;
}

body {
    font-family: var(--font-primary);
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 400;
    line-height: 1.25;
    margin-bottom: var(--space-md);
    color: var(--color-heading);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p {
    margin-bottom: var(--space-md);
    font-family: var(--font-secondary);
}

a {
    color: var(--color-link);
    text-decoration: none;
}

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

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

/* Header — z-index above Leaflet controls (~1000) so map tiles/controls scroll under the bar */
.site-header {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-md) 0;
    position: sticky;
    top: 0;
    z-index: 2100;
}

.settings-menu {
    position: relative;
    z-index: 1;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    transition:
        max-width 0.28s ease,
        padding-left 0.28s ease,
        padding-right 0.28s ease,
        margin-left 0.28s ease,
        margin-right 0.28s ease;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-shrink: 0;
}

.logo {
    display: flex;
    flex-direction: column;
    text-decoration: none;
}

.logo--planpony {
    flex-direction: row;
    align-items: flex-start;
    gap: var(--space-md);
    max-width: min(100%, 22rem);
}

.logo__mark {
    flex-shrink: 0;
    color: var(--color-accent);
    line-height: 0;
}

.logo-pony-svg {
    display: block;
    width: 2.35rem;
    height: auto;
    overflow: visible;
}

.logo-pony__head {
    transform-origin: 26px 20px;
    transform-box: fill-box;
    animation: none;
}

.logo--planpony:hover .logo-pony__head {
    animation: logoPonyHeadTurn 0.75s ease-in-out 1 forwards;
}

@media (prefers-reduced-motion: reduce) {
    .logo-pony__head,
    .logo--planpony:hover .logo-pony__head {
        animation: none !important;
    }

    .logo__name,
    .logo__byline {
        transition: none;
    }
}

@keyframes logoPonyHeadTurn {
    0% {
        transform: rotate(0deg) translate(0, 0);
    }
    100% {
        transform: rotate(-7deg) translate(-0.5px, 0);
    }
}

.logo__text-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    min-width: 0;
}

.logo__name {
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    color: var(--color-heading);
    transition: font-size 0.18s ease;
}

.logo__rule {
    display: block;
    height: 1px;
    max-width: 16rem;
    background: var(--color-accent);
    opacity: 0.85;
}

.logo__tagline {
    font-size: 0.5rem;
    font-weight: 300;
    color: var(--color-tagline);
    font-family: var(--font-primary);
    line-height: 1.35;
}

.logo__credit {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    font-family: var(--font-secondary);
}

.logo__byline {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-family: var(--font-secondary);
    transition: font-size 0.18s ease;
}

a.logo.logo--planpony:hover {
    text-decoration: none;
}

a.logo.logo--planpony:hover .logo__name {
    font-weight: 800;
}

a.logo.logo--planpony:hover .logo__byline {
    font-weight: 600;
}

/* Teal outline nav */
.main-nav {
    display: flex;
    gap: var(--space-sm);
}

.main-nav a {
    color: var(--color-heading);
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-primary);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
}

.main-nav a:hover,
.main-nav a.active {
    background: var(--color-bg-elevated);
    border-color: var(--color-accent);
    color: var(--color-accent);
    text-decoration: none;
}

.main-nav a.main-nav__profile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
    min-width: 2.375rem;
    min-height: 2.375rem;
}

.main-nav a.main-nav__profile--with-label {
    min-width: auto;
    max-width: 16rem;
    gap: 0.35rem;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
}

.main-nav__profile-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 500;
    max-width: 10rem;
}

.main-nav a.main-nav__profile svg {
    display: block;
    flex-shrink: 0;
}

/* Settings Dropdown */
.settings-menu {
    position: relative;
}

.settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    cursor: pointer;
    color: var(--color-accent);
    transition: all 0.2s ease;
    width: 44px;
    height: 44px;
}

.settings-btn:hover {
    background: var(--color-accent);
    color: var(--color-on-accent);
}

.settings-btn svg {
    width: 20px;
    height: 20px;
}

.settings-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + var(--space-xs));
    right: 0;
    background: var(--color-background-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    min-width: 180px;
    z-index: 2200;
    box-shadow: var(--shadow-dropdown);
    overflow: hidden;
}

.settings-menu.open .settings-dropdown {
    display: block;
}

.settings-dropdown__section {
    padding: var(--space-sm) 0;
}

.settings-dropdown__section + .settings-dropdown__section {
    border-top: 1px solid var(--color-border);
}

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

.settings-dropdown a {
    display: block;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.875rem;
    border: none;
    border-radius: 0;
    transition: background 0.15s ease;
}

.settings-dropdown a:hover,
.settings-dropdown a.active {
    background: var(--color-accent);
    color: var(--color-on-accent);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: var(--space-xl) 0;
}

/* Footer */
.site-footer {
    background: var(--color-background-alt);
    border-top: 1px solid var(--color-border);
    padding: var(--space-lg) 0;
    margin-top: auto;
}

.site-footer p {
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.footer__meta {
    font-size: 0.75rem !important;
}

.footer__meta--map-attribution {
    margin-top: 0;
    margin-bottom: 0;
    opacity: 0.85;
}

.footer__meta--map-attribution a {
    color: var(--color-link);
}

/* Leaflet map containers */
.map-container {
    width: 100%;
    min-height: 200px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    overflow: hidden;
}

.map-container--dashboard {
    height: 400px;
}

.map-container--applications {
    height: 500px;
}

.map-container--detail {
    height: 300px;
}

/* Leaflet adds .leaflet-container on the same node as .map-container--leaflet (not a child) — use chained selectors so we beat leaflet.css loaded after main.css */
.map-container--leaflet.leaflet-container {
    font-family: var(--font-primary);
    background: var(--map-tile-placeholder-bg) !important;
    color: var(--color-text);
}

.map-container--leaflet.leaflet-container .leaflet-pane,
.map-container--leaflet.leaflet-container .leaflet-tile-pane,
.map-container--leaflet.leaflet-container .leaflet-map-pane .leaflet-layer {
    background-color: var(--map-tile-placeholder-bg) !important;
}

.map-container--leaflet.leaflet-container .leaflet-tile-container,
.map-container--leaflet.leaflet-container .leaflet-tile-container img.leaflet-tile {
    background-color: var(--map-tile-placeholder-bg) !important;
}

.map-container--leaflet.leaflet-container .leaflet-tile-container img.leaflet-tile {
    /* Until the raster decodes, avoid a bright flash through transparent PNG edges */
    background-clip: padding-box;
}

.map-container--leaflet.leaflet-container .leaflet-control-attribution {
    background: var(--color-background-alt);
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
    border-radius: var(--radius-sm) 0 0 0;
    font-size: 0.65rem;
    max-width: 100%;
}

.map-container--leaflet.leaflet-container .leaflet-control-attribution a {
    color: var(--color-link);
}

.map-container--leaflet.leaflet-container .leaflet-bar a {
    background: var(--color-background-alt);
    color: var(--color-heading);
    border-color: var(--color-border);
}

.map-container--leaflet.leaflet-container .leaflet-bar a:hover {
    background: var(--color-bg-elevated);
    color: var(--color-accent);
}

.map-unavailable {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: var(--space-xl);
    color: var(--color-text-muted);
    font-family: var(--font-primary);
    font-size: 0.875rem;
}

.map-tooltip {
    text-align: left;
    line-height: 1.35;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    word-break: normal;
    overflow-wrap: break-word;
}

.map-tooltip__addr {
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--map-tooltip-text);
    opacity: 0.95;
}

.map-tooltip__meta {
    margin-top: 0.35rem;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

.map-tooltip__reason {
    margin-top: 0.4rem;
    font-size: 0.68rem;
    line-height: 1.35;
    color: var(--color-text-muted);
}

.map-tooltip__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--map-tooltip-border);
}

.map-tooltip .map-chip {
    display: inline-block;
    max-width: 100%;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.25;
    border: 1px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 11rem;
}

/* Bucket chip colours: shared hue steps; map vs table use different mix bases. */
.map-tooltip .explore-bucket-chip[data-bucket-index="0"] {
    background: color-mix(in srgb, var(--color-accent) 22%, var(--map-tooltip-bg));
    color: var(--map-tooltip-text);
    border-color: color-mix(in srgb, var(--color-accent) 45%, var(--map-tooltip-border));
}

.map-tooltip .explore-bucket-chip[data-bucket-index="1"] {
    background: color-mix(in srgb, #6366f1 24%, var(--map-tooltip-bg));
    color: var(--map-tooltip-text);
    border-color: color-mix(in srgb, #6366f1 50%, var(--map-tooltip-border));
}

.map-tooltip .explore-bucket-chip[data-bucket-index="2"] {
    background: color-mix(in srgb, #c026d3 22%, var(--map-tooltip-bg));
    color: var(--map-tooltip-text);
    border-color: color-mix(in srgb, #c026d3 45%, var(--map-tooltip-border));
}

.map-tooltip .explore-bucket-chip[data-bucket-index="3"] {
    background: color-mix(in srgb, #ea580c 22%, var(--map-tooltip-bg));
    color: var(--map-tooltip-text);
    border-color: color-mix(in srgb, #ea580c 45%, var(--map-tooltip-border));
}

.map-tooltip .explore-bucket-chip[data-bucket-index="4"],
.map-tooltip .explore-bucket-chip[data-bucket-index="5"],
.map-tooltip .explore-bucket-chip[data-bucket-index="6"],
.map-tooltip .explore-bucket-chip[data-bucket-index="7"] {
    background: color-mix(in srgb, var(--color-text-muted) 18%, var(--map-tooltip-bg));
    color: var(--map-tooltip-text);
    border-color: var(--map-tooltip-border);
}

.map-leaflet-tooltip,
.leaflet-tooltip.map-leaflet-tooltip {
    background: var(--map-tooltip-bg) !important;
    color: var(--map-tooltip-text) !important;
    border: 1px solid var(--map-tooltip-border) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-sm) !important;
    padding: var(--space-sm) var(--space-md) !important;
    font-family: var(--font-primary) !important;
    /* Width follows content until max; then wrap at words / long strings only when needed. */
    width: max-content !important;
    max-width: min(36rem, calc(100vw - 1.5rem)) !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    white-space: normal !important;
    overflow: visible !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
}

.map-leaflet-tooltip::before,
.leaflet-tooltip.map-leaflet-tooltip::before {
    border-top-color: var(--map-tooltip-border) !important;
}

.footer__credit {
    display: inline;
    margin-left: 0.35rem;
    color: var(--color-text-muted);
}

.footer__credit a {
    color: var(--color-link);
}

/* Panels */
.panel {
    background: var(--color-background-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    box-shadow: none;
}

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

.panel__header h2 {
    margin-bottom: 0;
    font-size: 1.125rem;
}

.panel__header .section-heading-terminal {
    margin-bottom: 0;
}

.panel__footer {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

/* Profile layout */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

.profile-subscriptions {
    grid-column: 1 / -1;
}

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

.keyword-readonly-list {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.subscription-builder-shell {
    max-width: 72rem;
    margin: 0 auto;
}

.subscription-builder-form.panel--constrained {
    max-width: none;
}

/* Dashboard metric cards */
.dash-metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.dash-metric-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    padding: var(--space-sm) var(--space-md);
    min-height: 5.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
}

.dash-metric-card__value {
    font-size: 1.35rem;
    font-weight: 700;
    font-family: var(--font-primary);
    color: var(--color-heading);
    line-height: 1.2;
}

.dash-metric-card__label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    line-height: 1.25;
}

.dash-metric-card__hint {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    opacity: 0.9;
    line-height: 1.3;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-lg);
}

.dashboard-grid--single {
    grid-template-columns: 1fr;
}

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

/* Quick Stats Row */
.quick-stats-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
    padding: var(--space-xl) 0;
}

.quick-stat {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
}

.quick-stat__number {
    font-size: 3rem;
    font-weight: 700;
    color: var(--color-heading);
    font-family: var(--font-primary);
    line-height: 1;
}

.quick-stat__label {
    font-size: 1.25rem;
    color: var(--color-text-muted);
    font-family: var(--font-secondary);
}

.quick-stats-separator {
    font-size: 2rem;
    color: var(--color-text-muted);
    padding: 0 var(--space-sm);
}

@media (max-width: 640px) {
    .quick-stats-row {
        flex-direction: column;
        align-items: center;
        gap: var(--space-sm);
    }

    .quick-stats-separator {
        display: none;
    }

    .quick-stat__number {
        font-size: 2.5rem;
    }

    .quick-stat__label {
        font-size: 1rem;
    }
}

/* Keyword Matches Section */
.keyword-matches-list {
    list-style: none;
}

.keyword-match-item {
    border-bottom: 1px solid var(--color-border);
}

.keyword-match-item:last-child {
    border-bottom: none;
}

.keyword-match-link {
    display: block;
    padding: var(--space-md);
    text-decoration: none;
    transition: background 0.2s ease;
}

.keyword-match-link:hover {
    background: var(--color-overlay);
    text-decoration: none;
}

.keyword-match__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xs);
}

.keyword-match__ref {
    font-weight: 600;
    color: var(--color-accent);
}

.keyword-match__portal {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-bg);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.keyword-match__address {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
    font-family: var(--font-secondary);
}

.keyword-match__description {
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    font-family: var(--font-secondary);
}

.keyword-match__keywords {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.keyword-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    background: var(--color-success);
    color: var(--color-on-accent);
    font-family: var(--font-primary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--color-background-alt);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--color-border);
}

.stat-card__value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-accent);
    display: block;
}

.stat-card__label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
    font-family: var(--font-secondary);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    font-family: var(--font-secondary);
}

.table th,
.table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg);
}

.table--compact th,
.table--compact td {
    padding: var(--space-xs) var(--space-sm);
}

.table tr:hover {
    background: var(--color-overlay);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: var(--space-sm) var(--space-lg);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    font-family: var(--font-primary);
}

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

.btn--primary:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    transform: scale(1.05);
    text-decoration: none;
}

.btn--secondary {
    background: transparent;
    color: var(--color-accent);
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-sm);
}

.btn--secondary:hover {
    background: var(--color-accent);
    color: var(--color-on-accent);
    transform: scale(1.05);
    text-decoration: none;
}

.btn--small {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.75rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--color-background-alt);
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-transform: capitalize;
}

.status-badge--completed,
.status-badge--success {
    background: var(--color-success-dim);
    color: var(--color-success);
}

.status-badge--running,
.status-badge--pending {
    background: var(--color-pending-dim);
    color: var(--color-pending);
}

.status-badge--failed,
.status-badge--error {
    background: var(--color-error-dim);
    color: var(--color-error);
}

.status-badge--interrupted {
    background: var(--color-pending-dim);
    color: var(--color-pending);
}

.status-badge--completed_with_warnings {
    background: var(--color-warning-dim);
    color: var(--color-warning);
}

/* Dashboard: portal sync strip (in-flow panel, auto-scroll via dashboard.js) */
.portal-sync-panel .portal-sync-strip__viewport {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    scrollbar-gutter: stable;
    padding-bottom: var(--space-xs);
    mask-image: linear-gradient(to right, transparent, #000 1.5%, #000 98.5%, transparent);
}

.portal-sync-panel .portal-sync-strip__viewport:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.portal-sync-strip__track {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: var(--space-sm);
    width: max-content;
    padding: var(--space-xs) 0;
}

.portal-sync-card {
    flex: 0 0 auto;
    width: min(11.5rem, 72vw);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    padding: var(--space-sm) var(--space-md);
    min-height: 5.5rem;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    justify-content: center;
}

.portal-sync-card__title {
    font-size: 0.8125rem;
    font-weight: 700;
    font-family: var(--font-primary);
    color: var(--color-heading);
    line-height: 1.2;
}

.portal-sync-card__rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.portal-sync-card__row {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-sm);
}

.portal-sync-card__label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    line-height: 1.2;
    flex-shrink: 0;
}

.portal-sync-card__value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.2;
    text-align: right;
    min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
    .portal-sync-strip__track .portal-sync-card[data-ticker-seq="2"] {
        display: none;
    }

    .portal-sync-strip__track {
        flex-wrap: wrap;
        width: 100%;
        max-width: 100%;
        row-gap: var(--space-sm);
    }

    .portal-sync-panel .portal-sync-strip__viewport {
        overflow-x: visible;
        mask-image: none;
    }
}

/* Subscriptions */
.subscriptions-flash {
    display: inline-block;
    margin-bottom: var(--space-md);
}

.subscriptions-table {
    width: 100%;
    margin-top: var(--space-lg);
}

.subscriptions-table__cell-recipients {
    max-width: 220px;
    word-break: break-all;
}

.subscriptions-table__cell-error {
    max-width: 180px;
    font-size: 0.75rem;
    color: var(--color-error);
}

.subscriptions-actions {
    white-space: nowrap;
}

.subscriptions-actions__inline-form {
    display: inline;
}

.subscriptions-actions .btn--small {
    vertical-align: middle;
}

.form-help--spaced-top {
    margin-top: var(--space-xl);
}

.panel--constrained {
    max-width: 40rem;
}

.panel--spaced-top {
    margin-top: var(--space-lg);
}

.subscription-form__section-title {
    margin-top: var(--space-lg);
    margin-bottom: var(--space-md);
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--color-heading);
}

/* Forms */
.form-group {
    margin-bottom: var(--space-md);
}

.form-hint,
.form-help {
    font-family: var(--font-secondary);
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
    line-height: 1.4;
}

.form-hint--error {
    color: var(--color-error);
}

.sync-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.portal-multiselect-toolbar {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.form-select--multi {
    width: 100%;
    min-height: 10rem;
    max-height: 16rem;
    font-family: var(--font-secondary);
    font-size: 0.875rem;
    line-height: 1.35;
    padding: var(--space-sm);
    padding-inline: var(--space-md);
}

.form-select--multi option {
    padding: var(--space-xs) var(--space-sm);
}

.form-hint kbd,
.form-label kbd {
    display: inline-block;
    padding: 0.1em 0.35em;
    font-size: 0.8em;
    font-family: var(--font-primary);
    background: var(--color-background-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--space-xs);
    color: var(--color-text);
    font-family: var(--font-secondary);
}

.form-input,
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.2s ease;
    font-family: var(--font-primary);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

/* Single-line selects: leave room for native chevron */
.form-select:not(.form-select--multi) {
    padding-right: 2.5rem;
}

/* Search */
.search-box {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.search-box input {
    flex: 1;
}

/* Filters */
.filters {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--color-background-alt);
    border-radius: var(--radius-md);
}

.filters__form {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    align-items: flex-end;
    width: 100%;
}

.filters-panel {
    flex-basis: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0 var(--space-md) var(--space-md);
    background: var(--color-filters-panel-bg);
}

.filters-panel__summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-heading);
    user-select: none;
}

.filters-panel__summary::-webkit-details-marker {
    display: none;
}

.filters-panel__summary-text {
    flex: 1;
}

.filters-panel__chevron::before {
    content: "▼";
    display: inline-block;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--color-accent);
    margin-left: var(--space-sm);
}

.filters-panel:not([open]) .filters-panel__chevron::before {
    content: "▶";
    font-size: 1rem;
}

.filters-panel__body {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    align-items: flex-end;
    width: 100%;
}

.filters-more__summary {
    display: list-item;
    cursor: pointer;
    margin-bottom: 0.25rem;
}

.filters .form-group {
    flex: 1;
    min-width: 150px;
    margin-bottom: 0;
}

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

/* Application List */
.application-list {
    list-style: none;
}

.application-item {
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

.application-item:last-child {
    border-bottom: none;
}

.application-item__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-sm);
}

.application-item__reference {
    font-weight: 600;
    color: var(--color-accent);
}

.application-item__status {
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    background: var(--color-background-alt);
}

.application-item__address {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
    font-family: var(--font-secondary);
}

.application-item__description {
    font-size: 0.875rem;
    line-height: 1.4;
    font-family: var(--font-secondary);
}

.application-item__meta {
    display: flex;
    gap: var(--space-lg);
    margin-top: var(--space-sm);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-family: var(--font-secondary);
}

/* Application Detail */
.application-detail {
    max-width: 100%;
}

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

.application-detail__details,
.application-detail__search,
.application-detail__map,
.application-detail__actions,
.application-detail__documents {
    min-width: 0;
}

.application-detail__documents--empty {
    display: none;
}

@media (min-width: 960px) {
    .application-detail__layout {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "details search"
            "map map"
            "actions docs";
        align-items: stretch;
    }

    .application-detail__layout--no-map {
        grid-template-areas:
            "details search"
            "actions docs";
    }

    .application-detail__layout .application-detail__search.detail-search {
        margin-top: 0;
    }

    .application-detail__details {
        grid-area: details;
    }

    .application-detail__search {
        grid-area: search;
    }

    .application-detail__map {
        grid-area: map;
    }

    .application-detail__actions {
        grid-area: actions;
    }

    .application-detail__documents {
        grid-area: docs;
    }

    /* Same-row panels stretch to the taller column */
    .application-detail__details.panel,
    .application-detail__search,
    .application-detail__actions.panel,
    .application-detail__documents.panel {
        display: flex;
        flex-direction: column;
        align-self: stretch;
        min-height: 0;
        height: 100%;
    }

    .application-detail__search .detail-search__panel {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 100%;
    }

    .application-detail__search #detail-search-snippet.detail-search-snippet {
        flex: 1;
        min-height: 0;
    }

    .application-detail__documents--empty {
        display: block;
        min-height: 0;
        border: none;
        background: transparent;
        padding: 0;
        box-shadow: none;
    }
}

.application-detail__header {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.application-detail__reference {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-accent);
    margin-bottom: var(--space-sm);
}

.application-detail__address {
    font-size: 1.125rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
    font-family: var(--font-secondary);
}

.application-detail__description {
    font-size: 1rem;
    line-height: 1.6;
    font-family: var(--font-secondary);
}

.application-detail__section {
    margin-bottom: var(--space-xl);
}

.application-detail__section h3 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
}

/* Documents List */
.documents-list {
    list-style: none;
}

.documents-list li {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-border);
}

.documents-list li:last-child {
    border-bottom: none;
}

.documents-list a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.documents-list a::before {
    content: "📄";
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--color-text-muted);
}

/* Sync History */
.sync-history {
    max-height: 300px;
    overflow-y: auto;
}

/* Detail list */
.detail-list {
    margin: 0;
    padding: 0;
}

.detail-list--inline {
    display: flex;
    gap: var(--space-xl);
    flex-wrap: wrap;
}

.detail-item {
    margin-bottom: var(--space-sm);
}

.detail-item dt {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.detail-item dd {
    color: var(--color-text);
    font-family: var(--font-secondary);
}

/* Sync progress */
.sync-progress {
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    font-family: var(--font-secondary);
}

.sync-progress__title {
    font-weight: 600;
    color: var(--color-accent);
    margin-bottom: var(--space-sm);
}

.sync-progress__detail {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.sync-progress__detail span {
    color: var(--color-text);
}

.sync-progress__bar {
    height: 6px;
    background: var(--color-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-top: var(--space-sm);
}

.sync-progress__bar-fill {
    height: 100%;
    background: var(--color-accent);
    transition: width 0.5s ease;
    border-radius: 3px;
}

.sync-progress__summary {
    margin-bottom: var(--space-md);
}

/* ~5 portal rows visible; scroll for long multi-portal syncs */
.sync-progress__portals-viewport {
    max-height: 14rem;
    overflow-y: auto;
    margin-top: var(--space-sm);
    padding-right: var(--space-xs);
}

.sync-progress__portal--row-running {
    border-color: var(--color-accent);
    background: var(--color-accent-dim);
}

.sync-progress__portal--row-ok {
    border-color: var(--color-success-border);
    background: var(--color-success-dim);
}

.sync-progress__portal--row-warn {
    border-color: var(--color-warning-border);
    background: var(--color-warning-dim);
}

.sync-progress__portal--row-error {
    border-color: color-mix(in srgb, var(--color-error) 40%, var(--color-border));
    background: color-mix(in srgb, var(--color-error) 14%, transparent);
}

.sync-progress__portal {
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated, var(--color-bg));
}

.sync-progress__portal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.sync-progress__portal-name {
    font-weight: 600;
    color: var(--color-text);
    font-family: var(--font-mono, var(--font-secondary));
    font-size: 0.875rem;
}

.sync-progress__portal-status {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--color-border);
    color: var(--color-text-muted);
}

.sync-progress__portal-status--running {
    background: var(--color-accent-dim);
    color: var(--color-accent);
}

.sync-progress__portal-status--done {
    background: color-mix(in srgb, var(--color-success) 20%, transparent);
    color: var(--color-success);
}

.sync-progress__portal-status--error {
    background: color-mix(in srgb, var(--color-error) 20%, transparent);
    color: var(--color-error);
}

.sync-progress__portal-status--skipped {
    opacity: 0.85;
}

.sync-progress__portal-detail {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
    word-break: break-word;
}

.sync-progress__portal-detail span {
    color: var(--color-text);
    font-family: var(--font-mono, var(--font-secondary));
    font-size: 0.8125rem;
}

.sync-progress__portal-error {
    font-size: 0.8125rem;
    color: var(--color-error);
    margin-top: var(--space-xs);
    word-break: break-word;
}

/* Highlight row */
.highlight-row {
    background: var(--color-accent-dim) !important;
}

/* Keyword Group Selector */
.keyword-group-selector {
    margin-bottom: var(--space-md);
}

.keyword-group-selector__label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
    display: block;
    font-family: var(--font-secondary);
}

.keyword-group-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.keyword-group-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-lg);
    border: 2px solid var(--color-border);
    background: var(--color-background-alt);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-primary);
}

.keyword-group-chip:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
    transform: translateY(-1px);
}

.keyword-group-chip--selected {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-on-accent);
}

.keyword-group-chip--selected:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: var(--color-on-accent);
}

.keyword-group-chip__check {
    display: none;
    font-weight: 700;
}

.keyword-group-chip--selected .keyword-group-chip__check {
    display: inline;
}

/* Selected Keywords Display */
.selected-keywords {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--color-accent-dim);
    border: 1px solid var(--color-accent-dim-border);
    border-radius: var(--radius-md);
}

.selected-keywords__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.selected-keywords__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-accent);
    margin: 0;
}

.selected-keywords__count {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-family: var(--font-secondary);
}

.selected-keywords__list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.keyword-tag {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    background: var(--color-background-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    font-family: var(--font-primary);
}

/* Matched Keywords Column */
.matched-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    max-width: 200px;
}

.matched-keyword {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-xs);
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    background: var(--color-success-dim);
    color: var(--color-success);
    border: 1px solid var(--color-success-border);
    font-family: var(--font-primary);
    white-space: nowrap;
}

.matched-keyword--description {
    background: var(--color-pending-dim);
    color: var(--color-link);
    border-color: var(--color-pending-border);
}

.matched-keyword--document {
    background: var(--color-accent-dim);
    color: var(--color-accent);
    border-color: var(--color-accent-dim-border);
}

.matched-keyword--indexed {
    background: var(--color-success-dim);
    color: var(--color-success);
    border-color: var(--color-success-border);
}

/* Explore table: same bucket hues as map tooltips (mix with row surface). */
.table--explore .explore-bucket-chip[data-bucket-index="0"] {
    background: color-mix(in srgb, var(--color-accent) 22%, var(--color-bg));
    color: var(--color-text);
    border-color: color-mix(in srgb, var(--color-accent) 45%, var(--color-border));
}

.table--explore .explore-bucket-chip[data-bucket-index="1"] {
    background: color-mix(in srgb, #6366f1 24%, var(--color-bg));
    color: var(--color-text);
    border-color: color-mix(in srgb, #6366f1 50%, var(--color-border));
}

.table--explore .explore-bucket-chip[data-bucket-index="2"] {
    background: color-mix(in srgb, #c026d3 22%, var(--color-bg));
    color: var(--color-text);
    border-color: color-mix(in srgb, #c026d3 45%, var(--color-border));
}

.table--explore .explore-bucket-chip[data-bucket-index="3"] {
    background: color-mix(in srgb, #ea580c 22%, var(--color-bg));
    color: var(--color-text);
    border-color: color-mix(in srgb, #ea580c 45%, var(--color-border));
}

.table--explore .explore-bucket-chip[data-bucket-index="4"],
.table--explore .explore-bucket-chip[data-bucket-index="5"],
.table--explore .explore-bucket-chip[data-bucket-index="6"],
.table--explore .explore-bucket-chip[data-bucket-index="7"] {
    background: color-mix(in srgb, var(--color-text-muted) 18%, var(--color-bg));
    color: var(--color-text);
    border-color: var(--color-border);
}

.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="0"] {
    background: color-mix(in srgb, var(--color-accent) 22%, var(--color-bg-elevated));
}

.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="1"] {
    background: color-mix(in srgb, #6366f1 24%, var(--color-bg-elevated));
}

.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="2"] {
    background: color-mix(in srgb, #c026d3 22%, var(--color-bg-elevated));
}

.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="3"] {
    background: color-mix(in srgb, #ea580c 22%, var(--color-bg-elevated));
}

.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="4"],
.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="5"],
.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="6"],
.table--explore tbody tr:hover .explore-bucket-chip[data-bucket-index="7"] {
    background: color-mix(in srgb, var(--color-text-muted) 18%, var(--color-bg-elevated));
}

/* Explore list: row opens application detail */
.application-row {
    cursor: pointer;
}

.application-row:hover {
    background: var(--color-overlay);
}

.application-details-row {
    background: var(--color-background-alt);
}

.application-details {
    padding: var(--space-md);
}

.application-details__section {
    margin-bottom: var(--space-md);
}

.application-details__section:last-child {
    margin-bottom: 0;
}

.application-details__label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
    font-family: var(--font-secondary);
}

.application-details__keywords {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

/* HTMX Loading States */
.htmx-request .loading {
    opacity: 0.5;
}

.htmx-request .loading::after {
    content: " …";
}

/* Responsive */
@media (max-width: 640px) {
    .site-header .container {
        flex-direction: column;
        gap: var(--space-md);
    }

    .logo--planpony {
        flex-direction: column;
        align-items: flex-start;
        max-width: 100%;
    }

    .main-nav {
        gap: var(--space-xs);
        flex-wrap: wrap;
        justify-content: center;
    }

    .main-nav a {
        padding: var(--space-xs) var(--space-md);
        font-size: 0.8rem;
    }

    .search-box {
        flex-direction: column;
    }

    .filters {
        flex-direction: column;
    }

    .filters .form-group {
        min-width: 100%;
    }

    .detail-list--inline {
        flex-direction: column;
        gap: var(--space-md);
    }
}

/* Application detail — in-page search (below details grid) */
.detail-search {
    margin-top: var(--space-lg);
}

.detail-search__heading {
    font-size: 1.1rem;
    margin-bottom: var(--space-sm);
}

.detail-search__row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    align-items: flex-start;
}

.detail-search__actions .form-label {
    visibility: hidden;
}

.detail-search__nav {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-md);
    flex-wrap: wrap;
}

.detail-search__counter {
    font-variant-numeric: tabular-nums;
    min-width: 4rem;
}

.detail-search-snippet {
    margin-top: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
}

.detail-search-snippet__text {
    margin: 0;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-search-snippet mark {
    background: var(--color-highlight-mark);
    color: inherit;
    padding: 0 0.1em;
}

.detail-distance-pill {
    display: inline-block;
    margin-left: var(--space-sm);
    padding: 0.2rem 0.6rem;
    font-size: 0.85rem;
    border-radius: 999px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
}

kbd {
    display: inline-block;
    padding: 0.1em 0.4em;
    font-size: 0.8em;
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
}

/* --- Explore: terminal shell + refine aside --- */
#applications-section {
    min-width: 0;
    max-width: 100%;
}

:root {
    --explore-header-band: var(--color-bg);
}

.container--explore {
    max-width: 100%;
    width: 100%;
    min-width: 0;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    margin-top: 0;
    padding-top: var(--space-md);
    background: var(--explore-header-band);
    border-bottom: 1px solid var(--color-border);
}

.section-heading-terminal {
    font-family: var(--font-primary);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0 0 var(--space-sm);
    color: var(--color-heading);
}

.section-heading-terminal--sub {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: lowercase;
    margin: 0 0 var(--space-sm);
    color: var(--color-text-muted);
}

.explore-app {
    display: grid;
    grid-template-columns: minmax(240px, 20rem) 1fr;
    gap: var(--space-lg);
    align-items: stretch;
    min-height: calc(100dvh - 5.5rem);
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

/* Form wraps refine aside only; display:contents so aside participates in explore-app grid */
.explore-app > .explore-refine__form {
    display: contents;
}

.explore-app--refine-collapsed {
    grid-template-columns: minmax(2.75rem, auto) 1fr;
}

.explore-rail {
    position: sticky;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: calc(100dvh - 5.25rem);
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-elevated);
    font-family: var(--font-primary);
}

.explore-rail--refine {
    top: calc(var(--space-md) + 3.25rem);
}

.explore-refine {
    /* aside also has .explore-rail; inner column fills rail */
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-primary);
}

/* .filters__form is row flex + wrap for dashboard filters; Explore needs a vertical stack full-width. */
.explore-refine__form.filters__form {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    align-content: stretch;
    gap: 0;
    width: 100%;
    min-width: 0;
}

.explore-refine__form .explore-refine__scroll,
.explore-refine__form .explore-refine__foot,
.explore-refine__form .explore-refine__actions,
.explore-refine__form .explore-refine__footer {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
}

.explore-refine__form .explore-refine__scroll {
    flex: 1 1 auto;
    min-height: 0;
}

.explore-app--refine-collapsed .explore-rail {
    align-self: start;
    border-color: transparent;
    background: transparent;
}

/*
 * Explore refine — layout hierarchy
 * L0: .explore-refine (rail shell)
 * L1: .explore-refine__rail-cap (chrome row: // query + −/+; no bottom border — flows into scroll)
 * L1: .explore-refine__body > .explore-refine__scroll (no horizontal padding — rules bleed)
 * L2: .explore-refine__scroll > .explore-refine__segment — padded bands; no full-width dividers between segments (foot keeps internal rule above save)
 * L3: .explore-refine__advanced-panel — nested accordions; no inter-row dividers; bodies indented
 */
/* Top rail: single control — // query + trailing − (expanded) / + (collapsed) for panel open/close. */
.explore-refine__rail-cap {
    width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
    padding: 0.55rem var(--space-md);
    border-bottom: 1px solid var(--color-border);
    min-height: 2.5rem;
}

.explore-app--refine-collapsed .explore-refine__rail-cap {
    border-bottom: none;
    padding: var(--space-xs) var(--space-sm);
}

.explore-app--refine-collapsed .explore-refine__toggle-query-rest {
    display: none;
}

.explore-app--refine-collapsed .explore-refine__rail-cap-icon {
    display: none;
}

.explore-refine__rail-cap-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-heading);
    font: inherit;
    cursor: pointer;
    text-align: left;
}

.explore-app--refine-collapsed .explore-refine__rail-cap-toggle {
    justify-content: center;
    text-align: center;
}

.explore-refine__rail-cap-toggle:hover,
.explore-refine__rail-cap-toggle:hover .explore-refine__row-heading__label,
.explore-refine__rail-cap-toggle:hover .explore-refine__toggle-slash,
.explore-refine__rail-cap-toggle:hover .explore-refine__toggle-query-rest,
.explore-refine__rail-cap-toggle:hover .explore-refine__rail-cap-icon {
    color: var(--color-accent);
}

.explore-refine__rail-cap-toggle:hover .explore-refine__rail-cap-icon {
    opacity: 1;
}

.explore-refine__rail-cap-label {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    text-align: inherit;
}

.explore-refine__rail-cap-icon {
    flex-shrink: 0;
    font-weight: 400;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.75;
}

.explore-refine__or-append-row {
    margin-top: var(--space-xs);
}

/* Outlined control — distinct from expand/collapse + icons in row headings. */
.explore-refine__or-append {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-heading);
    font-family: var(--font-primary);
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.35;
    cursor: pointer;
}

.explore-refine__or-append:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.explore-refine__or-append-mark {
    font-size: 0.95rem;
    line-height: 1;
    opacity: 0.85;
}

.explore-refine__or-append-label {
    text-transform: none;
    letter-spacing: normal;
}

.explore-refine__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0;
    overflow: hidden;
}

.explore-app--refine-collapsed .explore-refine__body {
    display: none;
}

.explore-refine__scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-anchor: none;
    padding: 0;
}

/* Major vertical bands: padding inside each band (no border between advanced and foot). */
.explore-refine__scroll > .explore-refine__segment {
    padding: var(--space-md);
}

.explore-refine__section {
    margin: 0;
}

.explore-refine__advanced {
    margin: 0;
    padding: 0;
    border: none;
}

.explore-refine__advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0;
    margin: 0;
    border: none;
    background: transparent;
    color: var(--color-heading);
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.45;
    cursor: pointer;
    text-align: left;
    min-height: 2.25rem;
}

.explore-refine__advanced-toggle:hover,
.explore-refine__advanced-toggle:hover .explore-refine__advanced-toggle-label,
.explore-refine__advanced-toggle:hover .explore-refine__advanced-toggle-icon {
    color: var(--color-accent);
}

.explore-refine__advanced-toggle-icon {
    font-weight: 400;
    opacity: 0.75;
    flex-shrink: 0;
    margin-left: var(--space-sm);
}

.explore-refine__row-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
    min-height: 2.25rem;
    padding: 0.45rem 0;
    margin: 0 0 var(--space-xs);
}

.explore-refine__row-heading--static {
    justify-content: flex-start;
}

.explore-refine__row-heading__label {
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 300;
    text-transform: lowercase;
    color: var(--color-heading);
    line-height: 1.45;
}

.explore-refine__row-heading__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    margin-left: var(--space-sm);
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-heading);
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1;
    opacity: 0.75;
    cursor: pointer;
    flex-shrink: 0;
}

.explore-refine__row-heading__icon:hover {
    color: var(--color-accent);
}

.explore-refine__keyword-groups {
    margin-top: var(--space-md);
}

.explore-refine__advanced-panel {
    padding-top: 0;
}

.explore-refine__advanced-panel[hidden] {
    display: none !important;
}

.explore-refine__hint {
    margin: 0 0 var(--space-sm);
    font-size: 0.75rem;
}

.explore-or-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin: var(--space-sm) 0 var(--space-md);
}

.explore-or-chips--empty {
    margin: 0;
}

.explore-or-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    font-size: 0.8rem;
    font-family: var(--font-primary);
}

.explore-or-chip__remove {
    margin: 0;
    padding: 0 0.15rem;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.explore-or-chip__remove:hover {
    color: var(--color-accent);
}

.explore-group-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.explore-group-chip {
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-bg-muted);
    color: var(--color-text);
    font-size: 0.8rem;
    font-family: var(--font-primary);
    cursor: pointer;
}

.explore-group-chip.is-selected {
    border-color: var(--color-accent);
    background: var(--color-bg);
    box-shadow: 0 0 0 1px var(--color-accent);
}

.form-input--explore-query {
    font-size: 0.9rem;
}

.explore-refine__advanced-panel .explore-accordion {
    margin: 0;
    border: none;
    border-radius: 0;
    background: transparent;
}

.explore-accordion__summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
    padding: 0.45rem 0;
    margin: 0;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 400;
    text-transform: lowercase;
    color: var(--color-heading);
    line-height: 1.45;
}

.explore-refine__advanced-panel .explore-accordion__summary:hover,
.explore-refine__advanced-panel .explore-accordion__summary:hover .explore-refine__row-heading__label {
    color: var(--color-accent);
}

.explore-accordion__summary::-webkit-details-marker {
    display: none;
}

.explore-accordion__summary::after {
    content: "+";
    font-weight: 400;
    opacity: 0.75;
    flex-shrink: 0;
    margin-left: var(--space-sm);
}

.explore-accordion[open] > .explore-accordion__summary::after {
    content: "\2212";
}

.explore-accordion__body {
    padding: 0 0 var(--space-sm);
}

.explore-refine__advanced-panel .explore-accordion__body {
    padding-left: var(--space-md);
}

.explore-refine__date-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.explore-refine__foot {
    margin: 0;
}

.explore-refine__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin: 0;
    padding: 0 0 var(--space-sm);
}

.explore-refine__footer {
    padding: var(--space-md) 0 0;
    border-top: 1px solid var(--color-border);
}

.explore-refine__save.is-disabled {
    opacity: 0.55;
    pointer-events: none;
    cursor: not-allowed;
}

.explore-results {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
}

.explore-results__table-wrap {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.explore-results__message {
    margin: 0 0 var(--space-md);
}

.explore-results__toolbar {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.explore-view-toggle__btn.is-active {
    background: var(--color-accent);
    color: var(--color-on-accent);
    border-color: var(--color-accent);
}

.explore-view-toggle__btn.is-active:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: var(--color-on-accent);
}

.results-info {
    margin-bottom: var(--space-md);
}

.results-info__row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-xs) var(--space-md);
}

.results-info__count {
    margin: 0;
}

.results-info__page {
    margin: 0;
    margin-left: auto;
    text-align: right;
}

.table-wrapper--explore {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    container-type: inline-size;
    container-name: explore-list;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.table--explore {
    font-family: var(--font-primary);
    font-size: 0.85rem;
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
    box-sizing: border-box;
}

.table--explore th {
    border-color: var(--color-border);
    box-sizing: border-box;
    vertical-align: bottom;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
    /* Extra trailing room so sort arrows are not flush against the next column. */
    padding-inline-end: calc(var(--space-md) + 0.55rem);
}

.table--explore th a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.table--explore td {
    border-color: var(--color-border);
    box-sizing: border-box;
    vertical-align: top;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
}

.table--explore .explore-col--matched .matched-keywords {
    max-width: none;
}

.table--explore .explore-match-reason {
    margin-top: 0.35rem;
    margin-bottom: 0;
    max-width: 18rem;
    line-height: 1.35;
}

/* Description body: up to four lines (header stays single-line via th rules). */
.table--explore td.explore-col--desc .explore-desc-cell {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
}

.table--explore tbody tr:hover {
    background: var(--color-bg-elevated);
}

/*
 * Fixed column targets: min-width keeps each column at least as wide as its header;
 * max-width caps growth. Hidden columns (container queries) free space for the rest.
 */
.table--explore .explore-col--ref {
    /* Wider than a bare % so typical refs stay one line under table-layout: fixed. */
    width: 13%;
    min-width: 12.5rem;
    max-width: none;
}

/* .table--explore td sets word-break: break-word — that splits references mid-string. */
.table--explore td.explore-col--ref {
    white-space: normal;
    word-break: normal;
    /* Wrap only when an unbroken string overflows; unlike word-break: break-word on td. */
    overflow-wrap: break-word;
}

.table--explore td.explore-col--ref .ref-link {
    word-break: normal;
    overflow-wrap: inherit;
}

.table--explore .explore-col--relevance {
    width: 7%;
    min-width: 7.5rem;
    max-width: 8.5rem;
}

.table--explore .explore-col--matched {
    width: 14%;
    min-width: 12.75rem;
    max-width: 15rem;
}

.table--explore .explore-col--address {
    width: 16%;
    min-width: 6.75rem;
    max-width: 16rem;
}

.table--explore .explore-col--desc {
    width: 26%;
    min-width: 7.5rem;
    max-width: 24rem;
}

.table--explore .explore-col--type {
    width: 11%;
    min-width: 5.25rem;
    max-width: 11rem;
}

.table--explore .explore-col--status {
    width: 9%;
    min-width: 6.25rem;
    max-width: 9rem;
}

.table--explore .explore-col--received {
    width: 8%;
    min-width: 7.25rem;
    max-width: 7.5rem;
}

.table--explore .explore-col--distance {
    width: 7%;
    min-width: 6.75rem;
    max-width: 7.25rem;
}

.table--explore .explore-col--portal {
    width: 7%;
    min-width: 5.75rem;
    max-width: 6.5rem;
}

/*
 * Explore: hide whole columns as the list narrows (no horizontal scroll).
 * Order = lowest value first: portal → distance → received → status → type →
 * description → address → matched → relevance (reference always kept).
 * Thresholds are tuned so extra FTS/matched columns do not squeeze text.
 */
@container explore-list (max-width: 1680px) {
    .table--explore .explore-col--portal {
        display: none;
    }
}

@container explore-list (max-width: 1520px) {
    .table--explore .explore-col--distance {
        display: none;
    }
}

@container explore-list (max-width: 1380px) {
    .table--explore .explore-col--received {
        display: none;
    }
}

@container explore-list (max-width: 1240px) {
    .table--explore .explore-col--status {
        display: none;
    }
}

@container explore-list (max-width: 1120px) {
    .table--explore .explore-col--type {
        display: none;
    }
}

@container explore-list (max-width: 980px) {
    .table--explore .explore-col--desc {
        display: none;
    }
}

@container explore-list (max-width: 820px) {
    .table--explore .explore-col--address {
        display: none;
    }
}

@container explore-list (max-width: 640px) {
    .table--explore .explore-col--matched {
        display: none;
    }
}

@container explore-list (max-width: 480px) {
    .table--explore .explore-col--relevance {
        display: none;
    }
}

@media (max-width: 960px) {
    .explore-app {
        grid-template-columns: 1fr;
    }

    .explore-app--refine-collapsed {
        grid-template-columns: 1fr;
    }

    .explore-rail {
        position: static;
        max-height: none;
    }

    .explore-app--refine-collapsed .explore-refine__body {
        display: block;
    }
}

/* --- Breadcrumb path (detail & inner pages) --- */
.breadcrumb--path {
    margin-bottom: var(--space-lg);
    font-size: 0.85rem;
}

.breadcrumb-path {
    font-family: var(--font-primary);
    color: var(--color-text-muted);
    word-break: break-word;
}

.breadcrumb-path a {
    color: var(--color-link);
    text-decoration: none;
}

.breadcrumb-path a:hover {
    text-decoration: underline;
}

.breadcrumb-path__sep {
    color: var(--color-border);
    user-select: none;
}

.breadcrumb-path__current {
    color: var(--color-heading);
}

/* Data tables: structured output */
.subscriptions-table,
.data-table {
    font-family: var(--font-primary);
    font-size: 0.85rem;
}

/* Print Styles */
@media print {
    .site-header,
    .site-footer,
    .main-nav {
        display: none;
    }

    .main-content {
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }
}
