/* ---------------------------------------------------------------------------
   Tokens
--------------------------------------------------------------------------- */
:root {
    /* Tropical palette: deep green night, cream text, coconut-husk amber accent */
    --bg-color: #0c1411;
    --surface: #14201b;
    --surface-soft: rgba(22, 35, 29, 0.78);
    --text-main: #f4f1e8;
    --text-muted: #a3b2a9;
    --border-color: rgba(244, 241, 232, 0.09);
    --accent: #f2b544;
    --accent-hover: #e3a22d;
    --accent-ink: #1d1505;      /* text on the accent colour */
    --accent-soft: rgba(242, 181, 68, 0.14);
    --accent-green: #6fd49a;
    --danger: #ff7a6b;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --radius: 14px;
    --shadow-glow: 0 0 28px rgba(242, 181, 68, 0.08);
    --gutter: 2rem;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

/* ---------------------------------------------------------------------------
   Top bar
--------------------------------------------------------------------------- */
.topbar {
    border-bottom: 1px solid var(--border-color);
    background: rgba(12, 20, 17, 0.88);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 2000; /* above Leaflet panes */
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem var(--gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
}

.brand-mark { font-size: 1.5rem; }
.brand-org {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-muted);
}
.brand-sep { color: var(--text-muted); font-weight: 400; }
.highlight { color: var(--accent); }

.social-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.social-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    background: var(--surface-soft);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.social-links a.docs-link {
    width: auto;
    gap: 0.4rem;
    padding: 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .social-links a.docs-link { width: 38px; padding: 0; }
    .docs-link-label { display: none; }
}

.social-links a:hover {
    color: var(--text-main);
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ---------------------------------------------------------------------------
   Layout
--------------------------------------------------------------------------- */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2.5rem var(--gutter) 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

/* ---------------------------------------------------------------------------
   Intro
--------------------------------------------------------------------------- */
.intro { text-align: center; }

.intro h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.lede {
    margin: 0.75rem auto 0;
    max-width: 620px;
    color: var(--text-muted);
    font-size: 1.05rem;
}

.steps {
    list-style: none;
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.steps li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem 0.55rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: left;
}

.steps strong { color: var(--text-main); font-weight: 600; }

.step-num {
    flex: none;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
}

/* ---------------------------------------------------------------------------
   Map card: toolbar + map
--------------------------------------------------------------------------- */
.map-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow-glow);
}

.map-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 42px;
    padding: 0 1rem;
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary[aria-pressed="true"] {
    background: var(--text-main);
    color: var(--bg-color);
}

.btn-ghost {
    background: transparent;
    color: var(--text-main);
    border-color: var(--border-color);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.4; cursor: default; }

.map-status {
    flex: 1 1 260px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.map-status strong { color: var(--text-main); }
.map-status.is-error { color: var(--danger); }
.map-status.is-success strong:first-child { color: var(--accent-green); }

.map-wrapper {
    position: relative;
    height: 50vh;
    min-height: 360px;
    max-height: 560px;
}

#main-map { width: 100%; height: 100%; }

#main-map.drawing-box,
#main-map.drawing-box .leaflet-interactive {
    cursor: crosshair;
    touch-action: none; /* the drag draws instead of scrolling/zooming the page */
}

.draw-tooltip { font-family: var(--font-family); }

/* Coordinates bar under the map */
.map-coords {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    min-height: 40px;
}
.coords-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.coords-value {
    color: var(--text-main);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
}
.coords-zoom { margin-left: auto; }
.coords-copy {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
}
.coords-copy:hover { border-color: var(--accent); color: var(--accent); }

/* Loading overlay */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(12, 20, 17, 0.75);
    backdrop-filter: blur(3px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-weight: 600;
    transition: opacity 0.25s ease;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.9rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Workspace: map on the left, this session's count and the steps on the right
--------------------------------------------------------------------------- */
.workspace { display: grid; gap: 1rem; }
.panel-title { display: none; }
.panel-howto { display: none; }

/* Narrow screens: no room beside the map, so the count is one compact bar above it. */
@media (max-width: 900px) {
    .workspace { gap: 0.6rem; }
    .side-panel { order: -1; }
    .side-panel .metrics-section {
        grid-template-columns: 1.1fr 1fr 1fr;
        gap: 0;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        background: var(--surface-soft);
    }
    .side-panel .metric-card {
        background: none;
        border: none;
        border-radius: 0;
        padding: 0.5rem 0.75rem;
        text-align: left;
    }
    .side-panel .metric-card + .metric-card { border-left: 1px solid var(--border-color); }
    .side-panel .metric-card h3 { font-size: 0.65rem; white-space: nowrap; }
    .side-panel .metric-value { font-size: 1.15rem; margin-top: 0.1rem; color: var(--text-main); }
    .side-panel .metric-hero .metric-value { color: var(--accent-green); }
    .side-panel .metric-unit { display: inline; margin: 0 0 0 0.25rem; font-size: 0.7rem; }
}

@media (min-width: 901px) {
    .workspace { grid-template-columns: minmax(0, 1fr) 17.5rem; align-items: stretch; }

    .side-panel {
        display: flex;
        flex-direction: column;
        padding: 1.4rem 1.4rem 1.25rem;
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        background: var(--surface);
    }
    .panel-title {
        display: block;
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-muted);
    }

    /* One hero number, two supporting ones: no boxes inside the panel. */
    .side-panel .metrics-section { grid-template-columns: 1fr 1fr; gap: 1.1rem 1rem; margin-top: 0.9rem; }
    .side-panel .metric-card { background: none; border: none; border-radius: 0; padding: 0; }
    .side-panel .metric-hero { grid-column: 1 / -1; padding-bottom: 1.1rem; border-bottom: 1px solid var(--border-color); }
    .side-panel .metric-card h3 { font-size: 0.8rem; text-transform: none; letter-spacing: 0; font-weight: 500; }
    .side-panel .metric-value { font-size: 1.35rem; color: var(--text-main); margin-top: 0.2rem; }
    .side-panel .metric-hero .metric-value { font-size: 3.25rem; color: var(--accent-green); letter-spacing: -0.03em; }
    .side-panel .metric-unit { font-size: 0.8rem; margin-left: 0.25rem; }

    .panel-howto { display: block; margin-top: 1.5rem; padding-top: 1.4rem; border-top: 1px solid var(--border-color); }
    .side-panel .steps { flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 0.85rem; margin-top: 0.9rem; }
    .side-panel .steps li { padding: 0; border: none; border-radius: 0; background: none; align-items: flex-start; line-height: 1.4; }
    .side-panel .steps strong { display: block; }
    .panel-note { margin-top: 1.25rem; color: var(--text-muted); font-size: 0.8rem; line-height: 1.5; }
}

/* ---------------------------------------------------------------------------
   Session metrics
--------------------------------------------------------------------------- */
.metrics-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.metric-card {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}

.metric-card h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.metric-value {
    margin-top: 0.35rem;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-green);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.metric-unit {
    margin-left: 0.35rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   Statistics
--------------------------------------------------------------------------- */
.stats-section {
    margin-top: 1.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.section-head { margin-bottom: 1.25rem; }
.section-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.section-sub { color: var(--text-muted); margin-top: 0.25rem; }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.25rem;
    align-items: start;
}

.stats-summary { display: flex; flex-direction: column; gap: 0.75rem; }

.stat-item {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label { color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.heatmap-wrapper {
    height: 420px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
}
#heatmap-map { width: 100%; height: 100%; }

.table-container {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 0.7rem 1.1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
tbody tr:last-child td { border-bottom: none; }
th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
}
.num, td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   Live from the server (static/js/status.js)
--------------------------------------------------------------------------- */
.live-section {
    --series-web: #b87d18;   /* website spans */
    --series-det: #3987c9;   /* detector spans and stages */
    --meter: #3d9c74;
    position: relative;
    margin-top: 1.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}
.live-section[hidden], .social-links a[hidden] { display: none; }
.live-section { scroll-margin-top: 4.5rem; }

.live-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
}
.live-link { text-decoration: none; font-size: 0.875rem; min-height: 38px; }
.live-link:hover { border-color: var(--accent); color: var(--accent); }

.live-card {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem 1.25rem;
    min-width: 0;
}
.live-card-title { font-size: 1rem; font-weight: 600; }
.live-card-sub { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.15rem; }
.live-empty { color: var(--text-muted); font-size: 0.9rem; margin-top: 1rem; }

/* Tiles: server gauges and containers */
.live-group {
    margin: 1.5rem 0 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-main);
}
.live-group span { margin-left: 0.5rem; color: var(--text-muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.live-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.live-split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; align-items: start; }

.tile {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem 1rem;
    min-width: 0;
}
.tile-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.tile-value { margin-top: 0.15rem; font-size: 1.6rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile-value small { margin-left: 0.3rem; font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.tile-detail { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.4rem; }
.meter-track {
    height: 8px;
    position: relative;
    margin-top: 0.55rem;
    border-radius: 4px;
    background: rgba(244, 241, 232, 0.08);
    overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 4px; background: var(--meter); transition: width 0.4s ease; }
/* Highest value seen in the window: a tick on the bar, keyed in the line below. */
.meter-peak { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--text-main); }
.tile-peak { display: flex; align-items: center; gap: 0.4rem; color: var(--text-muted); font-size: 0.78rem; margin-top: 0.25rem; }
.peak-key { flex: none; width: 2px; height: 0.8rem; background: var(--text-main); }

.spark { margin-top: 0.6rem; }
.spark svg { display: block; width: 100%; height: 28px; overflow: visible; touch-action: pan-y; }
.spark-line { fill: none; stroke: var(--meter); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-base { stroke: rgba(244, 241, 232, 0.12); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-dot { fill: var(--text-main); stroke: var(--surface); stroke-width: 2; }
.spark-note { display: block; color: var(--text-muted); font-size: 0.7rem; margin-top: 0.2rem; }


/* Time per step */
.hbars { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 1rem; }
.hbar-row { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 0.75rem; align-items: center; font-size: 0.85rem; }
.hbar-label { color: var(--text-main); }
.hbar-value { color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: right; }
.hbar-track { grid-column: 1 / -1; grid-row: 2; height: 10px; }
.hbar { height: 100%; min-width: 3px; border-radius: 0 4px 4px 0; background: var(--series-det); }

/* Trace waterfall */
.trace-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.legend { list-style: none; display: flex; gap: 1rem; color: var(--text-muted); font-size: 0.8rem; }
.legend li { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }
.swatch-web { background: var(--series-web); }
.swatch-det { background: var(--series-det); }

.trace { margin-top: 1rem; }
.trace-row {
    display: grid;
    grid-template-columns: minmax(0, 17rem) minmax(0, 1fr) 4.5rem;
    gap: 0.75rem;
    align-items: center;
    padding: 0.35rem 0;
    border-radius: 6px;
}
.trace-row:not(.trace-axis):hover { background: rgba(244, 241, 232, 0.04); }
.trace-name { min-width: 0; }
.trace-label { display: block; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trace-raw { display: block; color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trace-lane { position: relative; height: 14px; border-left: 1px solid rgba(244, 241, 232, 0.12); }
.trace-bar { position: absolute; top: 0; height: 100%; min-width: 3px; border-radius: 4px; }
.trace-bar.is-web { background: var(--series-web); }
.trace-bar.is-det { background: var(--series-det); }
.trace-time { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; text-align: right; }
.trace-ticks { display: flex; justify-content: space-between; height: auto; border-left: none; color: var(--text-muted); font-size: 0.7rem; font-variant-numeric: tabular-nums; }

.viz-tip {
    position: absolute;
    z-index: 1500;
    max-width: 280px;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #1c2b25;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.viz-tip[hidden] { display: none; }
.viz-tip-title { color: var(--text-main); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Footer
--------------------------------------------------------------------------- */
.footer {
    border-top: 1px solid var(--border-color);
    padding: 1.25rem var(--gutter);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.footer a { color: var(--text-main); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .live-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .live-split { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .heatmap-wrapper { height: 340px; }
}

@media (max-width: 640px) {
    :root { --gutter: 1rem; }
    .app-container { padding-top: 1.5rem; gap: 1.25rem; }
    .intro h1 { font-size: 1.5rem; }
    .lede { font-size: 0.9rem; margin-top: 0.5rem; }
    .map-toolbar { padding: 0.75rem; }
    .map-toolbar .btn { flex: 1 1 auto; padding: 0 0.75rem; }
    .brand { font-size: 1.15rem; }
    .brand-org { font-size: 0.8rem; }
    .map-status { flex-basis: 100%; }
    .map-wrapper { height: 48vh; min-height: 320px; }
    .map-coords { padding: 0.5rem 0.75rem; gap: 0.5rem; font-size: 0.8rem; }
    .coords-label { display: none; }
    .live-tiles { gap: 0.6rem; }
    .tile { padding: 0.75rem 0.85rem 0.85rem; }
    .tile-value { font-size: 1.3rem; }
    .live-group span { display: block; margin: 0.15rem 0 0; }
    .trace-row { grid-template-columns: minmax(0, 1fr) 4.5rem; gap: 0.25rem 0.75rem; }
    .trace-row .trace-lane { grid-column: 1 / -1; grid-row: 2; }
    .trace-raw { display: none; }
    .trace-name { padding-left: 0 !important; }
}
