:root {
    --bg: #08101f;
    --bg-top: #0f1930;
    --bg-card: #111c33;
    --bg-card-soft: #15213b;
    --bg-input: #0d172c;
    --border: #23365f;
    --border-hover: #3a5390;

    --blue-strong: #5bb9ff;
    --blue-soft: rgba(91, 185, 255, 0.14);
    --blue-soft-2: rgba(91, 185, 255, 0.22);
    --green: #58d17f;
    --orange: #ffb457;
    --red: #ff7b7b;

    --text: #e8eefb;
    --text-secondary: #aebede;
    --text-muted: #6e86b5;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow: 0 16px 48px rgba(2, 8, 20, 0.42);

    --layout-offset-desktop: 206px;
    --layout-offset-tablet: 262px;
    --layout-offset-mobile: 276px;
}

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

html,
body {
    height: 100%;
}

body {
    font-family: 'Roboto', sans-serif;
    background: radial-gradient(circle at 10% -20%, #1a2f56 0%, var(--bg) 44%, #060b16 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 0 20px;
    min-height: 56px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(11, 20, 38, 0.95) 0%, rgba(11, 20, 38, 0.88) 100%);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 60;
}

.nav-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--blue-strong);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.86rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.brand-sub {
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-tabs {
    display: inline-flex;
    align-items: center;
    padding: 4px;
    gap: 2px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(14, 25, 47, 0.86);
}

.nav-tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    padding: 7px 16px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: all 0.2s ease;
}

.nav-tab:hover {
    color: var(--text-secondary);
}

.nav-tab.active {
    border-color: rgba(91, 185, 255, 0.34);
    background: var(--blue-soft);
    color: var(--blue-strong);
    cursor: default;
}

.nav-meta {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.nav-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nav-help-btn {
    padding: 6px 10px;
    font-size: 0.73rem;
    flex: 0 0 auto;
}

.view {
    display: none;
    padding: 14px 18px 18px;
}

.view.active {
    display: block;
    animation: fade-in 0.22s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(17, 28, 50, 0.92) 0%, rgba(12, 21, 38, 0.9) 100%);
}

.toolbar-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.toolbar-group-wrap {
    flex-wrap: wrap;
}

.hist-controls-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 12px;
    width: 100%;
}

.control-stack {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}

.control-stack-emphasis {
    padding: 8px;
    border-radius: 10px;
    border: 1px solid rgba(91, 185, 255, 0.34);
    background: rgba(17, 34, 62, 0.55);
}

.control-stack-emphasis select {
    border-color: rgba(91, 185, 255, 0.42);
}

.control-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding-left: 2px;
    font-family: 'Roboto Mono', monospace;
}

.control-stack-emphasis .control-label {
    color: var(--blue-strong);
}

.control-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.control-stack select {
    min-width: 180px;
}

.toolbar-note {
    font-size: 0.73rem;
    color: var(--text-muted);
}

.toolbar-inline-note {
    font-size: 0.69rem;
    color: var(--text-muted);
    border: 1px dashed rgba(91, 185, 255, 0.28);
    background: rgba(19, 33, 60, 0.4);
    padding: 6px 8px;
    border-radius: 8px;
}

.view-help {
    margin: 4px 2px 10px;
    color: var(--text-muted);
    font-size: 0.74rem;
}

.mobile-pane-nav {
    display: none;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(88, 209, 127, 0.25);
    background: rgba(88, 209, 127, 0.08);
    color: #c9f6d8;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.74rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 10px rgba(88, 209, 127, 0.8);
}

.btn {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.76rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-outline {
    border-color: var(--border);
    background: rgba(11, 19, 35, 0.72);
}

.btn-outline:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: rgba(20, 31, 56, 0.82);
}

.btn-primary {
    color: var(--blue-strong);
    border-color: rgba(91, 185, 255, 0.36);
    background: var(--blue-soft);
}

.btn-primary:hover {
    border-color: rgba(91, 185, 255, 0.58);
    background: var(--blue-soft-2);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.sample-custom {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(10, 18, 34, 0.72);
    padding: 5px 8px;
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.sample-custom[hidden] {
    display: none !important;
}

.sample-custom input {
    width: 62px;
    padding: 6px 7px;
    text-align: center;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.75rem;
}

.card {
    background: linear-gradient(180deg, rgba(16, 27, 49, 0.95) 0%, rgba(11, 20, 36, 0.94) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding: 11px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.card-header-between {
    justify-content: space-between;
}

.inline-status {
    font-size: 0.73rem;
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.64rem;
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge-live {
    background: rgba(88, 209, 127, 0.12);
    color: var(--green);
    border: 1px solid rgba(88, 209, 127, 0.35);
}

.badge-blue {
    background: var(--blue-soft);
    color: var(--blue-strong);
    border: 1px solid rgba(91, 185, 255, 0.3);
}

.badge-orange {
    background: rgba(255, 180, 87, 0.12);
    color: var(--orange);
    border: 1px solid rgba(255, 180, 87, 0.35);
}

.rt-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 12px;
    align-items: stretch;
    transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: min(76vh, calc(100dvh - var(--layout-offset-desktop)));
    max-height: calc(100dvh - var(--layout-offset-desktop));
}

.rt-map-card {
    min-height: 70vh;
}

.map-wrap {
    position: relative;
    width: 100%;
    height: calc(100% - 43px);
    min-height: 420px;
}

#map-rt,
#map-hist {
    width: 100%;
    height: 100%;
}

.map-fab {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 420;
    border: 1px solid rgba(91, 185, 255, 0.45);
    background: rgba(8, 17, 33, 0.92);
    color: var(--blue-strong);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.map-fab:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#rt-detail-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: opacity 0.28s ease, transform 0.28s ease, max-width 0.28s ease;
}

.rt-grid.panel-collapsed {
    grid-template-columns: minmax(0, 1fr) 52px;
}

.rt-grid.panel-collapsed .results-title,
.rt-grid.panel-collapsed .results-actions > *:not(.icon-btn),
.rt-grid.panel-collapsed .results-list {
    opacity: 0;
    pointer-events: none;
}

.rt-grid.panel-collapsed .results-header {
    justify-content: center;
    min-height: 100%;
    border-bottom-color: transparent;
}

.rt-grid.panel-collapsed .icon-btn svg {
    transform: rotate(180deg);
}

.live-panel {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.live-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.live-field {
    padding: 10px 11px;
    background: rgba(9, 18, 34, 0.8);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(65, 95, 151, 0.25);
}

.live-field .lbl {
    font-size: 0.64rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.live-field .val {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.82rem;
    color: var(--blue-strong);
    font-weight: 700;
}

.hist-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 12px;
    transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: min(74vh, calc(100dvh - var(--layout-offset-desktop)));
    min-height: 520px;
    max-height: calc(100dvh - var(--layout-offset-desktop));
}

.hist-map-card {
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hist-map-wrap {
    flex: 1;
    height: auto;
    min-height: 0;
}

.results-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(16, 27, 49, 0.95) 0%, rgba(11, 20, 36, 0.94) 100%);
    overflow: hidden;
    transition: opacity 0.28s ease;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.results-title {
    color: var(--text-secondary);
    font-size: 0.77rem;
    font-weight: 600;
}

.results-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.results-count {
    color: var(--blue-strong);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.74rem;
}

.icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: rgba(9, 18, 34, 0.75);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

.results-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
}

.sensor-events-panel {
    border-top: 1px solid var(--border);
    background: rgba(8, 15, 30, 0.6);
    padding: 8px;
    max-height: 38%;
    min-height: 132px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sensor-events-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sensor-events-summary {
    font-size: 0.69rem;
    color: var(--text-muted);
    line-height: 1.35;
}

.sensor-events-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sensor-event-item {
    border: 1px solid rgba(65, 95, 151, 0.25);
    border-radius: var(--radius-sm);
    padding: 7px 8px;
    background: rgba(9, 18, 34, 0.76);
}

.sensor-event-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sensor-event-time {
    font-size: 0.66rem;
    color: var(--text-muted);
    font-family: 'Roboto Mono', monospace;
}

.sensor-event-tags {
    display: inline-flex;
    gap: 5px;
    align-items: center;
}

.sensor-tag {
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 0.62rem;
    font-family: 'Roboto Mono', monospace;
    border: 1px solid rgba(148, 163, 184, 0.28);
    color: var(--text-muted);
    background: rgba(148, 163, 184, 0.1);
}

.sensor-tag-brake {
    color: var(--orange);
    border-color: rgba(255, 180, 87, 0.42);
    background: rgba(255, 180, 87, 0.12);
}

.sensor-tag-turn {
    color: var(--blue-strong);
    border-color: rgba(91, 185, 255, 0.4);
    background: rgba(91, 185, 255, 0.13);
}

.sensor-event-coords {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-family: 'Roboto Mono', monospace;
}

.hist-layout.panel-collapsed {
    grid-template-columns: minmax(0, 1fr) 52px;
}

.hist-layout.panel-collapsed .results-title,
.hist-layout.panel-collapsed .results-count,
.hist-layout.panel-collapsed .results-list,
.hist-layout.panel-collapsed .sensor-events-panel {
    opacity: 0;
    pointer-events: none;
}

.hist-layout.panel-collapsed .sensor-events-panel {
    max-height: 0;
    min-height: 0;
    padding: 0;
    border-top: none;
}

.hist-layout.panel-collapsed .results-header {
    justify-content: center;
    min-height: 100%;
    border-bottom-color: transparent;
}

.hist-layout.panel-collapsed .icon-btn svg {
    transform: rotate(180deg);
}

.result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.16s ease;
    margin-bottom: 2px;
}

.result-item:hover {
    background: rgba(27, 42, 73, 0.62);
}

.result-item.active {
    background: rgba(35, 57, 99, 0.72);
    border: 1px solid rgba(91, 185, 255, 0.38);
}

.result-index {
    width: 27px;
    height: 27px;
    border-radius: 7px;
    border: 1px solid rgba(91, 185, 255, 0.26);
    background: var(--blue-soft);
    color: var(--blue-strong);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.66rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.result-info {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.result-coords {
    font-family: 'Roboto Mono', monospace;
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 500;
}

.result-device {
    color: var(--text-muted);
    font-size: 0.66rem;
    margin-top: 2px;
}

.result-subline {
    color: rgba(174, 190, 222, 0.75);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.62rem;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.result-time {
    font-family: 'Roboto Mono', monospace;
    color: var(--text-secondary);
    font-size: 0.68rem;
}

.result-item-trip {
    align-items: flex-start;
    flex-wrap: wrap;
}

.trip-status {
    align-self: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.63rem;
    letter-spacing: 0.03em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.trip-status-closed {
    color: var(--green);
    border-color: rgba(88, 209, 127, 0.42);
    background: rgba(88, 209, 127, 0.12);
}

.trip-status-open {
    color: var(--orange);
    border-color: rgba(255, 180, 87, 0.42);
    background: rgba(255, 180, 87, 0.12);
}

.no-data {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.79rem;
    padding: 24px 12px;
}

.no-data-icon {
    margin-bottom: 8px;
    opacity: 0.6;
}

select,
input {
    background: rgba(10, 18, 34, 0.8);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.77rem;
    padding: 8px 11px;
    outline: none;
    transition: border-color 0.2s ease;
}

select:focus,
input:focus {
    border-color: var(--border-hover);
}

select:disabled,
input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(5, 9, 18, 0.82);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    width: min(420px, 92vw);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(17, 28, 52, 0.98) 0%, rgba(10, 18, 34, 0.98) 100%);
    box-shadow: var(--shadow);
    padding: 22px;
    animation: modal-in 0.2s ease-out;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal h3 {
    font-size: 0.95rem;
    margin-bottom: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.modal-field {
    margin-bottom: 12px;
}

.modal-field label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.69rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.modal-field input {
    width: 100%;
}

.modal-field input.input-error {
    border-color: var(--red);
}

.modal-field input::-webkit-calendar-picker-indicator {
    filter: invert(0.68) sepia(0.2) hue-rotate(186deg);
}

.quick-ranges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.quick-btn {
    border: 1px solid var(--border);
    background: rgba(9, 18, 34, 0.86);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-btn:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

.modal-error {
    display: none;
    color: var(--red);
    font-size: 0.72rem;
}

.modal-error.show {
    display: block;
}

.modal-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-help {
    width: min(760px, 94vw);
    max-height: min(82dvh, 760px);
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.help-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.help-head h3 {
    margin: 0;
}

.help-tabs {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.help-tab {
    border: 1px solid var(--border);
    background: rgba(9, 18, 34, 0.86);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 0.73rem;
    font-weight: 600;
    cursor: pointer;
}

.help-tab.active {
    border-color: rgba(91, 185, 255, 0.4);
    background: var(--blue-soft);
    color: var(--blue-strong);
}

.help-body {
    margin-top: 12px;
    border: 1px solid rgba(54, 79, 131, 0.34);
    border-radius: var(--radius);
    background: rgba(7, 14, 26, 0.74);
    padding: 14px;
    overflow-y: auto;
}

.help-section {
    display: none;
}

.help-section.active {
    display: block;
}

.help-section h4 {
    color: var(--blue-strong);
    font-size: 0.83rem;
    margin-bottom: 8px;
}

.help-section ul {
    margin-left: 18px;
    color: var(--text-secondary);
    font-size: 0.77rem;
    line-height: 1.55;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 18px;
    z-index: 1010;
    border: 1px solid var(--border-hover);
    border-radius: var(--radius);
    background: rgba(10, 18, 34, 0.96);
    color: var(--text);
    font-size: 0.79rem;
    padding: 12px 15px;
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.26s ease;
    box-shadow: var(--shadow);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.skeleton {
    background: linear-gradient(90deg, rgba(18, 32, 58, 0.56) 20%, rgba(39, 57, 96, 0.66) 50%, rgba(18, 32, 58, 0.56) 80%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.footer {
    text-align: center;
    padding: 14px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.68rem;
    font-family: 'Roboto Mono', monospace;
}

.footer span {
    color: var(--blue-strong);
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-thumb {
    background: #314a7f;
    border-radius: 999px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

.leaflet-container {
    background: #dce5f2;
}

.leaflet-control-zoom a {
    background: rgba(12, 22, 39, 0.92) !important;
    color: var(--blue-strong) !important;
    border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: rgba(17, 31, 54, 0.96) !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: rgba(13, 22, 39, 0.96) !important;
    color: var(--text) !important;
    border: 1px solid var(--border-hover) !important;
}

.leaflet-popup-content {
    font-family: 'Roboto', sans-serif;
    font-size: 0.79rem;
}

@media (max-width: 1180px) {
    .rt-grid {
        grid-template-columns: minmax(0, 1fr) 320px;
    }

    .hist-layout {
        grid-template-columns: minmax(0, 1fr) 320px;
        min-height: 460px;
        height: min(72vh, calc(100dvh - var(--layout-offset-tablet)));
        max-height: calc(100dvh - var(--layout-offset-tablet));
    }
    .rt-grid.panel-collapsed {
        grid-template-columns: minmax(0, 1fr) 52px;
    }
}

@media (max-width: 960px) {
    #btn-toggle-rt-details,
    #btn-toggle-hist-panel {
        display: none;
    }
    .top-nav {
        padding: 0 12px;
    }

    .nav-meta {
        display: none;
    }

    .view {
        padding: 10px 10px 12px;
    }

    .view-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .hist-controls-grid {
        gap: 10px;
    }

    .control-stack {
        width: 100%;
        min-width: 0;
    }

    .control-stack select {
        width: 100%;
        min-width: 0;
    }

    .control-inline {
        width: 100%;
    }

    .control-inline .btn {
        flex: 0 0 auto;
    }

    .rt-grid,
    .rt-grid.panel-collapsed,
    .hist-layout,
    .hist-layout.panel-collapsed {
        grid-template-columns: 1fr;
    }

    .rt-grid,
    .rt-grid.panel-collapsed,
    .hist-layout,
    .hist-layout.panel-collapsed {
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .rt-map-card,
    .hist-map-card {
        min-height: 56vh;
    }

    .map-wrap {
        min-height: 56vh;
    }

    .results-panel {
        min-height: 46vh;
        max-height: 46vh;
    }

    .sensor-events-panel {
        max-height: 45%;
        min-height: 140px;
    }

    .hist-layout.panel-collapsed .results-panel {
        min-height: 58px;
        max-height: 58px;
    }

    .hist-layout.panel-collapsed .results-header {
        min-height: 58px;
    }

    #rt-grid.panel-collapsed #rt-detail-cards {
        display: none;
    }

    .mobile-pane-nav {
        display: inline-flex;
        width: 100%;
        gap: 6px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 4px;
        margin-bottom: 10px;
        background: rgba(11, 19, 35, 0.78);
    }

    .mobile-pane-btn {
        flex: 1;
        border: 1px solid transparent;
        border-radius: 8px;
        padding: 8px 10px;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-secondary);
        background: transparent;
        cursor: pointer;
    }

    .mobile-pane-btn.active {
        color: var(--blue-strong);
        background: var(--blue-soft);
        border-color: rgba(91, 185, 255, 0.34);
    }

    #view-realtime.mobile-pane-map #rt-detail-cards {
        display: none;
    }

    .results-actions {
        display: none;
    }

    #view-realtime.mobile-pane-info .rt-map-card {
        display: none;
    }

    #view-historical.mobile-pane-map .results-panel {
        display: none;
    }

    #view-historical.mobile-pane-info .hist-map-card {
        display: none;
    }

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

@media (max-width: 640px) {
    .nav-brand {
        font-size: 0.8rem;
    }

    .nav-tabs {
        width: 100%;
        justify-content: center;
    }

    .nav-actions {
        width: 100%;
        justify-content: space-between;
    }

    .top-nav {
        flex-wrap: wrap;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .nav-tab {
        padding: 7px 12px;
        font-size: 0.75rem;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }

    .top-nav .btn {
        flex: 0 0 auto;
    }

    .toolbar-note {
        width: 100%;
    }

    .sample-custom {
        width: 100%;
        justify-content: center;
    }

    .toolbar-inline-note {
        width: 100%;
        text-align: center;
    }

    .sample-custom input {
        width: 80px;
    }

    .results-panel {
        min-height: 50vh;
        max-height: 50vh;
    }

    .sensor-events-summary {
        font-size: 0.67rem;
    }

    .modal-help {
        max-height: 86dvh;
    }

    .help-body {
        max-height: 58dvh;
    }

    .toast {
        right: 10px;
        left: 10px;
        bottom: 10px;
    }

    /* ── Toolbar 2-column layout on mobile to reduce vertical height ── */
    .hist-controls-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .hist-controls-grid .control-stack {
        width: auto;
    }

    /* Rango temporal spans full width (has two controls inside) */
    .hist-controls-grid .control-stack:first-child {
        grid-column: 1 / -1;
    }

    /* Acciones (Buscar / Limpiar) spans full width */
    .hist-controls-grid .control-stack-actions {
        grid-column: 1 / -1;
    }

    /* Hint note spans full width */
    .hist-controls-grid .toolbar-inline-note {
        grid-column: 1 / -1;
    }
}

/* ══════════════════════════════════════════
   CARD HEADER ACTIONS (query button + status)
   ══════════════════════════════════════════ */

.card-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.72rem;
    gap: 5px;
}

/* Active state when query mode is ON */
.btn-active-query {
    background: rgba(255, 169, 77, 0.15);
    border-color: #ffa94d;
    color: #ffa94d;
}

.btn-active-query:hover {
    background: rgba(255, 169, 77, 0.25);
}

.hist-seq-controls {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 7px;
    border: 1px solid rgba(54, 79, 131, 0.34);
    border-radius: 999px;
    background: rgba(9, 18, 34, 0.72);
}

#hist-seq-slider {
    width: 150px;
    accent-color: #5bb9ff;
}

.hist-seq-label {
    min-width: 92px;
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-family: 'Roboto Mono', monospace;
    text-align: right;
}

.hist-seq-controls .btn.btn-sm {
    white-space: nowrap;
}

/* ══════════════════════════════════════════
   LOCATION QUERY — CROSSHAIR + BANNER + POPUP
   ══════════════════════════════════════════ */

/* Crosshair cursor when query mode is active */
#map-hist.query-mode,
#map-hist.query-mode .leaflet-container {
    cursor: crosshair !important;
}

/* Banner shown on top of the map on mobile (and desktop when mode is on) */
.location-query-banner {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(10, 14, 26, 0.88);
    border: 1px solid rgba(255, 169, 77, 0.45);
    color: #ffa94d;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 6px 10px 6px 10px;
    border-radius: 20px;
    white-space: nowrap;
    backdrop-filter: blur(6px);
    pointer-events: auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.lq-banner-close {
    background: transparent;
    border: none;
    color: #ffa94d;
    cursor: pointer;
    padding: 0 2px;
    display: flex;
    align-items: center;
    opacity: 0.8;
    flex-shrink: 0;
}

.lq-banner-close:hover {
    opacity: 1;
}

/* Leaflet popup for query result */
.lq-popup-wrap .leaflet-popup-content-wrapper {
    background: rgba(10, 14, 26, 0.95);
    border: 1px solid rgba(255, 169, 77, 0.4);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    color: var(--text-primary);
    padding: 0;
}

.lq-popup-wrap .leaflet-popup-tip {
    background: rgba(10, 14, 26, 0.95);
}

.lq-popup-wrap .leaflet-popup-content {
    margin: 0;
}

.lq-popup {
    padding: 10px 14px;
    text-align: center;
    min-width: 110px;
}

.lq-popup-time {
    font-size: 1.4rem;
    font-weight: 700;
    color: #ffa94d;
    letter-spacing: 0.02em;
    line-height: 1.2;
}

.lq-popup-date {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.lq-popup-dist {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 4px;
    border-top: 1px solid var(--border);
    padding-top: 5px;
}

/* ══════════════════════════════════════════
   LOCATION QUERY — RESULT MARKER (divIcon)
   ══════════════════════════════════════════ */

.lq-result-icon {
    background: transparent;
    border: none;
}

/* ══════════════════════════════════════════
   MOBILE FILTER BAR — compact always-visible strip
   ══════════════════════════════════════════ */

/* Hidden on desktop — shown only on mobile via media query below */
.mobile-filter-bar {
    display: none;
}

/* Full controls always visible on desktop */
.hist-controls-collapse {
    display: contents;
}

@media (max-width: 960px) {
    #btn-toggle-rt-details,
    #btn-toggle-hist-panel {
        display: none;
    }

    /* Show compact strip on mobile */
    .mobile-filter-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
        padding: 2px 0;
    }

    .mobile-filter-summary {
        flex: 1;
        font-size: 0.74rem;
        color: var(--text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }

    .mobile-filter-bar-actions {
        display: flex;
        gap: 6px;
        flex-shrink: 0;
    }

    /* Full controls collapsed by default on mobile */
    .hist-controls-collapse {
        display: none;
        width: 100%;
    }

    /* Expand when view has .filters-open */
    #view-historical.filters-open .hist-controls-collapse {
        display: block;
    }
}

/* ══════════════════════════════════════════
   CORRECCIÓN PROFESOR A2: Toggle modo técnico
   ══════════════════════════════════════════ */

.dev-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dev-toggle:hover {
    border-color: var(--border-hover);
    color: var(--text-secondary);
}

.dev-toggle.active {
    background: rgba(91, 185, 255, 0.12);
    border-color: rgba(91, 185, 255, 0.44);
    color: var(--blue-strong);
}

.dev-only {
    transition: opacity 0.2s ease, max-height 0.2s ease;
}

body:not(.dev-mode) .dev-only {
    display: none !important;
}

/* ══════════════════════════════════════════
   CORRECCIÓN PROFESOR A5: Móvil — mapa visible sin scroll
   ══════════════════════════════════════════ */

.dev-toggle svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .top-nav {
        min-height: 46px;
        padding: 0 12px;
    }

    .nav-brand {
        font-size: 0.8rem;
    }

    .nav-tabs {
        padding: 2px;
    }

    .nav-tab {
        padding: 5px 12px;
        font-size: 0.75rem;
    }

    .view {
        padding: 10px;
    }

    .rt-map-card,
    .hist-map-card {
        min-height: 55vh;
    }

    .map-wrap {
        min-height: 55vh;
    }

    #map-rt,
    #map-hist {
        height: calc(100% - 38px) !important;
    }

    .card-header {
        padding: 8px 12px;
        font-size: 0.72rem;
    }

    .live-panel {
        padding: 10px;
        gap: 8px;
    }

    #hist-seq-slider {
        width: 108px;
    }

    .hist-seq-label {
        min-width: 72px;
        font-size: 0.64rem;
    }

    .live-field {
        padding: 8px 10px;
    }

    .live-field .val {
        font-size: 0.85rem;
    }

    .hist-map-card {
        min-height: 50vh;
    }

    .results-panel {
        min-height: 300px;
        max-height: 300px;
    }

    .footer {
        display: none;
    }
}

@media (max-width: 480px) {
    .top-nav {
        min-height: 42px;
    }

    .nav-brand .brand-sub {
        display: none;
    }

    .rt-map-card {
        min-height: 50vh;
    }

    .map-wrap {
        min-height: 50vh;
    }

    .dev-toggle span {
        display: none;
    }
}

/* ══════════════════════════════════════════
   CORRECCIÓN PROFESOR: Tooltip Help Icon
   ══════════════════════════════════════════ */

.help-tooltip-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(91, 185, 255, 0.15);
    border: 1px solid rgba(91, 185, 255, 0.3);
    color: var(--blue-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: help;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 2px;
}

.help-tooltip-icon:hover {
    background: var(--blue-soft-2);
    border-color: var(--blue-strong);
    transform: scale(1.1);
}


/* Collapsable cards */
.card-body {
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 1000px;
    opacity: 1;
    overflow: hidden;
}

.card.collapsed .card-body {
    max-height: 0;
    opacity: 0;
}

.card.collapsed .chevron {
    transform: rotate(90deg) !important;
}

.card-header:hover {
    background: rgba(36, 56, 100, 0.6);
}

#sensor-3d-wrap {
    min-height: 160px;
    display: flex;
    justify-content: center;
    align-items: center;
}
