@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&display=swap');

:root {
    --bg-dark: #050a10;
    --navy-dark: #0a192f;
    --cyan-glow: #00f2ff;
    --cyan-dim: rgba(0, 242, 255, 0.15);
    --gold-glow: #f0b429;
    --red-alert: #ff4d4d;
    --green-safe: #00ffaa;
    --glass-bg: rgba(10, 25, 47, 0.7);
    --glass-border: rgba(0, 242, 255, 0.2);
    --text-primary: #e6f1ff;
    --text-secondary: #8892b0;
    --blue-safe: #33ccff;
    --font-main: 'Outfit', sans-serif;
}

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

html,
body {
    overflow-x: hidden !important;
    width: 100vw !important;
    position: relative;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 0;
}

body {
    background: #050a10;
    /* Premium Mesh Gradient Background */
    background-image:
        radial-gradient(at 0% 0%, rgba(0, 242, 255, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(0, 242, 255, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(10, 25, 47, 0.1) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(0, 242, 255, 0.08) 0px, transparent 50%),
        linear-gradient(135deg, #050a10 0%, #0a192f 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow-x: hidden !important;
    /* Prevent horizontal scroll on body */
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    position: relative;
    /* Forzar que nada haga scroll horizontal */
}

.layout-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    margin: 0;
    padding: 0;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
}

.dashboard-container {
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    overflow-x: hidden !important;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
        "header header"
        "metrics ship"
        "chart chart"
        "messages messages"
        "footer footer";
    gap: 15px;
    box-sizing: border-box;
}

/* Header Styling */
.header {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
    transition: all 0.3s ease;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
}

.header-logo {
    height: 120px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.9)) brightness(1.3) contrast(1.5);
    transition: all 0.3s ease;
}

.header-title h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, #fff, var(--cyan-glow));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-links {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-gauge-container {
    width: 130px;
    height: 85px;
    margin-right: 15px;
    transition: transform 0.2s;
}

.header-gauge-container:hover {
    transform: scale(1.05);
}

.gauge-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 5px var(--cyan-dim));
}

#gaugeValuePath {
    transition: stroke-dashoffset 1s ease-out;
}

#gaugeNeedle {
    transition: transform 1s cubic-bezier(0.1, 1.75, 0.5, 1);
    transform-origin: 50px 50px;
}

.needle-jitter {
    animation: gaugeJitter 0.15s infinite linear;
    transform-origin: 50px 50px;
}

@keyframes gaugeJitter {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(0.8deg);
    }

    50% {
        transform: rotate(0deg);
    }

    75% {
        transform: rotate(-0.8deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

/* Metrics Cards (Bento style) */
.metrics-grid {
    grid-area: metrics;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-height: 80vh;
    overflow-y: auto;
    padding-right: 5px;
    align-content: start;
}

.metric-card {
    background: rgba(10, 25, 47, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 242, 255, 0.1);
    padding: 20px 25px;
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 6px solid var(--cyan-glow);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 140px;
    justify-content: center;
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Center vertically */
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 5px;
    font-family: monospace;
}

.ip-meta {
    color: var(--gold-glow);
}

.time-meta {
    color: var(--cyan-glow);
    font-size: 0.9rem; /* Increased from 0.65rem */
    text-shadow: 0 0 5px var(--cyan-dim);
}

.metric-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px var(--cyan-dim);
    border-color: rgba(0, 242, 255, 0.3);
}

.delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: all 0.2s;
    z-index: 10;
}

.metric-card:hover .delete-btn {
    opacity: 0.5;
}

.delete-btn:hover {
    color: var(--red-alert) !important;
    opacity: 1 !important;
}

.editable-label {
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.5px;
    width: 90%;
    outline: none;
    padding: 2px 0;
    margin-bottom: 4px;
}

.editable-label:hover,
.editable-label:focus {
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--cyan-glow);
    color: #fff;
    border-radius: 3px 3px 0 0;
}

.metric-value {
    font-size: 2.5rem;
    /* Larger value */
    font-weight: 800;
    color: #fff;
    line-height: 1;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.metric-unit {
    font-size: 0.9rem;
    color: var(--cyan-glow);
    font-weight: 400;
}

/* Add Card Styling */
.add-card {
    background: rgba(10, 25, 47, 0.2);
    border: 2px dashed var(--glass-border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--cyan-glow);
    transition: all 0.3s;
    min-height: 100px;
}

.add-card:hover {
    background: var(--cyan-dim);
    border-color: var(--cyan-glow);
    transform: scale(0.98);
}

.add-card span {
    font-size: 2rem;
    margin-bottom: 5px;
}

.add-card label {
    font-size: 0.7rem;
    font-weight: 800;
    cursor: pointer;
}

/* Interactive Ship View */
.ship-visualizer {
    grid-area: ship;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    position: relative;
    overflow: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    width: fit-content;
    /* Shrink to fit the map */
    justify-self: end;
    /* Align to the right */
    -webkit-overflow-scrolling: touch;
    /* Asegurar que el contenedor no corte los marcadores */
    overflow-x: auto;
    overflow-y: auto;
}

.visualizer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 10px;
}

.lock-btn,
.fullscreen-btn {
    background: var(--red-alert);
    color: #fff;
    border: none;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lock-btn:not([style*="red-alert"]) {
    background: var(--cyan-glow);
    color: #000;
}

.fullscreen-btn {
    background: var(--cyan-glow);
    color: #000;
    margin-left: 8px;
}

.lock-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.2);
}

.map-container {
    position: relative;
    display: inline-block;
    align-self: center;
    width: auto;
    max-width: 100%;
    /* min-width: 600px; Removed to allow full scaling */
    cursor: crosshair;
    /* El contenedor se ajustará dinámicamente al tamaño de la imagen via JavaScript */
    /* Esto asegura que los marcadores se posicionen correctamente en todos los dispositivos */
    box-sizing: border-box;
    overflow: visible !important;
    /* Asegurar que los marcadores no se corten */
    /* Asegurar que los marcadores estén dentro del contenedor */
}

#markersLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Permitir que los marcadores sean clickeables */
}

#markersLayer .sensor-marker {
    pointer-events: auto;
}

.ship-model {
    display: block;
    width: auto;
    /* Was 100%, caused letterboxing */
    height: auto;
    max-width: 100%;
    max-height: 80vh;
    /* object-fit: contain; Removed, let the element size itself */
    filter: drop-shadow(0 0 30px rgba(0, 242, 255, 0.25));
    opacity: 0.95;
    user-select: none;
    -webkit-user-drag: none;
}

/* Sensor Markers on Map */
.sensor-marker {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: move;
    z-index: 100;
    /* transition: transform 0.1s; REMOVED to avoid lag while dragging */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    transform: translate(-50%, -50%);
    /* Center the marker on the interaction point */
}

.sensor-marker:active {
    transform: translate(-50%, -50%) scale(1.2);
    z-index: 1000;
}

/* Dual View Distinctions */
.marker-top::before {
    border: 2px solid var(--cyan-glow);
}

.marker-side::before {
    border: 2px solid var(--gold-glow);
    animation-delay: 1s;
    /* Offset pulse for side markers */
}

/* Highlight both on hover */
.sensor-marker:hover {
    z-index: 1001;
    filter: brightness(1.5);
}

/* Pinpoint Calibrated Marker Positions (Relative to Silhouette) */
.m1 {
    top: 23%;
    left: 70%;
}

/* Proa (Top View) */
.m2 {
    top: 23%;
    left: 30%;
}

/* Popa (Top View) */
.m3 {
    top: 15%;
    left: 50%;
}

/* Babor (Top View) */
.m4 {
    top: 31%;
    left: 50%;
}

/* Estribor (Top View) */
.m5 {
    top: 76%;
    left: 45%;
}

/* Bodega A (Side View) */
.m6 {
    top: 76%;
    left: 55%;
}

/* Bodega B (Side View) */

.sensor-marker::before {
    content: '';
    width: 8px;
    /* Slightly smaller */
    height: 8px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px var(--gold-glow);
    margin-bottom: 3px;
    animation: markerPulse 2s infinite ease-in-out;
}

@keyframes markerPulse {
    0% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 10px var(--gold-glow), 0 0 20px var(--gold-glow);
    }

    50% {
        transform: scale(1.3);
        opacity: 0.8;
        box-shadow: 0 0 20px var(--gold-glow), 0 0 40px var(--gold-glow);
    }

    100% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 10px var(--gold-glow), 0 0 20px var(--gold-glow);
    }
}

/* Animación de alerta de temperatura alta (parpadeo) */
@keyframes temperatureAlert {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 20px var(--red-alert), 0 0 40px var(--red-alert), 0 0 60px var(--red-alert);
        border-color: var(--red-alert);
    }

    50% {
        opacity: 0.3;
        box-shadow: 0 0 10px var(--red-alert), 0 0 20px var(--red-alert);
        border-color: rgba(255, 77, 77, 0.5);
    }
}

/* Clase para alerta de temperatura alta en cards */
.metric-card.alert-high-temp {
    animation: temperatureAlert 1s infinite;
    border-left: 6px solid var(--red-alert) !important;
    background: rgba(255, 77, 77, 0.1) !important;
}

/* Clase para alerta de temperatura alta en marcadores */
.sensor-marker.alert-high-temp::before {
    background: var(--red-alert) !important;
    animation: temperatureAlert 1s infinite;
    box-shadow: 0 0 20px var(--red-alert), 0 0 40px var(--red-alert), 0 0 60px var(--red-alert) !important;
}

.sensor-marker.alert-high-temp .marker-label {
    background: rgba(255, 77, 77, 0.9) !important;
    border-color: var(--red-alert) !important;
    color: #fff !important;
    animation: temperatureAlert 1s infinite;
}

.sensor-marker.alert-high-temp .marker-temp {
    color: var(--red-alert) !important;
    text-shadow: 0 0 10px var(--red-alert), 0 0 20px var(--red-alert) !important;
    animation: temperatureAlert 1s infinite;
}

.marker-label {
    font-size: 0.65rem;
    color: var(--gold-glow);
    font-weight: 800;
    background: rgba(10, 25, 47, 0.85);
    backdrop-filter: blur(4px);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(240, 180, 41, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transform: translateX(-50%);
    /* Aparecer por encima del punto */
    margin-bottom: 8px;
    /* Permitir que el transform se ajuste dinámicamente para evitar solapamientos */
    transition: opacity 0.3s ease-out, transform 0.2s ease-out;
    display: none;
    /* Oculto por defecto */
    white-space: nowrap;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    z-index: 101;
    /* El label aparece arriba del punto */
}

.marker-temp {
    font-size: 0.9rem;
    color: #fff;
    font-weight: 800;
    text-shadow: 0 0 10px var(--gold-glow);
    display: none;
    /* Oculto por defecto */
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* Línea conectora entre el marcador y el label cuando está desplazado */
.marker-connector {
    position: absolute;
    width: 2px;
    background: linear-gradient(to top, var(--cyan-glow), rgba(0, 242, 255, 0.3));
    display: none;
    z-index: 99;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(0, 242, 255, 0.5);
    opacity: 0.6;
}

.marker-side .marker-connector {
    background: linear-gradient(to top, var(--gold-glow), rgba(255, 215, 0, 0.3));
    box-shadow: 0 0 4px rgba(255, 215, 0, 0.5);
}

/* Efecto radar para puntos en estado normal */
.radar-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    pointer-events: none;
    z-index: 1;
}

.radar-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border: 2px solid var(--cyan-glow);
    border-radius: 50%;
    background: transparent;
    opacity: 0;
}

.marker-side .radar-ring {
    border-color: var(--gold-glow);
}

.radar-ring.ring-1 {
    animation: radarPulse 8s infinite ease-out;
    animation-delay: 0s;
}

.radar-ring.ring-2 {
    animation: radarPulse 8s infinite ease-out;
    animation-delay: 0.66s;
}

.radar-ring.ring-3 {
    animation: radarPulse 8s infinite ease-out;
    animation-delay: 1.33s;
}

@keyframes radarPulse {
    0% {
        width: 8px;
        height: 8px;
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(0, 242, 255, 0);
    }

    1% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(0, 242, 255, 0.7);
    }

    25% {
        width: 60px;
        height: 60px;
        opacity: 0;
        box-shadow: 0 0 0 20px rgba(0, 242, 255, 0);
    }

    25.01%,
    100% {
        width: 8px;
        height: 8px;
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(0, 242, 255, 0);
    }
}

.marker-side .radar-ring.ring-1,
.marker-side .radar-ring.ring-2,
.marker-side .radar-ring.ring-3 {
    animation-name: radarPulseGold;
}

@keyframes radarPulseGold {
    0% {
        width: 8px;
        height: 8px;
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }

    1% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7);
    }

    25% {
        width: 60px;
        height: 60px;
        opacity: 0;
        box-shadow: 0 0 0 20px rgba(255, 215, 0, 0);
    }

    25.01%,
    100% {
        width: 8px;
        height: 8px;
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}

/* Bodega B */

.live-clock {
    font-family: 'Outfit';
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--cyan-glow);
    text-shadow: 0 0 10px var(--cyan-glow);
}

.ship-selector {
    background: var(--navy-dark);
    color: #fff;
    border: 1px solid var(--glass-border);
    padding: 5px 15px;
    border-radius: 5px;
    font-family: 'Outfit';
    font-weight: 600;
    margin-left: 20px;
}

/* Chart Area */
/* Chart Area */
.chart-section {
    grid-area: chart;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    /* Slightly reduced radius */
    padding: 10px 15px;
    /* Reduced padding (top/bottom, left/right) */
    display: flex;
    flex-direction: column;
}

.custom-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    /* Reduced gap */
    margin: 0 auto 10px auto;
    /* Centered, reduced bottom margin */
    justify-content: center;
    max-width: 95%;
    /* Prevent edge touching */
}

.legend-btn {
    background: rgba(10, 25, 47, 0.5);
    border: 1px solid;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    min-width: 70px;
    /* Slightly narrower */
    height: 28px;
    /* Slightly shorter */
    line-height: 26px;
    display: inline-block;
    margin: 2px;
    padding: 0 8px;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
}

.legend-btn:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

.legend-btn.inactive {
    background: rgba(0, 0, 0, 0.2);
    border-color: #555 !important;
    color: #555 !important;
    text-decoration: line-through;
    opacity: 0.6;
}

/* Target specific chart container, not all divs */
.chart-container-wrapper {
    flex: 1;
    min-height: 250px;
    /* Exact height */
    position: relative;
    width: 100%;
}

/* Messages Area */
.messages-panel {
    grid-area: messages;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 15px;
    padding-right: 10px;
}

.message-item {
    background: rgba(255, 255, 255, 0.03);
    border-left: 2px solid var(--gold-glow);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

/* Status Indicators */
.status-pill {
    padding: 6px 16px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-online {
    background: rgba(0, 255, 170, 0.1);
    color: var(--green-safe);
    border: 1px solid var(--green-safe);
}

.status-offline {
    background: rgba(255, 77, 77, 0.1);
    color: var(--red-alert);
    border: 1px solid var(--red-alert);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--cyan-glow);
}

/* Pantalla completa para móviles */
.ship-visualizer:fullscreen,
.ship-visualizer:-webkit-full-screen,
.ship-visualizer:-moz-full-screen,
.ship-visualizer:-ms-fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
    padding: 20px;
}

.ship-visualizer:fullscreen .map-container,
.ship-visualizer:-webkit-full-screen .map-container,
.ship-visualizer:-moz-full-screen .map-container,
.ship-visualizer:-ms-fullscreen .map-container {
    width: auto !important;
    height: auto !important;
    display: inline-block !important;
    align-items: center;
    justify-content: center;
    position: relative !important;
    min-width: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    /* El JavaScript ajustará el tamaño al de la imagen */
}

/* Asegurar que el contenedor tenga el mismo tamaño que la imagen en pantalla completa */
.ship-visualizer:fullscreen .map-container img,
.ship-visualizer:-webkit-full-screen .map-container img,
.ship-visualizer:-moz-full-screen .map-container img,
.ship-visualizer:-ms-fullscreen .map-container img {
    position: relative;
    z-index: 1;
}

/* Asegurar que markersLayer esté correctamente posicionado en pantalla completa */
.ship-visualizer:fullscreen #markersLayer,
.ship-visualizer:-webkit-full-screen #markersLayer,
.ship-visualizer:-moz-full-screen #markersLayer,
.ship-visualizer:-ms-fullscreen #markersLayer {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: visible !important;
    z-index: 100;
    pointer-events: none;
}

.ship-visualizer:fullscreen #markersLayer .sensor-marker,
.ship-visualizer:-webkit-full-screen #markersLayer .sensor-marker,
.ship-visualizer:-moz-full-screen #markersLayer .sensor-marker,
.ship-visualizer:-ms-fullscreen #markersLayer .sensor-marker {
    pointer-events: auto;
}

.ship-visualizer:fullscreen .ship-model,
.ship-visualizer:-webkit-full-screen .ship-model,
.ship-visualizer:-moz-full-screen .ship-model,
.ship-visualizer:-ms-fullscreen .ship-model {
    max-height: 95vh !important;
    max-width: 95vw !important;
    width: auto !important;
    height: auto !important;
    min-height: 85vh !important;
    object-fit: contain;
}

/* PC Specific Fullscreen Optimization */
@media (min-width: 769px) {

    .ship-visualizer:fullscreen .ship-model,
    .ship-visualizer:-webkit-full-screen .ship-model,
    .ship-visualizer:-moz-full-screen .ship-model,
    .ship-visualizer:-ms-fullscreen .ship-model {
        /* Use max-width/height to let the image maintain its natural aspect ratio within the box */
        max-width: 98vw !important;
        max-height: 92vh !important;
        width: auto !important;
        height: auto !important;
        min-height: auto !important;
        /* Overriding previous min-height */
        object-fit: contain;
        display: block;
        margin: 0 auto;
    }

    .ship-visualizer:fullscreen .map-container,
    .ship-visualizer:-webkit-full-screen .map-container {
        /* Let the container shrink-wrap the image to ensure marker alignment */
        width: auto !important;
        height: auto !important;
        display: inline-block !important;
        position: relative !important;
    }
}

/* Forzar orientación horizontal en pantalla completa (móviles) - El JavaScript manejará el bloqueo de orientación */

/* Responsive */

/* Fix for Chart Scrolling and Height on Touch Devices */
@media (max-width: 1024px) {
    .chart-container-wrapper {
        width: 90% !important;
        margin: 0 auto;
        height: 220px !important;
        min-height: auto !important;
    }
}

/* Chart Fullscreen Mode */
.chart-container-wrapper:fullscreen,
.chart-container-wrapper:-webkit-full-screen,
.chart-container-wrapper:-moz-full-screen,
.chart-container-wrapper:-ms-fullscreen {
    background: var(--bg-dark);
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 99999;
}

.chart-container-wrapper:fullscreen canvas,
.chart-container-wrapper:-webkit-full-screen canvas,
.chart-container-wrapper:-moz-full-screen canvas,
.chart-container-wrapper:-ms-fullscreen canvas {
    width: 95vw !important;
    height: 90vh !important;
}

/* Ensure controls are visible in fullscreen */
.chart-container-wrapper:fullscreen .chart-zoom-controls,
.chart-container-wrapper:-webkit-full-screen .chart-zoom-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100000;
}

@media (max-width: 1400px) {
    .dashboard-container {
        width: 100%;
        max-width: 100%;
        padding: 5px 10px 15px 10px;
        /* Reducir padding superior */
        overflow-x: hidden !important;
        grid-template-columns: 100%;
        grid-template-areas:
            "header"
            "metrics"
            "ship"
            "chart"
            "messages";
        display: block;
        /* Simplificar grid en móvil para evitar desbordes */
    }

    .header {
        padding: 0;
        margin-top: -10px;
        /* Subir todo el bloque */
        margin-bottom: 10px;
        /* Reducir espacio con lo de abajo */
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        /* Logo a la izquierda */
        gap: 5px;
        /* Gap mínimo */
        background: transparent;
        border: none;
        box-shadow: none;
        width: 100%;
    }

    .header-logo {
        height: 250px !important;
        /* Ajustar a un tamaño grande pero controlable */
        width: auto !important;
        max-width: 100vw !important;
        margin-left: -20px !important;
        margin-top: -30px !important;
        margin-bottom: -30px !important;
        padding: 0;
        display: block;
        align-self: flex-start;
        filter: drop-shadow(0 0 30px rgba(255, 255, 255, 0.6));
        pointer-events: none !important;
        /* No bloquear clicks en el selector */
        position: relative;
        z-index: 1;
    }

    .header-title {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
        padding-left: 5px;
    }

    .header-status {
        width: 100%;
        justify-content: flex-start;
        margin-top: 5px;
        gap: 10px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
        /* Una columna pura en móvil pequeño */
        max-height: none;
        width: 100%;
        padding: 0;
        gap: 15px;
    }
}

/* Tablets: Mantener 2 columnas para pantallas medianas (600px - 1400px) */
@media (min-width: 600px) and (max-width: 1400px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }

    .metric-card {
        min-height: 140px;
    }

    .ship-visualizer {
        margin: 0 auto !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        justify-content: center !important;
    }

    .map-container {
        margin: 0 auto !important;
        text-align: center !important;
    }
}

/* Mobile Landscape Optimization: 2 columns for metric cards */
@media (max-width: 932px) and (orientation: landscape) {
    .metrics-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .metric-card {
        min-height: 110px !important;
        padding: 10px 15px !important;
    }

    .metric-value {
        font-size: 1.8rem !important;
    }
}

/* Móviles y tablets - Imagen más grande */
@media (max-width: 768px) {
    .ship-visualizer {
        width: 100%;
        max-width: 100%;
        padding: 0;
        overflow-y: hidden;
        overflow-x: auto !important;
        border-radius: 12px;
        background: rgba(10, 25, 47, 0.5);
        border: 1px solid var(--glass-border);
        display: block !important;
        text-align: left !important;
        justify-self: start !important;
    }

    .ship-model {
        width: auto !important;
        height: auto !important;
        min-width: 1000px !important;
        /* Un poco más ancho para asegurar que se vea todo */
        max-width: none !important;
        display: block !important;
        margin: 0 !important;
        /* No centrar */
    }

    .map-container {
        width: 1000px !important;
        min-width: 1000px !important;
        max-width: none !important;
        display: block !important;
        position: relative !important;
        overflow: visible !important;
        margin: 0 !important;
        /* Alinear al inicio del scroll */
        box-sizing: border-box;
    }

    #markersLayer {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 1000px !important;
        /* Coincidir con la imagen */
        height: 100% !important;
        overflow: visible !important;
    }

    .message-item {
        font-size: 0.8rem;
        padding: 10px 15px !important;
    }

    .header {
        gap: 10px !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        height: auto !important;
    }

    .header-title {
        width: 100%;
        justify-content: center;
    }

    .header-status {
        width: 100%;
        justify-content: center;
        flex-direction: column;
        gap: 10px;
    }

    .header-links {
        width: 100%;
        justify-content: center;
        gap: 8px;
        margin-top: 5px;
    }

    .header-logo {
        height: 60px !important;
        width: auto !important;
        margin: 0 !important;
        filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
    }

    .header-title h1 {
        font-size: 1.2rem;
        justify-content: center;
    }

    .ship-selector {
        margin-left: 0;
        /* Reset margin since it's in a gap container now */
        padding: 6px 12px;
        font-size: 0.9rem;
        position: relative !important;
        z-index: 100 !important;
        /* Estar sobre el logo si hay solapamiento */
        background: var(--navy-dark) !important;
        pointer-events: auto !important;
        border: 1px solid var(--cyan-glow);
        color: var(--cyan-glow);
        border-radius: 4px;
    }
}

/* Tablets en landscape y portrait ancho (incluyendo iPad 768px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .ship-model {
        width: 100%;
        height: auto;
    }

    .header {
        flex-direction: column !important;
        /* Stack rows */
        align-items: center !important;
        padding: 30px !important;
        gap: 60px !important;
        /* HUGE GAP */
        height: auto !important;
    }

    /* Reset vertical stack hack */
    .header-title {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        margin-bottom: 20px !important;
    }

    .header-status {
        margin-top: 20px !important;
        width: 100%;
        justify-content: center;
        gap: 20px;
    }

    .header-logo {
        height: 180px !important;
        margin: 0 !important;
        pointer-events: none;
        z-index: 1;
        position: relative;
    }

    .ship-selector {
        margin: 0 !important;
        position: relative;
        z-index: 100 !important;
        font-size: 1.1rem;
        padding: 10px 20px;
    }
}

/* MODAL STYLES */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    background: rgba(0, 0, 0, 0.85);
    /* Darker background for focus */
    backdrop-filter: blur(8px);
    z-index: 20000;
    /* Higher than anything else */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
}

.modal-content {
    background: var(--navy-dark);
    padding: 30px;
    border-radius: 15px;
    border: 1px solid var(--cyan-glow);
    box-shadow: 0 0 30px rgba(0, 242, 255, 0.3);
    text-align: center;
    width: 95%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    margin: auto;
    position: relative;
}

.modal-content h3 {
    color: var(--cyan-glow);
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-input {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--text-secondary);
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.modal-input:focus {
    outline: none;
    border-color: var(--cyan-glow);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.modal-btn.cancel {
    background: rgba(255, 77, 77, 0.2);
    color: var(--red-alert);
}

.modal-btn.cancel:hover {
    background: rgba(255, 77, 77, 0.4);
}

.modal-btn.confirm {
    background: rgba(0, 242, 255, 0.2);
    color: var(--cyan-glow);
}

.modal-btn.confirm:hover {
    background: rgba(0, 242, 255, 0.4);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

/* --- MOBILE ROTATION HINT --- */
.mobile-rotate-hint {
    display: none;
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(0, 242, 255, 0.05);
    border-radius: 10px;
    border: 1px dashed rgba(0, 242, 255, 0.3);
}

.rotate-icon {
    font-size: 2.5rem;
    margin-bottom: 5px;
    display: inline-block;
    animation: rotate-phone 3s infinite ease-in-out;
}

@keyframes rotate-phone {
    0% {
        transform: rotate(0deg);
    }

    30% {
        transform: rotate(90deg);
    }

    50% {
        transform: rotate(90deg);
    }

    /* Pause */
    80% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

@media (max-width: 600px) {
    .header {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
        text-align: center;
    }

    .header-logo {
        height: 60px;
    }

    .header-status {
        justify-content: center;
        width: 100%;
        gap: 10px;
    }

    .header-links {
        justify-content: center;
        width: 100%;
        gap: 8px;
    }

    .header-links a, 
    .header-links button {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
    }

    .header-gauges {
        justify-content: center;
        width: 100%;
    }

    .ship-selector {
        width: 100%;
        max-width: 250px;
        margin: 5px 0;
    }
}

@media (max-width: 768px) {
    .mobile-rotate-hint {
        display: block;
    }
}

/* --- INTERACTIVE MARKER HIGHLIGHT --- */
@keyframes highlight-card-pulse {
    0% {
        background-color: var(--navy-dark);
        transform: scale(1);
        border-color: var(--cyan-glow);
    }

    50% {
        background-color: rgba(0, 242, 255, 0.3);
        transform: scale(1.05);
        border-color: white;
        box-shadow: 0 0 20px var(--cyan-glow);
    }

    100% {
        background-color: var(--navy-dark);
        transform: scale(1);
        border-color: var(--cyan-glow);
    }
}

.highlight-card {
    animation: highlight-card-pulse 0.8s ease-in-out 3;
    /* Pulse 3 times fast */
    z-index: 1000;
    position: relative;
    border: 2px solid var(--cyan-glow) !important;
}

/* Toast Notification */
.sensor-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 25, 47, 0.95);
    border: 1px solid var(--cyan-glow);
    padding: 10px 20px;
    border-radius: 30px;
    color: var(--cyan-glow);
    font-weight: bold;
    z-index: 20000;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    font-size: 1rem;
    white-space: nowrap;
}

/* --- FULL SCREEN ROTATION PROMPT --- */
#rotationPrompt {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--navy-dark);
    z-index: 19000;
    /* Below Toast (20000) but above everything else */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

#rotationPrompt .rotate-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotate-phone 3s infinite ease-in-out;
}

#rotationPrompt h3 {
    color: var(--cyan-glow);
    font-size: 1.5rem;
    margin-bottom: 15px;
}

#rotationPrompt p {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 300px;
}

/* BOTÓN AÑADIR SENSOR */
.metric-card.add-card {
    background: transparent;
    border: 2px dashed var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--cyan-glow);
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 130px;
    opacity: 0.6;
}

.metric-card.add-card:hover {
    background: rgba(100, 255, 218, 0.05);
    border-color: var(--cyan-glow);
    opacity: 1;
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(100, 255, 218, 0.2);
}

/* Professional Footer Styles */
.main-footer {
    grid-area: footer;
    grid-column: 1 / -1;
    width: 100%;
    padding: 30px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 50px;
    border-top: 1px solid var(--glass-border);
    background: rgba(10, 25, 47, 0.4);
    backdrop-filter: blur(10px);
    letter-spacing: 0.8px;
    position: relative;
    z-index: 10;
    clear: both;
}

.main-footer p {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.main-footer a {
    color: var(--cyan-glow);
    text-decoration: none !important;
    font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 2px solid transparent;
    padding-bottom: 2px;
}

.main-footer a:hover {
    text-shadow: 0 0 15px var(--cyan-glow);
    border-bottom: 2px solid var(--cyan-glow);
    filter: brightness(1.2);
}

/* --- TABLE HEADERS STACKING --- */
.th-sensor-id {
    display: block;
    font-size: 0.75rem;
    color: var(--cyan-glow);
    opacity: 0.8;
    text-transform: uppercase;
}

.th-sensor-name {
    display: block;
    font-weight: bold;
    color: #fff;
    font-size: 0.9rem;
}

/* CHART ZOOM CONTROLS */
.chart-container-wrapper {
    position: relative;
    width: 100%;
    height: 450px !important;
    min-height: 450px !important;
    max-height: 450px !important;
    /* REFORCED FIXED HEIGHT TO PREVENT INFINITE SLIDING */
    background: rgba(10, 25, 47, 0.3);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    padding: 5px;
    overflow: hidden;
    /* Prevent canvas from leaking during resize */
}

.chart-zoom-controls {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    /* Center vertically relative to chart area */
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.chart-zoom-controls button {
    width: 32px;
    height: 32px;
    background: rgba(10, 25, 47, 0.8);
    border: 1px solid var(--glass-border);
    color: var(--cyan-glow);
    border-radius: 6px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.chart-zoom-controls button:hover {
    background: var(--cyan-glow);
    color: var(--bg-dark);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.4);
}

.chart-zoom-controls button:active {
    transform: scale(0.95);
}

/* CHART LOADING OVERLAY */
.chart-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 25, 47, 0.95);
    /* More opaque */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    /* Super high z-index */
    border-radius: 12px;
    border: 2px solid var(--cyan-glow);
    /* Neon border */
    gap: 15px;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(10px);
    /* Stronger blur */
}

.chart-loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
    /* Hard hide */
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 242, 255, 0.1);
    border-top: 3px solid var(--cyan-glow);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

.chart-loading-overlay span {
    color: var(--cyan-glow);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(0, 242, 255, 0.5);
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* BACK TO TOP BUTTON */
.back-to-top {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 45px;
    height: 45px;
    background: rgba(10, 25, 47, 0.8);
    border: 1px solid var(--cyan-glow);
    border-radius: 50%;
    color: var(--cyan-glow);
    font-size: 24px;
    display: none;
    /* Hidden by default */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 242, 255, 0.2);
}

.back-to-top.visible {
    display: flex;
    animation: fadeIn 0.3s ease-in-out;
}

.back-to-top:hover {
    background: var(--cyan-glow);
    color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.6);
    transform: translateY(-5px);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* --- DEMO LAYOUT SPECIFIC OPTIMIZATIONS --- */
.demo-layout {
    grid-template-columns: 1fr 1.6fr !important;
}

.demo-layout .ship-visualizer {
    width: 100% !important;
    justify-self: stretch !important;
}

.demo-layout .ship-model {
    width: 100% !important;
}

@media (max-width: 1024px) {
    .demo-layout {
        grid-template-columns: 1fr !important;
        grid-template-areas:
            "header"
            "metrics"
            "ship"
            "chart"
            "messages"
            "footer" !important;
    }
}