:root {
    --navy-900: #0f172a;
    --navy-850: #162338;
    --navy-800: #1e293b;
    --navy-700: #334155;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --green-500: #22c55e;
    --green-600: #16a34a;
    --yellow-400: #facc15;
    --orange-400: #fb923c;
    --red-400: #f87171;
    --white: #ffffff;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    --border: rgba(148, 163, 184, 0.2);
    --glass: rgba(51, 65, 85, 0.55);
    --transition: 0.2s ease;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: linear-gradient(135deg, var(--navy-900), var(--navy-800), var(--navy-900));
    color: var(--white);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Layout */

.site-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: min(1200px, 92vw);
    margin: 0 auto;
}

.page-content {
    flex: 1;
    padding: 0 0 4rem;
}

/* Topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
}

/* Brand */

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 700;
}

.brand-mark {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--blue-500), var(--green-500));
    color: var(--white);
}

.brand-text {
    font-size: 1.2rem;
}

/* Navigation */

.nav-links {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;

    & a {
        padding: 0.45rem 0.8rem;
        border-radius: 999px;
        color: var(--slate-300);
        transition: background-color var(--transition), color var(--transition);

        &:is(:hover, .active) {
            color: var(--white);
            background: rgba(51, 65, 85, 0.7);
        }
    }
}

.mobile-nav-toggle {
    display: none;
    border: 0;
    background: transparent;
    color: var(--slate-300);
    padding: 0.35rem;
    border-radius: var(--radius-sm);
    cursor: pointer;

    &:hover {
        color: var(--white);
        background: var(--glass);
    }
}

.mobile-nav {
    display: none;
    border-top: 1px solid var(--border);
    padding: 0.75rem 0 0.95rem;

    & a {
        display: block;
        padding: 0.55rem 0.75rem;
        border-radius: var(--radius-sm);
        color: var(--slate-300);

        &:is(.active, :hover) {
            background: rgba(51, 65, 85, 0.7);
            color: var(--white);
        }
    }
}

/* Footer */

.footer {
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.55);
    color: var(--slate-400);
    padding: 1.6rem 0;
    text-align: center;
}

/* Cards */

.card {
    background: var(--navy-800);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);

    &:hover {
        transform: translateY(-2px);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    }
}

/* Typography */

.text-gradient {
    background: linear-gradient(135deg, var(--blue-500), var(--green-500));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Buttons */

.btn {
    border: 0;
    border-radius: 0.5rem;
    padding: 0.75rem 1.15rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: transform var(--transition), box-shadow var(--transition), background-color var(--transition), color var(--transition);

    &:hover {
        transform: translateY(-1px);
    }

    &:disabled {
        opacity: 0.55;
        cursor: not-allowed;
        transform: none;
    }
}

.btn-primary {
    background: var(--blue-500);
    color: var(--white);

    &:hover {
        background: var(--blue-600);
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    }
}

.btn-secondary {
    background: var(--green-500);
    color: var(--white);

    &:hover {
        background: var(--green-600);
        box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
    }
}

.btn-ghost {
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: var(--slate-300);
}

.btn-icon {
    width: 2.45rem;
    height: 2.45rem;
    padding: 0;
}

/* Page Header */

.page-header {
    text-align: center;
    margin: 2.5rem auto 2.1rem;

    & h1 {
        margin: 0;
        font-size: clamp(2rem, 5vw, 3rem);
    }

    & p {
        margin: 0.75rem auto 0;
        max-width: 720px;
        color: var(--slate-300);
    }
}

/* Hero */

.hero {
    position: relative;
    overflow: hidden;
    margin-top: 2rem;
    padding: 4rem 0 3.5rem;
}

.hero-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.08;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.2) 1px, transparent 1px);
    background-size: 20px 20px;
}

.hero-copy {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    text-align: center;

    & h1 {
        margin: 0;
        line-height: 1.1;
        font-size: clamp(2.5rem, 7vw, 4.4rem);
    }
}

.hero-subtitle {
    margin: 1rem auto 0;
    min-height: 3.3rem;
    max-width: 760px;
    color: var(--slate-300);
    font-size: clamp(1.05rem, 2.8vw, 1.4rem);
}

.hero-actions {
    margin-top: 1.45rem;
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    flex-wrap: wrap;
}

.live-chip {
    margin-top: 1.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: var(--slate-300);
    font-size: 0.85rem;
}

.live-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--green-500);
    animation: pulse 1.5s ease-in-out infinite;
}

/* Features */

.features {
    margin-top: 1rem;
}

.features-grid {
    display: grid;
    gap: 0.95rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.feature-card {
    & h3 {
        margin: 0;
        font-size: 1.1rem;
    }

    & p {
        margin: 0.5rem 0 0;
        color: var(--slate-300);
    }
}

.feature-icon {
    width: 2.8rem;
    height: 2.8rem;
    border-radius: 0.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.8rem;
    color: var(--white);
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

.icon-blue   { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.icon-green  { background: linear-gradient(135deg, #22c55e, #16a34a); }
.icon-purple { background: linear-gradient(135deg, #a855f7, #7c3aed); }
.icon-red    { background: linear-gradient(135deg, #ef4444, #dc2626); }
.icon-orange { background: linear-gradient(135deg, #fb923c, #ea580c); }

/* CTA */

.cta-section {
    margin-top: 1.5rem;

    & .card {
        text-align: center;
        background: linear-gradient(90deg, rgba(30, 41, 59, 0.8), rgba(51, 65, 85, 0.65));
    }
}

/* Forms */

.filter-card {
    margin-bottom: 1.2rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1.8fr 1fr 1fr;
    gap: 0.8rem;
}

label {
    display: block;

    & span {
        display: block;
        margin-bottom: 0.35rem;
        color: var(--slate-300);
        font-size: 0.82rem;
    }
}

:is(input, select) {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: var(--radius-sm);
    padding: 0.72rem 0.78rem;
    font: inherit;
    background: var(--glass);
    color: var(--white);

    &:focus {
        outline: 0;
        border-color: var(--blue-500);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
    }
}

input::placeholder {
    color: var(--slate-400);
}

.form-actions {
    margin-top: 0.8rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}

/* HTMX indicators */

:is(.loading-indicator, .htmx-indicator) {
    color: var(--slate-400);
    font-size: 0.85rem;
}

.htmx-indicator {
    opacity: 0;
    transition: opacity 120ms ease;
}

:is(.htmx-request .htmx-indicator, .htmx-request.htmx-indicator) {
    opacity: 1;
}

/* Results */

.results-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.9rem;

    & p {
        margin: 0;
        color: var(--slate-300);
    }
}

.track-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.8rem;
}

/* Track Cards */

.track-card {
    display: block;
    text-align: left;
    width: 100%;
    color: inherit;

    & h3 {
        margin: 0;
        font-size: 1rem;

        & a:hover {
            color: #60a5fa;
        }
    }

    & .location {
        margin: 0.5rem 0 0;
        color: var(--slate-300);
        font-size: 0.92rem;
    }

    & .state {
        margin: 0.2rem 0 0;
        color: var(--slate-400);
        font-size: 0.8rem;
    }
}

.track-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.65rem;
}

.track-meta {
    margin-top: 0.7rem;
    display: flex;
    justify-content: flex-end;
}

.track-actions {
    margin-top: 0.6rem;
    display: flex;
    justify-content: flex-end;
}

.track-link {
    color: #60a5fa;
    font-size: 0.88rem;
    font-weight: 600;

    &:hover {
        color: #93c5fd;
    }
}

.pill {
    font-size: 0.75rem;
    color: var(--slate-300);
    background: rgba(51, 65, 85, 0.7);
    border-radius: 999px;
    padding: 0.2rem 0.5rem;
    white-space: nowrap;
}

/* Pagination */

.pagination {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;

    & .btn {
        min-width: 2.4rem;
    }
}

/* Empty State */

.empty-state {
    text-align: center;

    & :is(h2, h3, p) {
        margin: 0.25rem 0;
    }
}

/* Stats */

.stats-card {
    margin-top: 1.2rem;
    text-align: center;
    background: linear-gradient(90deg, rgba(30, 41, 59, 0.6), rgba(51, 65, 85, 0.55));
}

.stats-grid {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;

    & strong {
        display: block;
        font-size: 1.4rem;
    }

    & span {
        color: var(--slate-400);
        font-size: 0.82rem;
    }
}

/* Breadcrumb */

.breadcrumb {
    margin: 2rem 0 0.8rem;
    color: var(--slate-400);
    font-size: 0.88rem;
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;

    & a {
        color: #60a5fa;
    }
}

/* Detail Pages */

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: 0.85rem 0 1rem;
}

.detail-head {
    margin-bottom: 1rem;
}

.detail-head-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;

    & h1 {
        margin: 0;
        font-size: clamp(1.7rem, 4vw, 2.35rem);
    }

    & p {
        margin: 0.35rem 0 0;
        color: var(--slate-300);
    }
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
    margin-bottom: 1rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;

    & > div {
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 0.65rem;
        background: rgba(51, 65, 85, 0.35);
    }

    & span {
        display: block;
        color: var(--slate-400);
        font-size: 0.82rem;
    }

    & strong {
        font-size: 0.96rem;
    }
}

.mono {
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    word-break: break-all;
}

.coords-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Density Status */

.density-chip {
    margin: 0.8rem 0 0;
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    border: 1px solid;
}

:is(.ok, .density-ok) {
    color: #86efac;
    background: rgba(20, 83, 45, 0.35);
    border-color: rgba(74, 222, 128, 0.5);
}

:is(.warn, .density-warn) {
    color: #fef08a;
    background: rgba(113, 63, 18, 0.3);
    border-color: rgba(250, 204, 21, 0.45);
}

:is(.high, .density-high) {
    color: #fdba74;
    background: rgba(124, 45, 18, 0.3);
    border-color: rgba(251, 146, 60, 0.45);
}

:is(.critical, .density-critical) {
    color: #fca5a5;
    background: rgba(127, 29, 29, 0.3);
    border-color: rgba(248, 113, 113, 0.45);
}

/* Forecast */

.forecast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.forecast-toggle {
    display: inline-flex;
    gap: 0.4rem;
}

.forecast-view[hidden] {
    display: none;
}

.chart-wrap {
    margin-top: 0.8rem;
    padding: 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.45);
    min-height: 310px;

    & canvas {
        width: 100%;
        height: 340px;
    }
}

/* Tables */

.table-wrap {
    margin-top: 0.75rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    background: rgba(15, 23, 42, 0.35);
}

:is(th, td) {
    padding: 0.62rem 0.7rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.18);
    text-align: left;
    font-size: 0.87rem;
}

th {
    background: rgba(51, 65, 85, 0.4);
    font-weight: 600;
}

/* Legend */

.legend-grid {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.7rem;
    text-align: center;
    font-size: 0.8rem;

    & span {
        display: block;
        color: var(--slate-400);
    }
}

/* Location */

.location-card {
    margin-bottom: 1rem;
}

.location-results {
    display: grid;
    gap: 0.95rem;
}

.radius-row {
    margin-top: 0.65rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.location-status {
    color: var(--slate-300);
    margin-top: 0.75rem;

    &.error {
        color: var(--red-400);
    }
}

/* Error */

.error-card :is(h1, h2) {
    margin-top: 0.2rem;
}

.muted {
    color: var(--slate-400);
}

/* Toast */

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 100;
    background: #16a34a;
    color: var(--white);
    border-radius: 0.6rem;
    padding: 0.65rem 0.9rem;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;

    &.visible {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animations */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Responsive */

@media (width <= 1100px) {
    :is(.features-grid, .stats-grid, .legend-grid) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (width <= 980px) {
    :is(.detail-grid, .form-grid) {
        grid-template-columns: 1fr;
    }
}

@media (width <= 760px) {
    .desktop-nav {
        display: none;
    }

    .mobile-nav-toggle {
        display: inline-flex;
    }

    .mobile-nav {
        display: block;

        &[hidden] {
            display: none;
        }
    }

    .hero {
        padding: 3rem 0 2.6rem;
    }

    :is(.hero-actions, .detail-actions, .form-actions) {
        width: 100%;

        & .btn {
            flex: 1;
        }
    }

    :is(.features-grid, .stats-grid, .legend-grid, .stat-grid) {
        grid-template-columns: 1fr;
    }
}
