:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --bg-card-hover: #222940;
    --border: #2a3040;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a8;
    --text-dim: #5a6270;
    --accent-green: #00ff88;
    --accent-cyan: #00e5ff;
    --accent-gold: #ffd700;
    --accent-red: #ff4444;
    --accent-amber: #ffaa00;
    --user-jason: #00ff88;
    --user-rebecca: #00e5ff;
    --user-jake: #ffd700;
    --signal-active: #00ff88;
    --signal-weak: #ffaa00;
    --signal-lost: #ff4444;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
    overflow: hidden;
}

#beacon-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header */
#top-bar {
    height: 48px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 24px;
    z-index: 10;
}

#top-bar .title {
    font-size: 14px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--accent-green);
    font-weight: 700;
    flex-shrink: 0;
}
#top-bar .title-short { display: none; }

.status-badges {
    display: flex;
    gap: 12px;
    flex-grow: 1;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    box-shadow: 0 0 4px transparent;
}

.badge.ok .dot { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.badge.warn .dot { background: var(--accent-amber); box-shadow: 0 0 6px var(--accent-amber); }
.badge.err .dot { background: var(--accent-red); box-shadow: 0 0 6px var(--accent-red); }
.badge.ok { color: var(--text-primary); }

.beacon-count {
    font-size: 11px;
    letter-spacing: 2px;
    color: var(--accent-green);
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
    margin-right: 6px;
    animation: pulse-live 2s ease-in-out infinite;
}

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

/* Connection banner (reconnecting / offline) */
#ws-status {
    background: var(--accent-amber);
    color: #000;
    text-align: center;
    padding: 4px 0;
    font-size: 11px;
    letter-spacing: 2px;
    flex-shrink: 0;
    height: 28px;
    line-height: 20px;
    z-index: 25;
}
#ws-status.hidden { display: none; }
#ws-status.offline {
    background: var(--accent-red);
    color: #fff;
    animation: banner-pulse 1.6s ease-in-out infinite;
}
#ws-status.reconnecting {
    background: var(--accent-amber);
    color: #000;
    animation: banner-pulse 1.6s ease-in-out infinite;
}
#ws-status.clickable {
    cursor: pointer;
    animation: none;
}
@keyframes banner-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* Header button (wakelock toggle, etc.) */
.header-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.header-btn:hover { color: var(--text-secondary); border-color: var(--border); }
.header-btn[aria-pressed="true"] { color: var(--accent-green); border-color: var(--accent-green); }
.header-btn[hidden] { display: none !important; }

/* Main */
#main-content {
    display: flex;
    flex-grow: 1;
    min-height: 0;
}

#map-container {
    flex-grow: 1;
    background: #000;
    position: relative;
}

#right-panel {
    width: 340px;
    flex-shrink: 0;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#user-cards {
    flex: 1 1 0;
    min-height: 100px;
    overflow-y: auto;
    padding: 12px;
}

#event-log-header,
.section-header {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--text-dim);
    text-transform: uppercase;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-add-btn {
    width: 22px;
    height: 22px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.section-add-btn:hover { color: var(--accent-green); border-color: var(--accent-green); }
.section-add-btn[aria-pressed="true"] { color: var(--accent-green); border-color: var(--accent-green); }

#zones-list {
    flex: 0 1 auto;
    max-height: 220px;
    overflow-y: auto;
    padding: 6px 8px;
}

.zone-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
    transition: background 0.15s;
}
.zone-row:hover { background: var(--bg-card); }
.zone-row .zr-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 4px currentColor;
}
.zone-row .zr-name {
    flex-grow: 1;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.zone-row .zr-count {
    flex-shrink: 0;
    color: var(--text-dim);
    font-size: 10px;
    letter-spacing: 0.5px;
}
.zone-row.empty { color: var(--text-dim); cursor: default; }
.zone-row.empty:hover { background: transparent; }

#event-log {
    flex: 1 1 0;
    min-height: 100px;
    overflow-y: auto;
    padding: 8px 12px;
}

/* Place-mode banner overlaid on the map */
#place-banner {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--accent-green);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    z-index: 12;
    box-shadow: 0 2px 12px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: place-pulse 1.6s ease-in-out infinite;
}
#place-banner.hidden { display: none; }
.pb-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font: inherit;
    font-size: 10px;
    letter-spacing: 1px;
}
.pb-cancel:hover { color: var(--accent-red); border-color: var(--accent-red); }
@keyframes place-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(0, 255, 136, 0); }
}

/* Zone editor modal */
#zone-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
}
#zone-modal-backdrop.hidden { display: none; }

#zone-modal {
    position: fixed;
    z-index: 50;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    width: 320px;
    max-width: calc(100vw - 24px);
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    font-size: 12px;
}
#zone-modal.hidden { display: none; }

.zm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent-green);
}
.zm-close {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.zm-close:hover { color: var(--accent-red); }

.zm-body {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.zm-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.zm-label {
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--text-secondary);
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.zm-radius-val {
    color: var(--accent-green);
    text-transform: none;
    letter-spacing: 0.5px;
}
#zm-name {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 6px 8px;
    font: inherit;
    font-size: 12px;
}
#zm-name:focus {
    outline: none;
    border-color: var(--accent-green);
}
#zm-radius {
    width: 100%;
    accent-color: var(--accent-green);
}
.zm-swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.zm-swatches button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s, border-color 0.15s;
}
.zm-swatches button.selected {
    border-color: #fff;
    transform: scale(1.15);
}

.zm-toggle-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.zm-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
}
.zm-toggle input[type="checkbox"] {
    appearance: none;
    width: 32px;
    height: 18px;
    background: var(--border);
    border-radius: 9px;
    position: relative;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
.zm-toggle input[type="checkbox"]::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: transform 0.15s, background 0.15s;
}
.zm-toggle input[type="checkbox"]:checked {
    background: var(--accent-green);
}
.zm-toggle input[type="checkbox"]:checked::before {
    transform: translateX(14px);
    background: #fff;
}

.zm-error {
    color: var(--accent-red);
    font-size: 11px;
    background: rgba(255, 68, 68, 0.10);
    border: 1px solid rgba(255, 68, 68, 0.4);
    border-radius: 4px;
    padding: 6px 8px;
}
.zm-error.hidden { display: none; }

.zm-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}
.zm-spacer { flex-grow: 1; }
.zm-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.zm-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.zm-btn-primary {
    background: var(--accent-green);
    color: #000;
    border-color: var(--accent-green);
}
.zm-btn-primary:hover { color: #000; background: #33ffaa; border-color: #33ffaa; }
.zm-btn-danger {
    color: var(--accent-red);
    border-color: rgba(255, 68, 68, 0.5);
}
.zm-btn-danger:hover {
    background: rgba(255, 68, 68, 0.15);
    color: var(--accent-red);
    border-color: var(--accent-red);
}
.zm-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.zm-btn.hidden { display: none; }

/* Map zone label readability tuning is in zones.js paint props */

/* User cards */
.user-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-green);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.user-card.signal-lost {
    border-color: var(--accent-red);
    border-left-color: var(--accent-red);
    animation: pulse-lost-card 2.5s ease-in-out infinite;
}

.user-card.signal-weak {
    animation: pulse-weak-card 3s ease-in-out infinite;
}

@keyframes pulse-lost-card {
    0%, 100% { background: var(--bg-card); }
    50% { background: rgba(255, 68, 68, 0.12); }
}

@keyframes pulse-weak-card {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

.uc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.uc-name {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.uc-state {
    font-size: 11px;
    letter-spacing: 1px;
}

.uc-status {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.uc-detail {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.uc-detail .acc-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.acc-dot.good { background: var(--accent-green); }
.acc-dot.med { background: var(--accent-amber); }
.acc-dot.poor { background: #ff8800; }

.battery-bar-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 10px;
    color: var(--text-secondary);
}

.battery-bar {
    flex-grow: 1;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
}

.battery-fill {
    height: 100%;
    transition: width 0.3s ease;
}
.battery-fill.high { background: var(--accent-green); }
.battery-fill.med { background: var(--accent-amber); }
.battery-fill.low { background: var(--accent-red); }

.charging-icon {
    margin-left: 4px;
    color: var(--accent-amber);
    font-size: 0.9em;
    line-height: 1;
}
.charging-icon.full {
    color: var(--accent-green);
}

/* Event log */
.event-entry {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 0;
    line-height: 1.4;
    display: flex;
    gap: 6px;
    align-items: baseline;
    animation: event-flash 1.2s ease-out;
}

@keyframes event-flash {
    0% { background: rgba(0, 255, 136, 0.18); }
    100% { background: transparent; }
}

.event-time {
    color: var(--text-dim);
    flex-shrink: 0;
    font-size: 10px;
}

.event-icon {
    flex-shrink: 0;
}

.event-message {
    flex-grow: 1;
}

/* Speed alert severity tiers — color-coded event log entries. */
.event-entry.tier-over .event-message    { color: #ffd700; }
.event-entry.tier-warning .event-message { color: #ff8800; font-weight: 600; }
.event-entry.tier-critical .event-message { color: #ff3030; font-weight: 700; }
.event-entry.tier-warning  { background: rgba(255, 136, 0, 0.06); }
.event-entry.tier-critical { background: rgba(255, 48, 48, 0.10); }

/* Mapbox markers */
.beacon-marker {
    position: relative;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.marker-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    transition: transform 0.2s ease;
}

.beacon-marker[data-at-home="true"][data-moving="false"][data-signal="active"] .marker-dot {
    animation: pulse-home 3s ease-in-out infinite;
}

@keyframes pulse-home {
    0%, 100% { transform: scale(1.0); }
    50% { transform: scale(1.15); }
}

.beacon-marker[data-signal="lost"] .marker-dot {
    background: var(--accent-red) !important;
    box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.6);
    animation: pulse-lost 2s ease-out infinite;
}

@keyframes pulse-lost {
    0% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 16px rgba(255, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

.marker-heading {
    position: absolute;
    top: -10px;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 7px solid var(--accent-green);
    transform-origin: 50% 18px;
    transform: translate(-50%, 0) rotate(0deg);
    pointer-events: none;
}

.beacon-marker[data-moving="false"] .marker-heading { display: none; }

.marker-speed {
    position: absolute;
    top: -24px;
    left: 22px;
    font-size: 10px;
    color: #fff;
    text-shadow: 0 0 4px #000, 0 0 2px #000;
    white-space: nowrap;
    pointer-events: none;
}

.beacon-marker[data-moving="false"] .marker-speed { display: none; }

.marker-label-lost {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--accent-red);
    text-shadow: 0 0 4px #000;
    white-space: nowrap;
    letter-spacing: 1px;
    pointer-events: none;
}
.beacon-marker:not([data-signal="lost"]) .marker-label-lost { display: none; }

/* Mapbox attribution adjustments for dark theme */
.mapboxgl-ctrl-attrib {
    background: rgba(0, 0, 0, 0.5) !important;
    color: var(--text-dim) !important;
}
.mapboxgl-ctrl-attrib a {
    color: var(--text-secondary) !important;
}

/* Marker popups (override Mapbox defaults) */
.beacon-popup-wrap .mapboxgl-popup-content {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    padding: 10px 12px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6) !important;
    font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace !important;
    min-width: 180px;
}
.beacon-popup-wrap .mapboxgl-popup-tip {
    border-top-color: var(--bg-card) !important;
    border-bottom-color: var(--bg-card) !important;
}

.beacon-popup .bp-name {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.beacon-popup .bp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    line-height: 1.6;
    gap: 12px;
}
.beacon-popup .bp-label {
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.beacon-popup .bp-val {
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.beacon-popup .bp-acc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.beacon-popup .bp-acc-dot.good { background: var(--accent-green); }
.beacon-popup .bp-acc-dot.med { background: var(--accent-amber); }
.beacon-popup .bp-acc-dot.poor { background: #ff8800; }
.beacon-popup .bp-coords {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 10px;
    color: var(--text-dim);
    text-align: center;
    letter-spacing: 0.5px;
}

/* Distance section in popup */
.beacon-popup .bp-distance {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary);
}
.beacon-popup .bp-distance .bp-driving { color: var(--text-primary); }
.beacon-popup .bp-distance .bp-crow { color: var(--text-dim); font-size: 10px; }
.beacon-popup .bp-distance .bp-loading { color: var(--text-dim); font-style: italic; }
.beacon-popup .bp-distance .bp-self { color: var(--accent-green); }

.beacon-popup .bp-actions {
    display: flex;
    flex-wrap: nowrap;
    justify-content: stretch;
    align-items: stretch;
    gap: 6px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}
.beacon-popup .bp-nav-btn {
    flex: 1 1 0;
    min-width: 0;
    box-sizing: border-box;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 4px 8px;
    margin: 0;
    font: inherit;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 26px;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.beacon-popup .bp-nav-btn .bp-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
}
.beacon-popup .bp-nav-btn .bp-btn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.beacon-popup .bp-nav-btn:hover {
    color: var(--accent-green);
    border-color: var(--accent-green);
    background: rgba(255, 255, 255, 0.06);
}
.beacon-popup .bp-nav-btn:focus { outline: none; }
.beacon-popup .bp-nav-btn:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 1px;
}
.beacon-popup .bp-locate-btn:hover {
    color: var(--accent-amber, #ffd700);
    border-color: var(--accent-amber, #ffd700);
}

/* Locate / follow buttons on user cards (desktop + mobile drawer).
 * 28x28 hit target, subtle hover, active follow tints in the user's color. */
.uc-row-right {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.uc-row-right .uc-state { margin-right: 4px; }
.uc-locate-btn,
.mc-locate-btn,
.uc-follow-btn,
.mc-follow-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    line-height: 1;
    font-size: 13px;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.uc-locate-btn:focus,
.mc-locate-btn:focus,
.uc-follow-btn:focus,
.mc-follow-btn:focus { outline: none; }
.uc-locate-btn:focus-visible,
.mc-locate-btn:focus-visible,
.uc-follow-btn:focus-visible,
.mc-follow-btn:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 1px;
}
.uc-locate-btn:hover,
.mc-locate-btn:hover {
    color: var(--accent-amber, #ffd700);
    border-color: var(--accent-amber, #ffd700);
    background: rgba(255, 255, 255, 0.10);
}

/* Follow button — toggles BeaconFollow. Active = filled in user color (~20% opacity). */
.uc-follow-btn:hover,
.mc-follow-btn:hover {
    color: var(--follow-color, var(--accent-cyan));
    border-color: var(--follow-color, var(--accent-cyan));
    background: rgba(255, 255, 255, 0.10);
}
.uc-follow-btn[aria-pressed="true"],
.mc-follow-btn[aria-pressed="true"],
.uc-follow-btn.active,
.mc-follow-btn.active {
    color: var(--follow-color, var(--accent-cyan));
    border-color: var(--follow-color, var(--accent-cyan));
    background: color-mix(in srgb, var(--follow-color, #00e5ff) 20%, transparent);
}

.beacon-popup .bp-follow-btn.active,
.beacon-popup .bp-follow-btn[aria-pressed="true"] {
    color: var(--follow-color, var(--accent-cyan));
    border-color: var(--follow-color, var(--accent-cyan));
    background: color-mix(in srgb, var(--follow-color, #00e5ff) 20%, transparent);
}
.beacon-popup .bp-follow-btn:hover {
    color: var(--follow-color, var(--accent-cyan));
    border-color: var(--follow-color, var(--accent-cyan));
}

/* "FOLLOWING" label on the user card — replaces the zone line so the card
 * height stays constant when the follow toggle flips. */
.uc-following-label,
.user-card .uc-following-label { display: none; }
.user-card.following .uc-zone-line { display: none; }
.user-card.following .uc-following-label {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    letter-spacing: 1.5px;
    color: var(--follow-color, var(--accent-cyan));
    font-weight: 700;
}
.user-card.following,
.mobile-card.following {
    animation: follow-card-pulse 1.6s ease-in-out infinite;
}
@keyframes follow-card-pulse {
    0%, 100% { box-shadow: 0 0 0 1px var(--follow-color, var(--accent-cyan)); }
    50%      { box-shadow: 0 0 0 4px var(--follow-color, var(--accent-cyan)); }
}

/* Follow banner (mobile only — desktop shows the card pulse only) */
#follow-banner {
    flex-shrink: 0;
    height: 26px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 10px;
    font-size: 11px;
    letter-spacing: 1px;
    z-index: 24;
}
#follow-banner.hidden { display: none !important; }
#follow-banner .fb-name {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}
#follow-banner #fb-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    width: 22px;
    height: 22px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    font-size: 14px;
}
#follow-banner #fb-cancel:hover { color: var(--accent-red); border-color: var(--accent-red); }

/* Card extras: home distance, time-in-state, battery estimate */
.uc-zone-line {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 2px;
    letter-spacing: 0.5px;
}
.uc-time-in-state {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 2px;
}
.battery-estimate {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 2px;
    letter-spacing: 0.3px;
}
.battery-estimate.warn { color: var(--accent-amber); }
.battery-estimate.danger { color: var(--accent-red); }
.battery-estimate.good { color: var(--accent-green); }

/* Whole desktop user card is clickable — it flies the map to the user. */
.user-card {
    cursor: pointer;
}
.user-card:hover {
    background: var(--bg-card-hover);
}
.user-card.signal-lost:hover {
    background: rgba(255, 68, 68, 0.18);
}

/* Map controls (top-right) */
#map-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 5;
}
.map-ctl {
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    position: relative;
    transition: color 0.15s, border-color 0.15s, transform 0.2s;
}
.map-ctl:hover { color: var(--accent-green); border-color: var(--accent-green); }
.map-ctl[aria-pressed="true"] { color: var(--accent-green); border-color: var(--accent-green); }
.map-ctl .ctl-label {
    position: absolute;
    bottom: -2px;
    right: 2px;
    font-size: 8px;
    color: var(--text-dim);
    letter-spacing: 1px;
}
.map-ctl[aria-pressed="true"] .ctl-label { color: var(--accent-green); }
.mobile-only { display: none; }

/* Layer switcher flyout (anchored to the right of #map-controls) */
#layer-flyout {
    position: absolute;
    top: 12px;
    right: 56px;
    z-index: 6;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
    min-width: 188px;
    overflow: hidden;
    padding: 4px 0;
}
#layer-flyout.hidden { display: none; }
.layer-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: 0;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: left;
    letter-spacing: 0.5px;
}
.layer-opt:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
.layer-opt.selected {
    color: var(--accent-green);
    background: rgba(0, 255, 136, 0.06);
}
.layer-opt .layer-thumb {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    background-size: cover;
    background-position: center;
}
.layer-opt .layer-name { flex-grow: 1; }
.layer-opt .layer-check {
    width: 14px;
    text-align: right;
    color: var(--accent-green);
    font-weight: 700;
}
/* Distinct thumb tint per option (cheap visual cue without external images) */
.layer-thumb-google-satellite { background: linear-gradient(135deg, #2d3a2a 0%, #5a6b40 100%); }
.layer-thumb-google-hybrid { background: linear-gradient(135deg, #2d3a2a 0%, #5a6b40 60%, #ffaa00 60%, #ffaa00 65%, #5a6b40 65%); }
.layer-thumb-esri-imagery { background: linear-gradient(135deg, #1a2e3f 0%, #4a6b85 100%); }
.layer-thumb-mapbox-satellite-streets { background: linear-gradient(135deg, #2a3a2a 0%, #4a5a4a 100%); }
.layer-thumb-mapbox-dark { background: linear-gradient(135deg, #1a1f2e 0%, #2a3040 100%); }
.layer-thumb-mapbox-outdoors { background: linear-gradient(135deg, #5a6b40 0%, #8aa860 100%); }

/* Custom tile attribution (Google / Esri raster basemaps) */
#tile-attribution {
    position: absolute;
    bottom: 4px;
    right: 80px;
    z-index: 4;
    background: rgba(0, 0, 0, 0.55);
    color: var(--text-secondary);
    font-size: 9px;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 3px;
    pointer-events: none;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}
#tile-attribution.hidden { display: none; }

/* Off-screen direction arrows */
#offscreen-arrows {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}
.offscreen-arrow {
    position: absolute;
    width: 28px;
    height: 28px;
    margin-left: -14px;
    margin-top: -14px;
    pointer-events: auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    transition: transform 0.15s ease-out;
}
.offscreen-arrow .oa-tri {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 12px solid currentColor;
    filter: drop-shadow(0 0 4px rgba(0,0,0,0.8));
}
.offscreen-arrow .oa-initial {
    font-size: 9px;
    font-weight: 700;
    margin-top: 1px;
    color: #fff;
    text-shadow: 0 0 4px #000, 0 0 2px #000;
    letter-spacing: 0.5px;
}

/* Mobile drawer (hidden on desktop) */
#mobile-drawer { display: none; }

/* Toast */
#toast {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 24px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 12px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: opacity 0.2s ease;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ============================================================ */
/* MOBILE BREAKPOINT — 768px                                    */
/* ============================================================ */
@media (max-width: 768px) {
    #top-bar {
        height: 40px;
        padding: 0 10px;
        gap: 10px;
    }
    #top-bar .title {
        font-size: 12px;
        letter-spacing: 2px;
    }
    #top-bar .title-full { display: none; }
    #top-bar .title-short { display: inline; }
    .badge { gap: 0; }
    .badge .badge-label { display: none; }
    .badge .dot { width: 7px; height: 7px; }
    .status-badges { gap: 8px; }
    .beacon-count { font-size: 10px; letter-spacing: 1px; }
    .beacon-count .bc-text { font-size: 10px; }

    #ws-status { height: 24px; line-height: 18px; padding: 3px 0; font-size: 10px; }

    /* Mobile-only follow banner */
    #follow-banner:not(.hidden) { display: flex; }

    /* Hide right panel; mobile drawer takes over */
    #right-panel { display: none; }
    #map-container { width: 100%; }

    /* Larger marker hit target on mobile */
    .beacon-marker {
        width: 44px;
        height: 44px;
    }
    .beacon-marker::before {
        /* invisible padding for touch target */
        content: "";
        position: absolute;
        inset: 0;
    }
    .marker-dot {
        width: 24px;
        height: 24px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    .marker-heading { top: 0; transform-origin: 50% 22px; }
    .marker-speed { top: -10px; left: 50%; transform: translateX(-50%); }
    .marker-label-lost { top: 36px; }

    .map-ctl { width: 40px; height: 40px; }
    .mobile-only { display: inline-flex; }

    /* Drawer */
    #mobile-drawer {
        display: flex;
        flex-direction: column;
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 80vh;
        max-height: 80vh;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 10;
        transform: translateY(calc(100% - 64px));
        transition: transform 300ms ease-out;
        will-change: transform;
        touch-action: pan-y;
    }
    #mobile-drawer[data-state="half"]   { transform: translateY(55%); }
    #mobile-drawer[data-state="full"]   { transform: translateY(0%); }
    #mobile-drawer.dragging { transition: none; }

    /* Drag handle */
    #drawer-handle {
        flex-shrink: 0;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: grab;
        touch-action: none;
    }
    #drawer-handle .handle-bar {
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--text-dim);
    }

    /* Collapsed strip */
    #drawer-strip {
        flex-shrink: 0;
        height: 44px;
        display: flex;
        align-items: center;
        padding: 0 12px;
        background: var(--bg-secondary);
        transition: background 0.3s ease;
    }
    #mobile-drawer.tint-home #drawer-strip { background: rgba(0, 255, 136, 0.08); }
    #mobile-drawer.tint-away #drawer-strip { background: rgba(255, 170, 0, 0.08); }
    #mobile-drawer.tint-lost #drawer-strip { background: rgba(255, 68, 68, 0.10); }

    #strip-badges {
        display: flex;
        gap: 14px;
        align-items: center;
        flex-grow: 1;
        overflow-x: auto;
        white-space: nowrap;
    }
    .strip-user {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        font-size: 11px;
        color: var(--text-primary);
        letter-spacing: 1px;
    }
    .strip-user .strip-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        box-shadow: 0 0 6px currentColor;
    }
    .strip-user .strip-init { font-weight: 700; }
    .strip-user .strip-icon { font-size: 11px; }

    /* Drawer body — cards row + distance + events */
    #drawer-body {
        flex-grow: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    #drawer-cards {
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
        overflow-y: auto;
        max-height: 50vh;
        scrollbar-width: thin;
    }
    .mobile-card {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 60px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-left: 3px solid var(--accent-green);
        border-radius: 8px;
        padding: 8px 10px;
        font-size: 11px;
        cursor: pointer;
    }
    .mobile-card.signal-lost { border-color: var(--accent-red); border-left-color: var(--accent-red); }
    .mobile-card.selected {
        background: var(--bg-card-hover);
        border-color: var(--text-secondary);
    }

    .mobile-card .mc-left {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        min-width: 70px;
        max-width: 110px;
    }
    .mobile-card .mc-name {
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 1px;
        text-transform: uppercase;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 110px;
    }
    .mobile-card .mc-icon {
        font-size: 13px;
        margin-top: 2px;
        line-height: 1;
    }

    .mobile-card .mc-center {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }
    .mobile-card .mc-distance {
        font-size: 11px;
        color: var(--text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mobile-card .mc-time-in-state {
        font-size: 10px;
        color: var(--text-dim);
    }
    .mobile-card .battery-bar-wrap {
        margin-top: 2px;
        font-size: 10px;
        gap: 6px;
    }
    .mobile-card .battery-bar { height: 3px; }

    .mobile-card .mc-right {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 4px;
        min-width: 56px;
        font-size: 10px;
        color: var(--text-dim);
    }
    .mobile-card .mc-right .acc-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
    }
    .mobile-card .mc-last-seen { white-space: nowrap; }

    .drawer-distance {
        flex-shrink: 0;
        padding: 6px 12px 8px;
        font-size: 11px;
        color: var(--text-secondary);
        text-align: center;
        border-top: 1px solid var(--border);
        line-height: 1.4;
    }
    .drawer-distance .dd-driving { color: var(--text-primary); display: block; }
    .drawer-distance .dd-crow { color: var(--text-dim); font-size: 10px; display: block; }
    .drawer-distance .dd-self { color: var(--accent-green); }
    .drawer-distance .dd-loading { color: var(--text-dim); font-style: italic; }

    #drawer-events {
        flex-grow: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 6px 12px 12px;
        border-top: 1px solid var(--border);
    }
    /* Hide distance + events while collapsed */
    #mobile-drawer[data-state="collapsed"] #drawer-body { display: none; }
    /* Hide events while half */
    #mobile-drawer[data-state="half"] #drawer-events { display: none; }
}

    /* Layer flyout — anchor to the bottom of the controls stack so it
       doesn't fall off the right edge of the screen. */
    #layer-flyout {
        top: auto;
        bottom: 12px;
        right: 60px;
        left: auto;
        min-width: 180px;
    }
    #tile-attribution {
        bottom: 4px;
        right: 4px;
        font-size: 8px;
    }

    /* Zones inside the mobile drawer */
    #drawer-zones-list {
        flex-shrink: 0;
        max-height: 25vh;
        overflow-y: auto;
        padding: 4px 8px;
    }
    #mobile-drawer[data-state="collapsed"] #drawer-zones-header,
    #mobile-drawer[data-state="collapsed"] #drawer-zones-list {
        display: none;
    }

    /* Editor modal: slide-up bottom sheet on mobile */
    #zone-modal {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        border-radius: 14px 14px 0 0;
        border-left: 0;
        border-right: 0;
        border-bottom: 0;
    }

    #place-banner {
        font-size: 10px;
        padding: 6px 10px;
        gap: 8px;
    }
}

/* ============================================================ */
/* Login page mobile polish                                     */
/* ============================================================ */
@media (max-width: 480px) {
    .login-card {
        width: 92vw !important;
        max-width: 360px;
        padding: 24px 22px !important;
    }
}
