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

:root {
    --bg-deep: #0a0a0a;
    --bg-base: #111111;
    --bg-surface: #1a1a1a;
    --bg-elevated: #222222;
    --bg-hover: #2a2a2a;
    --border: #333333;
    --border-bright: #444444;
    --text-primary: #e0e0e0;
    --text-secondary: #999999;
    --text-muted: #666666;
    --accent: #60a5fa;
    --accent-bright: #93c5fd;
    --green: #00c853;
    --green-dim: rgba(0, 200, 83, 0.12);
    --yellow: #fbbf24;
    --yellow-dim: rgba(251, 191, 36, 0.15);
    --orange: #f97316;
    --orange-dim: rgba(249, 115, 22, 0.15);
    --red: #ff1744;
    --red-dim: rgba(255, 23, 68, 0.12);
    --transition: 0.1s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Monospace for all data elements */
.cycle-table, .status-table, .detail-table, .db-footer,
.seg-flow, .stat-val, .health-stat .val, .sc-stat-value,
.fresh-date, .td-countdown, .badge, .stat-chip b,
.shc-value, .flow-val, .util-badge, .countdown-value {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

::selection {
    background: rgba(96, 165, 250, 0.3);
    color: #fff;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #444444; border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: #555555; }

/* ── Header (Status Bar) ────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 36px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 20;
}

header h1 {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

nav { display: flex; gap: 0; align-items: center; }

.pipe-selector {
    margin-right: 8px;
    padding-right: 8px;
    border-right: 1px solid var(--border);
}

.pipe-selector select {
    background: var(--bg-surface);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
    cursor: pointer;
    outline: none;
    transition: all var(--transition);
}

.pipe-selector select:hover {
    border-color: var(--accent);
}

.pipe-selector select option:disabled {
    color: var(--text-muted);
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 0;
    transition: all var(--transition);
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

nav a:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Short nav labels — hidden by default, shown on mobile */
.nav-short { display: none; }
.nav-full { display: inline; }

nav a.active {
    color: var(--accent);
    background: transparent;
    border-bottom: 2px solid var(--accent);
}

nav a.active::after {
    display: none;
}

/* ── Controls ────────────────────────────────────────────── */
.controls {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 6px 20px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
}

.controls label {
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 9px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.controls select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 24px 4px 8px;
    border-radius: 2px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

.controls select:hover {
    border-color: var(--accent);
}

.controls select:focus {
    outline: none;
    border-color: var(--accent);
}

.controls input[type="date"] {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 2px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition);
    color-scheme: dark;
}

.controls input[type="date"]:hover {
    border-color: var(--accent);
}

.controls input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
}

#last-updated {
    color: var(--text-muted);
    margin-left: auto;
    font-size: 10px;
    font-weight: 400;
}

/* ── Filter Toggle (hidden on desktop, shown on mobile) ─── */
.filter-toggle {
    display: none;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 500;
    font-family: "Inter", sans-serif;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
    width: fit-content;
    margin: 6px 10px 4px;
}

.filter-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.filter-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.filter-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 0;
    transition: all var(--transition);
}

.filter-close:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.filter-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.filter-backdrop.filter-open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Main Layout ─────────────────────────────────────────── */
.main-layout {
    display: flex;
    height: calc(100vh - 72px);
}

.main-layout--full {
    display: block;
    overflow-y: auto;
}

.map-panel {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.chart-panel {
    width: 480px;
    min-width: 200px;
    max-width: 800px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: relative;
}

.chart-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.02em;
}

.chart-header {
    padding: 14px 20px 6px;
}

.chart-header h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0;
}

.chart-stats {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 10px;
    color: var(--text-secondary);
}

.chart-stats .stat-val {
    color: var(--accent);
    font-weight: 600;
}

.chart-container {
    flex: 1;
    padding: 6px 16px 16px;
    min-height: 300px;
}

/* ── Zone Map ────────────────────────────────────────────── */
#zone-map {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.zone-group {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    overflow: hidden;
    transition: border-color var(--transition);
}

.zone-group:hover {
    border-color: var(--border-bright);
}

.zone-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
}

.zone-header:hover {
    background: var(--bg-hover);
}

.zone-header h3 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.zone-header .zone-info {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
}

.zone-arrow {
    display: inline-block;
    transition: transform 0.1s ease;
    font-size: 10px;
    margin-left: 4px;
}

.zone-group.collapsed .zone-arrow {
    transform: rotate(-90deg);
}

.zone-group.collapsed .zone-segments {
    display: none;
}

.zone-group.collapsed {
    border-bottom: none;
}

.zone-segments {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1px;
    background: var(--border);
}

.segment-card {
    background: var(--bg-base);
    padding: 6px 10px;
    cursor: pointer;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.segment-card:hover {
    background: var(--bg-surface);
}

.segment-card.selected {
    background: var(--bg-elevated);
    border-left-color: var(--accent);
}

.segment-card .seg-id {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0;
}

.segment-card .seg-name {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 400;
}

.segment-card .seg-flow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 10px;
}

.segment-card .seg-flow .flow-val {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.segment-card .seg-flow .util-badge {
    padding: 1px 6px;
    border-radius: 2px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Utilization colors — white <80% | orange 80% | dark orange 87.5% | light red 95% | red 100%+ */
.util-low { color: var(--text-primary); }
.util-med { color: var(--orange); }
.util-high { color: #e05a00; }
.util-warn { color: #ff6b6b; }
.util-crit { color: var(--red); }

.util-badge.util-low { background: rgba(224, 224, 224, 0.08); }
.util-badge.util-med { background: var(--orange-dim); }
.util-badge.util-high { background: rgba(224, 90, 0, 0.15); }
.util-badge.util-warn { background: rgba(255, 107, 107, 0.15); }
.util-badge.util-crit { background: var(--red-dim); }

/* ── Inline Accordion Charts ─────────────────────────────── */
.seg-expand-arrow {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.1s ease;
    margin-left: auto;
    opacity: 0.5;
}

.segment-card:hover .seg-expand-arrow {
    opacity: 0.8;
}

.segment-card.selected .seg-expand-arrow {
    transform: rotate(180deg);
    color: var(--accent);
    opacity: 1;
}

.seg-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-chart-panel {
    background: var(--bg-elevated);
    border-top: 2px solid var(--accent);
    padding: 16px 20px;
    animation: chartSlideIn 0.05s ease-out;
    position: relative;
    grid-column: 1 / -1;
}

@keyframes chartSlideIn {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 1; transform: translateY(0); }
}

.inline-chart-header {
    margin-bottom: 12px;
    position: relative;
}

.inline-chart-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0;
}

.inline-chart-seg {
    font-size: 10px;
    font-weight: 500;
    color: var(--accent);
    margin-left: 6px;
}

.inline-chart-stats {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    font-size: 10px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.stat-chip {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 2px 8px;
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.stat-chip b {
    color: var(--accent);
    font-weight: 600;
}

.inline-loading {
    color: var(--text-muted);
    font-size: 11px;
    font-style: italic;
}

.inline-no-data {
    color: var(--text-muted);
    font-size: 11px;
}

.inline-chart-container {
    height: 280px;
    position: relative;
    margin-top: 4px;
}

.seg-direction {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Control Center ──────────────────────────────────────── */
.control-layout {
    padding: 16px 20px;
    max-width: 1100px;
    margin: 0 auto;
}

.control-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    margin-bottom: 12px;
    overflow: hidden;
    transition: border-color var(--transition);
}

.control-section:hover {
    border-color: var(--border-bright);
}

.control-section h2 {
    font-size: 10px;
    font-weight: 600;
    padding: 8px 14px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    padding-left: 14px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: background var(--transition);
}

.control-section h2:hover {
    background: var(--bg-hover);
}

/* ── System Banner ──────────────────────────────────────── */
.system-banner {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-radius: 0;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    transition: all var(--transition);
}

.system-banner.system-visible {
    display: flex;
}

.system-banner-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.system-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-ok { background: var(--green); }
.dot-warn { background: var(--orange); }
.dot-err { background: var(--red); }

.dot-pulse {
    animation: dot-pulse-anim 1.5s ease-in-out infinite;
}

@keyframes dot-pulse-anim {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.system-text {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.system-banner-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.system-detail {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.banner-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 0;
    transition: all var(--transition);
    line-height: 1;
    font-family: inherit;
}

.banner-dismiss:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.system-ok { background: rgba(0, 200, 83, 0.06); border-color: #1a3d1a; }
.system-warn { background: rgba(255, 145, 0, 0.06); border-color: #3d2a00; }
.system-err { background: rgba(255, 23, 68, 0.06); border-color: #3d0a0a; }

.system-ok .system-text { color: var(--green); }
.system-warn .system-text { color: var(--orange); }
.system-err .system-text { color: var(--red); }

/* ── Data Freshness Grid ────────────────────────────────── */
.freshness-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: var(--border);
}

@media (max-width: 800px) {
    .freshness-grid { grid-template-columns: repeat(3, 1fr); }
}

.freshness-card {
    background: var(--bg-base);
    padding: 12px;
    text-align: center;
    transition: background var(--transition);
}

.freshness-card:hover {
    background: var(--bg-surface);
}

.fresh-cycle {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.fresh-date {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 3px;
    font-variant-numeric: tabular-nums;
}

.fresh-status {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.fresh-days {
    font-size: 9px;
    color: var(--text-muted);
}

.fresh-ok .fresh-cycle { color: var(--green); }
.fresh-ok .fresh-status { color: var(--green); }

.fresh-warn .fresh-cycle { color: var(--orange); }
.fresh-warn .fresh-status { color: var(--orange); }
.fresh-warn .fresh-date { color: var(--orange); }

.fresh-err .fresh-cycle { color: var(--red); }
.fresh-err .fresh-status { color: var(--red); }
.fresh-err .fresh-date { color: var(--red); }

/* ── Backfill Split Layout ────────────────────────────── */
.backfill-split {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    border-top: 1px solid var(--border);
}

.backfill-half {
    padding: 12px 16px;
}

.backfill-half-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.backfill-divider {
    width: 1px;
    background: var(--border);
}

.scraper-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 14px 16px;
    transition: border-color var(--transition);
}

.scraper-card:hover {
    border-color: var(--border-bright);
}

.sc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 10px;
}

.sc-header h3 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.sc-schedule {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
}

.sc-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 10px;
}

.sc-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sc-stat-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.sc-stat-value {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ── DB Footer ──────────────────────────────────────────── */
.db-footer {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    font-size: 10px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    margin-top: 6px;
}

.db-sep {
    color: var(--border-bright);
}

.status-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.status-table th {
    text-align: left;
    padding: 6px 14px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.status-table td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.status-table tr:last-child td { border-bottom: none; }

.status-table tr {
    transition: background var(--transition);
}

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 2px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-ok {
    background: var(--green-dim);
    color: var(--green);
}

.badge-warn {
    background: var(--orange-dim);
    color: var(--orange);
}

.badge-err {
    background: var(--red-dim);
    color: var(--red);
}

.health-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.health-stat {
    text-align: center;
    padding: 12px 10px;
    background: var(--bg-base);
    border-radius: 0;
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.health-stat:hover {
    border-color: var(--border-bright);
}

.health-stat .val {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.health-stat .lbl {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 3px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* ── Scraper Health Dashboard ────────────────────────────── */
.scraper-dashboard {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

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

.scraper-health-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition);
}

.scraper-health-card:hover {
    border-color: var(--border-bright);
}

.shc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.shc-header h3 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0;
}

.live-badge {
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border: 1px solid var(--border);
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.live-badge-active {
    background: var(--green-dim);
    color: var(--green);
    border-color: var(--green);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

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

.shc-body {
    flex: 1;
    margin-bottom: 10px;
}

.shc-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.shc-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.shc-value {
    font-size: 11px;
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.shc-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 0;
}

.shc-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 10px;
}

.shc-cycle-grid {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.cycle-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 8px;
    border-radius: 2px;
    border: 1px solid var(--border);
    min-width: 50px;
}

.cycle-pill-name {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}

.cycle-pill-day {
    font-size: 9px;
    font-variant-numeric: tabular-nums;
}

.cycle-current {
    background: var(--green-dim);
    border-color: var(--green);
}
.cycle-current .cycle-pill-name { color: var(--green); }
.cycle-current .cycle-pill-day { color: var(--green); }

.cycle-behind {
    background: var(--orange-dim);
    border-color: var(--orange);
}
.cycle-behind .cycle-pill-name { color: var(--orange); }
.cycle-behind .cycle-pill-day { color: var(--orange); }

.cycle-stale {
    background: var(--red-dim);
    border-color: var(--red);
}
.cycle-stale .cycle-pill-name { color: var(--red); }
.cycle-stale .cycle-pill-day { color: var(--red); }

.btn-sm {
    padding: 4px 12px;
    font-size: 10px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-sm:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-lg {
    padding: 10px 20px;
    font-size: 12px;
    width: 100%;
}

/* ── Action Cards ────────────────────────────────────────── */
.action-grid {
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}

.action-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 14px;
    transition: all var(--transition);
}

.action-card:hover {
    border-color: var(--border-bright);
}

.action-card h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.action-card p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 10px;
}

.action-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.action-row select {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text-primary);
    font-size: 11px;
    font-family: inherit;
}

.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-deep);
}

.btn-primary:hover {
    filter: brightness(1.15);
}

.btn-primary:active {
    transform: scale(0.97);
}

/* ── Admin Panel ──────────────────────────────────────── */
.admin-login-card {
    padding: 20px 16px;
    text-align: center;
    background: var(--bg-base);
}

.admin-login-prompt {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.admin-login-form {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.admin-login-form input {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 2px;
    color: var(--text-primary);
    padding: 6px 12px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    outline: none;
    width: 180px;
    transition: border-color var(--transition);
}

.admin-login-form input:focus {
    border-color: var(--accent);
}

.btn-accent {
    background: var(--accent);
    border: none;
    border-radius: 2px;
    color: var(--bg-deep);
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all var(--transition);
}

.btn-accent:hover {
    filter: brightness(1.15);
}

.admin-error {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--red);
}

.admin-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    padding: 12px 14px;
}

.admin-action-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 14px 12px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.admin-action-card:hover {
    border-color: var(--accent);
    background: var(--bg-elevated);
}

.admin-action-icon {
    font-size: 22px;
    margin-bottom: 6px;
}

.admin-action-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.admin-action-desc {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Live indicator dot inside admin action cards */
.card-live-indicator {
    display: none;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green, #34d399);
    box-shadow: 0 0 6px var(--green, #34d399);
    animation: card-pulse 2s ease-in-out infinite;
}

.card-live-indicator.active {
    display: block;
}

.card-live-indicator.active::after {
    content: "LIVE";
    position: absolute;
    top: -1px;
    right: 14px;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--green, #34d399);
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    white-space: nowrap;
}

@keyframes card-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--green, #34d399); }
    50% { opacity: 0.4; box-shadow: 0 0 2px var(--green, #34d399); }
}

.trigger-status {
    margin: 0 14px 12px;
    padding: 8px 12px;
    border-radius: 2px;
    font-size: 11px;
    font-weight: 500;
}

.trigger-status.pending {
    background: var(--orange-dim);
    color: var(--orange);
    border: 1px solid var(--orange);
}

.trigger-status.success {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid var(--green);
}

.trigger-status.error {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid var(--red);
}

.task-id-cell {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    font-size: 10px;
    color: var(--text-muted);
    cursor: help;
}

/* ── Scraper Log ─────────────────────────────────────────── */
.scraper-log {
    padding: 12px 14px;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    font-size: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.log-entry {
    padding: 2px 0;
    display: flex;
    gap: 10px;
    transition: background var(--transition);
    border-radius: 0;
    padding: 2px 4px;
    margin: 0 -4px;
}

.log-entry:hover {
    background: var(--bg-elevated);
}

.log-time { color: var(--text-muted); }
.log-msg { color: var(--text-secondary); }
.log-ok { color: var(--green); }
.log-fail { color: var(--red); }

/* ── Cycle Schedule Table ──────────────────────────────── */
.cycle-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.cycle-table th {
    text-align: left;
    padding: 6px 10px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.cycle-table td {
    padding: 4px 10px;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    vertical-align: middle;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
}

.cycle-table tbody tr {
    transition: all var(--transition);
}

.cycle-table > tbody > tr:not(.dataset-detail-row):hover > td {
    background: var(--bg-surface);
}

.cycle-table > tbody > tr:not(.dataset-detail-row):hover > td:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
}

.cycle-name {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.td-muted {
    color: var(--text-muted);
    font-size: 11px;
}

.td-sub {
    display: block;
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 1px;
}

.td-countdown {
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.btn-hunt {
    padding: 3px 10px;
    font-size: 9px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-hunt:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Dataset Inventory ─────────────────────────────────── */
.section-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-toggle:hover {
    background: var(--bg-hover);
}

.section-toggle-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-arrow {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.datasets-panel {
    max-height: 600px;
    overflow-y: auto;
}

/* Clickable dataset rows */
.dataset-row {
    cursor: pointer;
}
.dataset-row:hover {
    background: var(--bg-hover) !important;
}
.dataset-expanded {
    background: var(--bg-elevated) !important;
}

/* Expanded detail table */
.dataset-detail-row td {
    padding: 0 !important;
    border-bottom: 1px solid var(--border) !important;
}
.dataset-detail-wrap {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-deep);
    border-radius: 0;
    margin: 2px 6px 6px;
}
.detail-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 10px;
}
.detail-table th {
    text-align: left;
    padding: 4px 8px;
    color: var(--text-muted);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.detail-table td {
    padding: 3px 8px;
    color: var(--text-secondary);
    border-bottom: 1px solid #1a1a1a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.detail-table tbody tr {
    transition: background 0.1s ease;
}
.detail-table tbody tr:hover {
    background: var(--bg-hover);
}
.detail-table tbody tr:hover td {
    color: var(--text-primary);
}
.detail-table tbody tr:hover td:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
}

/* Task & hunt clickable rows */
.task-row {
    cursor: pointer;
}
.task-row:hover {
    background: var(--bg-hover) !important;
}

/* Task log detail panel */
.task-log-wrap {
    max-height: 350px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-deep);
    border-radius: 0;
    margin: 2px 6px 6px;
}
.task-log-lines {
    font-family: "Inter", sans-serif;
    font-size: 11px;
    line-height: 1.6;
}
.log-line {
    padding: 2px 0;
    color: var(--text-secondary);
}
.log-error {
    color: var(--red);
}
.log-success {
    color: var(--green);
}
.log-waiting {
    color: var(--orange);
}

/* Hunt timeline */
.hunt-timeline {
    padding: 4px 0;
}

/* ── Mobile / iPhone Responsive ──────────────────────────── */

@media (max-width: 640px) {

    /* Header: hide title, single-row scrollable nav */
    header {
        justify-content: center;
        padding: 0;
        height: 36px;
    }

    header h1 {
        display: none;
    }

    nav {
        width: 100%;
        justify-content: space-evenly;
        gap: 0;
        overflow-x: hidden;
    }

    nav a {
        font-size: 9px;
        padding: 10px 4px;
        white-space: nowrap;
        flex-shrink: 1;
        text-align: center;
        min-width: 0;
    }

    /* Show full nav labels — pipe selector is compact enough */
    .nav-full { display: inline !important; }
    .nav-short { display: none !important; }

    /* Hide the active underline on mobile */
    nav a.active::after {
        display: none;
    }

    nav a.active {
        border-bottom: 2px solid var(--accent);
    }

    /* Compact pipeline selector on mobile */
    .pipe-selector {
        margin-right: 2px;
        padding-right: 4px;
        border-right: 1px solid var(--border);
    }

    .pipe-selector select {
        font-size: 9px;
        padding: 2px 4px;
        min-width: 0;
    }

    /* ── Filter toggle button (mobile only) ── */
    .filter-toggle {
        display: flex !important;
    }

    /* Hide controls bar by default on mobile — shown via filter button */
    .controls {
        display: flex;
        position: fixed;
        z-index: 200;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        flex-direction: column;
        gap: 10px;
        padding: 12px;
        visibility: hidden;
        pointer-events: none;
    }

    .controls.filter-open {
        visibility: visible;
        pointer-events: auto;
    }

    .controls label {
        font-size: 10px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .controls select,
    .controls input[type="date"] {
        width: 100%;
        padding: 8px 10px;
        font-size: 14px !important;
    }

    /* Filter header (close button) — only visible on mobile */
    .filter-header {
        display: flex !important;
    }

    /* Left-to-right slide (Map page) */
    .filter-slide-left {
        top: 0;
        left: 0;
        bottom: 0;
        width: 240px;
        max-width: 75vw;
        border-radius: 0;
        transform: translateX(-100%);
        transition: transform 0.15s ease, visibility 0s linear 0.15s;
    }

    .filter-slide-left.filter-open {
        transform: translateX(0);
        transition: transform 0.15s ease, visibility 0s linear 0s;
    }

    /* Top-to-bottom slide (Dashboard page) */
    .filter-slide-down {
        top: 36px;
        left: 0;
        right: 0;
        border-radius: 0;
        transform: translateY(-100%);
        transition: transform 0.15s ease, visibility 0s linear 0.15s;
    }

    .filter-slide-down.filter-open {
        transform: translateY(0);
        transition: transform 0.15s ease, visibility 0s linear 0s;
    }

    /* Backdrop */
    .filter-backdrop {
        display: block !important;
        transition: opacity 0.15s ease;
    }

    #last-updated {
        font-size: 9px;
    }

    /* Control center layout */
    .control-layout {
        padding: 8px 6px;
    }

    .control-section h2 {
        padding: 10px 10px;
        font-size: 9px;
        min-height: 40px;
    }

    /* System banner */
    .system-banner.system-visible {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 8px 10px;
    }

    .system-text {
        font-size: 11px;
    }

    .system-detail {
        font-size: 10px;
    }

    /* Cycle Schedule table — fit on screen, no horizontal scroll */
    .control-section {
        overflow-x: hidden;
    }

    .cycle-table {
        font-size: 9px;
        min-width: 0;
        width: 100%;
        table-layout: auto;
    }

    .cycle-table th,
    .cycle-table td {
        padding: 4px 4px;
        white-space: nowrap;
    }

    /* Hide less-important columns on mobile by table context */

    /* Cycle Schedule (7 cols): hide "Gas Day" (2) and "Posts Around" (5) */
    #cycle-schedule-table th:nth-child(2),
    #cycle-schedule-table td:nth-child(2),
    #cycle-schedule-table th:nth-child(5),
    #cycle-schedule-table td:nth-child(5) {
        display: none;
    }

    /* Hunt Log (6 cols): hide "Attempt" (3) and "Message" (5) */
    #huntlog-panel .cycle-table th:nth-child(3),
    #huntlog-panel .cycle-table td:nth-child(3),
    #huntlog-panel .cycle-table th:nth-child(5),
    #huntlog-panel .cycle-table td:nth-child(5) {
        display: none;
    }

    /* Status table (recent tasks) */
    .status-table {
        font-size: 9px;
        min-width: 0;
        width: 100%;
    }

    .status-table th,
    .status-table td {
        padding: 4px 4px;
    }

    /* Backfill split on mobile — keep side by side */
    .backfill-half {
        padding: 8px 6px;
    }

    .backfill-half-title {
        font-size: 10px;
    }

    .sc-header h3 {
        font-size: 10px;
    }

    .sc-schedule {
        display: none;
    }

    .sc-stats {
        display: none;
    }

    .live-badge {
        font-size: 8px;
        padding: 2px 4px;
    }

    .scraper-card .btn,
    .scraper-card .btn-sm {
        font-size: 10px;
        padding: 6px 8px;
        min-height: 32px;
    }

    /* Freshness grid: 2 cols on phone */
    .freshness-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Dashboard: stack map + chart vertically */
    .main-layout {
        flex-direction: column;
        height: auto;
    }

    /* Zone segments: 2-column blocks on phone */
    .zone-segments {
        grid-template-columns: repeat(2, 1fr);
    }

    .segment-card {
        padding: 6px 8px;
    }

    .segment-card .seg-id {
        font-size: 10px;
    }

    .segment-card .seg-name {
        font-size: 8px;
    }

    .segment-card .seg-flow {
        margin-top: 4px;
        font-size: 9px;
    }

    .segment-card .seg-flow .util-badge {
        font-size: 8px;
        padding: 1px 4px;
    }

    /* Map panel */
    .map-panel {
        padding: 6px;
    }

    .inline-chart-container {
        height: 220px;
    }

    .inline-chart-panel {
        padding: 10px 8px;
    }

    .inline-chart-title {
        font-size: 12px;
    }

    .stat-chip {
        font-size: 9px;
        padding: 2px 6px;
    }

    /* Scraper dashboard: already 1-col via 1000px query */

    /* Buttons — bigger touch targets */
    .btn, .btn-sm {
        font-size: 11px;
        padding: 8px 14px;
        min-height: 40px;
        width: 100%;
    }

    .btn-hunt {
        padding: 4px 8px;
        min-height: 28px;
        font-size: 9px;
    }

    .td-sub {
        display: none;
    }

    /* DB footer — hide on mobile */
    .db-footer {
        display: none;
    }

    /* Dataset detail tables */
    .detail-table {
        font-size: 9px;
        min-width: 0;
        width: 100%;
    }

    .dataset-detail-wrap {
        overflow-x: hidden;
    }

    /* Hunt log timeline steps */
    .hunt-step {
        font-size: 10px;
    }

    /* Task log panel */
    .task-log-wrap {
        max-height: 250px;
    }

    .task-log-lines {
        font-size: 10px;
    }

    /* Badge sizing */
    .badge {
        font-size: 8px;
        padding: 1px 5px;
    }

    /* Make clickable rows easier to tap */
    .task-row td,
    .dataset-row td {
        padding: 10px 8px;
    }

    /* Prevent iOS from zooming on select/input focus */
    select, input {
        font-size: 16px !important;
    }
}

/* Extra small phones (iPhone SE, etc.) */
@media (max-width: 380px) {
    header h1 {
        display: none;
    }

    nav a {
        font-size: 9px;
        padding: 4px 4px;
    }

    .control-layout {
        padding: 6px 4px;
    }

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

    .scraper-card {
        padding: 10px;
    }
}
