:root {
    --bg: #0b1117;
    --panel: #121b24;
    --panel-soft: #18232e;
    --panel-hover: #202d39;
    --border: #2a3947;
    --text: #f3f7fa;
    --muted: #9eb0bf;
    --accent: #2f9bf4;
    --accent-hover: #57b0f7;
    --success: #31c978;
    --danger: #ff5f63;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top, rgba(47, 155, 244, 0.08), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
select {
    font: inherit;
}

.radar-page {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 24px;
}

.radar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.eyebrow {
    margin-bottom: 5px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.radar-heading h1 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 2.7rem);
    line-height: 1.1;
}

.radar-location {
    margin-top: 7px;
    color: var(--muted);
    font-size: 1rem;
}

.header-status {
    flex: 0 0 auto;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 13px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 12px currentColor;
}

.status-current {
    color: var(--success);
    background: rgba(49, 201, 120, 0.1);
    border-color: rgba(49, 201, 120, 0.3);
}

.status-stale {
    color: var(--danger);
    background: rgba(255, 95, 99, 0.1);
    border-color: rgba(255, 95, 99, 0.3);
}

.radar-meta-card {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 18px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(18, 27, 36, 0.92);
    box-shadow: var(--shadow);
}

.meta-item {
    min-width: 0;
    padding: 15px 18px;
}

.meta-item + .meta-item {
    border-left: 1px solid var(--border);
}

.meta-label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.meta-item strong {
    display: block;
    overflow: hidden;
    font-size: 0.95rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.radar-panel {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(18, 27, 36, 0.94);
    box-shadow: var(--shadow);
}

.product-form {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.product-form label {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 750;
}

.product-select-row {
    width: min(560px, 100%);
}

.product-form select,
.speed-group select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    background: var(--panel-soft);
    color: var(--text);
    padding: 8px 12px;
}

.product-form select:focus,
.speed-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 155, 244, 0.14);
}

.radar-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

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

.control-btn {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-soft);
    color: var(--text);
    padding: 8px 13px;
    cursor: pointer;
    transition: 0.16s ease;
}

.control-btn:hover {
    transform: translateY(-1px);
    border-color: #436079;
    background: var(--panel-hover);
}

.control-btn:active {
    transform: translateY(0);
}

.control-primary {
    min-width: 92px;
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 750;
}

.control-primary:hover {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
}

.speed-group {
    margin-left: auto;
}

.speed-group label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.speed-group select {
    width: 110px;
}

.fullscreen-btn {
    white-space: nowrap;
}

.radar-viewer {
    overflow: hidden;
    border: 1px solid #35495a;
    border-radius: 14px;
    background: #000;
}

.radar-viewer-title,
.radar-viewer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: #0b1117;
}

.radar-viewer-title {
    border-bottom: 1px solid #273744;
    font-size: 0.87rem;
    font-weight: 750;
}

.radar-viewer-title span:last-child {
    color: var(--muted);
    font-weight: 650;
}

.radar-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 320px;
    overflow: hidden;
    background: #000;
}

.radar-image {
    display: block;
    width: 100%;
    height: auto;
    max-width: 1180px;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.radar-viewer-footer {
    border-top: 1px solid #273744;
    color: var(--muted);
    font-size: 0.86rem;
}

.radar-viewer-footer strong {
    color: var(--text);
}

.viewer-status {
    text-align: right;
}

.radar-unavailable {
    padding: 46px 20px;
    text-align: center;
}

.radar-unavailable h2 {
    margin: 0 0 8px;
}

.radar-unavailable p {
    margin: 0;
    color: var(--muted);
}

.page-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 4px 0;
    color: #708493;
    font-size: 0.8rem;
}

/* Fullscreen radar viewer */
.radar-viewer:fullscreen {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    border: 0;
    border-radius: 0;
    background: #000;
}

.radar-viewer:fullscreen .radar-image-wrap {
    flex: 1;
    min-height: 0;
}

.radar-viewer:fullscreen .radar-image {
    width: auto;
    max-width: 100%;
    max-height: calc(100vh - 90px);
}

@media (max-width: 900px) {
    .radar-meta-card {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .meta-item:nth-child(3) {
        border-left: 0;
        border-top: 1px solid var(--border);
    }

    .meta-item:nth-child(4) {
        border-top: 1px solid var(--border);
    }

    .speed-group {
        margin-left: 0;
    }
}

@media (max-width: 700px) {
    .radar-page {
        padding: 12px;
    }

    .radar-header {
        align-items: flex-start;
    }

    .radar-panel {
        padding: 12px;
    }

    .product-form {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
    }

    .product-select-row {
        width: 100%;
    }

    .radar-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .control-group {
        width: 100%;
    }

    .control-group:first-child {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
    }

    .control-btn {
        padding-left: 8px;
        padding-right: 8px;
    }

    .speed-group {
        justify-content: space-between;
    }

    .speed-group select {
        width: 145px;
    }

    .fullscreen-btn {
        width: 100%;
    }

    .radar-viewer-title,
    .radar-viewer-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .viewer-status {
        text-align: left;
    }

    .page-footer {
        flex-direction: column;
    }
}

@media (max-width: 520px) {
    .radar-meta-card {
        grid-template-columns: 1fr;
    }

    .meta-item + .meta-item {
        border-left: 0;
        border-top: 1px solid var(--border);
    }

    .radar-heading h1 {
        font-size: 1.65rem;
    }

    .status-badge {
        padding: 7px 10px;
    }

    .radar-image-wrap {
        min-height: 180px;
    }
}


/* --------------------------------------------------------------------------
   V2 radar controls
   -------------------------------------------------------------------------- */

.animation-controls,
.viewer-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.animation-controls {
    flex-wrap: wrap;
}

.viewer-actions {
    margin-left: auto;
}

.icon-btn {
    min-width: 46px;
    font-weight: 800;
}

.auto-refresh-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid rgba(49, 201, 120, 0.24);
    border-radius: 10px;
    background: rgba(49, 201, 120, 0.07);
    color: var(--muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.auto-refresh-status strong {
    color: var(--success);
    font-size: 0.76rem;
}

.auto-refresh-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 9px rgba(49, 201, 120, 0.75);
}

.refresh-countdown {
    min-width: 38px;
    color: #7f94a5;
    font-variant-numeric: tabular-nums;
}

.frame-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.latest-badge {
    display: none;
    margin-left: 7px;
    padding: 3px 7px;
    border: 1px solid rgba(49, 201, 120, 0.28);
    border-radius: 999px;
    background: rgba(49, 201, 120, 0.09);
    color: var(--success);
    font-size: 0.66rem;
    font-weight: 850;
    letter-spacing: 0.06em;
}

.latest-badge.is-latest {
    display: inline-flex;
}

@media (min-width: 1200px) {
    .radar-page {
        width: min(1540px, 100%);
    }
}

@media (max-width: 900px) {
    .animation-controls,
    .viewer-actions {
        width: 100%;
    }

    .viewer-actions {
        margin-left: 0;
        justify-content: space-between;
    }
}

@media (max-width: 700px) {
    .animation-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .viewer-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .auto-refresh-status {
        justify-content: center;
    }
}


/* --------------------------------------------------------------------------
   V3 scan timeline / scrubber
   -------------------------------------------------------------------------- */

.radar-timeline {
    padding: 18px 16px 14px;
    border-top: 1px solid #273744;
    background: #0d151d;
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 8px;
}

.timeline-title {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.selected-scan-time {
    color: var(--text);
    font-size: 0.84rem;
    font-variant-numeric: tabular-nums;
}

.timeline-slider {
    width: 100%;
    height: 18px;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
}

.timeline-slider::-webkit-slider-runnable-track {
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(90deg, #24445e, var(--accent));
}

.timeline-slider::-moz-range-track {
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(90deg, #24445e, var(--accent));
}

.timeline-slider::-webkit-slider-thumb {
    width: 17px;
    height: 17px;
    margin-top: -6px;
    appearance: none;
    -webkit-appearance: none;
    border: 3px solid #0d151d;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px rgba(87, 176, 247, 0.7), 0 0 12px rgba(47, 155, 244, 0.55);
}

.timeline-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: 3px solid #0d151d;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 1px rgba(87, 176, 247, 0.7), 0 0 12px rgba(47, 155, 244, 0.55);
}

.timeline-ticks {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    align-items: center;
    margin: -2px 2px 2px;
}

.timeline-tick {
    justify-self: center;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #405362;
    transition: transform 0.15s ease, background 0.15s ease;
}

.timeline-tick.is-viewed {
    background: #477da7;
}

.timeline-tick.is-active {
    transform: scale(1.7);
    background: var(--accent);
}

.timeline-labels {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #657b8c;
    font-size: 0.70rem;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
    .radar-timeline {
        padding: 16px 12px 12px;
    }

    .timeline-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .selected-scan-time {
        font-size: 0.8rem;
    }
}


/* --------------------------------------------------------------------------
   Refresh Now control
   -------------------------------------------------------------------------- */

.refresh-now-btn {
    white-space: nowrap;
}

.refresh-now-btn.is-refreshing,
.refresh-now-btn:disabled {
    cursor: wait;
    opacity: 0.72;
}

@media (max-width: 700px) {
    .refresh-now-btn {
        width: 100%;
    }
}


/* --------------------------------------------------------------------------
   Mobile responsiveness + safe fullscreen exit
   -------------------------------------------------------------------------- */

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.radar-page,
.radar-panel,
.radar-viewer,
.radar-image-wrap,
.radar-toolbar,
.animation-controls,
.viewer-actions,
.product-form,
.product-select-row,
.radar-meta-card,
.meta-item {
    min-width: 0;
}

.fullscreen-exit-btn {
    display: none;
}

/* This button lives INSIDE #radarViewer, so it remains accessible on phones
   after #radarViewer itself enters fullscreen mode. */
.radar-viewer:fullscreen .fullscreen-exit-btn {
    position: fixed;
    z-index: 10000;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 9px 13px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    background: rgba(8, 14, 20, 0.92);
    color: #fff;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 750;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.38);
    -webkit-tap-highlight-color: transparent;
}

.radar-viewer:fullscreen .fullscreen-exit-btn:hover,
.radar-viewer:fullscreen .fullscreen-exit-btn:focus-visible {
    border-color: var(--accent);
    outline: none;
}

/* Account for mobile display cutouts / safe areas in fullscreen. */
.radar-viewer:fullscreen {
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

.radar-viewer:fullscreen .radar-viewer-title {
    padding-right: 150px;
}

@media (max-width: 700px) {
    body {
        font-size: 15px;
    }

    .radar-page {
        width: 100%;
        max-width: 100%;
        padding: 8px;
    }

    .radar-header {
        gap: 12px;
        margin-bottom: 12px;
    }

    .radar-heading {
        min-width: 0;
    }

    .radar-heading h1 {
        font-size: clamp(1.45rem, 7vw, 2rem);
        overflow-wrap: anywhere;
    }

    .radar-location {
        font-size: 0.92rem;
    }

    .header-status {
        margin-left: auto;
    }

    .radar-meta-card {
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .meta-item {
        padding: 12px 13px;
    }

    .meta-item strong {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .radar-panel {
        padding: 10px;
        border-radius: 12px;
    }

    .product-form {
        margin-bottom: 12px;
    }

    .product-form select,
    .speed-group select {
        min-height: 46px;
        font-size: 16px; /* Prevents iOS zoom-on-focus */
    }

    .control-group:first-child {
        gap: 6px;
    }

    .control-btn {
        min-width: 0;
        min-height: 46px;
        touch-action: manipulation;
    }

    .control-primary {
        min-width: 0;
    }

    .viewer-actions {
        gap: 8px;
    }

    .auto-refresh-status {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .refresh-now-btn,
    .fullscreen-btn {
        width: 100%;
        min-height: 46px;
    }

    .radar-viewer {
        border-radius: 10px;
    }

    .radar-viewer-title {
        padding: 9px 10px;
        font-size: 0.8rem;
    }

    .radar-image-wrap {
        min-height: 0;
        width: 100%;
        overflow: hidden;
    }

    .radar-image {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    .radar-timeline {
        padding: 14px 10px 11px;
    }

    .timeline-slider {
        min-height: 32px;
        touch-action: pan-y;
    }

    .timeline-labels {
        font-size: 0.67rem;
    }

    .radar-viewer-footer {
        padding: 10px;
    }

    .page-footer {
        padding: 12px 2px 0;
        font-size: 0.73rem;
    }

    /* Mobile fullscreen: maximize radar area while keeping the exit control visible. */
    .radar-viewer:fullscreen .radar-viewer-title {
        padding-right: 142px;
    }

    .radar-viewer:fullscreen .radar-image-wrap {
        flex: 1 1 auto;
        min-height: 0;
    }

    .radar-viewer:fullscreen .radar-image {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: none;
        object-fit: contain;
    }

    .radar-viewer:fullscreen .radar-timeline {
        flex: 0 0 auto;
    }

    .radar-viewer:fullscreen .radar-viewer-footer {
        flex: 0 0 auto;
    }
}

@media (max-width: 480px) {
    .radar-header {
        flex-direction: column;
        align-items: stretch;
    }

    .header-status {
        margin-left: 0;
        align-self: flex-start;
    }

    .radar-meta-card {
        grid-template-columns: 1fr;
    }

    .meta-item,
    .meta-item:nth-child(3),
    .meta-item:nth-child(4) {
        border-left: 0;
    }

    .meta-item + .meta-item {
        border-top: 1px solid var(--border);
    }

    .control-group:first-child {
        grid-template-columns: 0.8fr 0.8fr 1.35fr 0.8fr 0.8fr;
    }

    .control-btn {
        padding: 7px 5px;
        font-size: 0.88rem;
    }

    .speed-group {
        display: grid;
        grid-template-columns: auto minmax(120px, 1fr);
        align-items: center;
    }

    .speed-group select {
        width: 100%;
    }

    .radar-viewer-title span:last-child {
        max-width: 65%;
        text-align: right;
    }

    .radar-viewer:fullscreen .radar-viewer-title {
        min-height: 58px;
        padding-right: 138px;
    }

    .radar-viewer:fullscreen .fullscreen-exit-btn {
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        min-height: 42px;
        padding: 8px 10px;
        font-size: 0.8rem;
    }
}


/* --------------------------------------------------------------------------
   Fullscreen exit button desktop/Joomla compatibility
   Prevent template button rules from stretching the control across the screen.
   -------------------------------------------------------------------------- */

.radar-viewer:fullscreen .fullscreen-exit-btn {
    position: fixed !important;
    top: max(12px, env(safe-area-inset-top)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    bottom: auto !important;
    left: auto !important;

    width: auto !important;
    max-width: 180px !important;
    min-width: 0 !important;

    display: inline-flex !important;
    flex: 0 0 auto !important;

    margin: 0 !important;
    white-space: nowrap !important;
}

@media (max-width: 700px) {
    .radar-viewer:fullscreen .fullscreen-exit-btn {
        width: auto !important;
        max-width: 170px !important;
    }
}
