/* xKey Mobile CSS */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    background-color: #f5f5f5;
    position: relative;
}

#app {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

section {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: none;
    background-color: #fff;
}

section.active {
    display: block;
}

/* Common Elements */
header {
    background-color: #e00;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    height: 60px;
}

header h1 {
    font-size: 20px;
    text-align: center;
    flex-grow: 1;
    margin: 0;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
}

.icon-button i {
    font-size: 20px;
}

/* Login Section */
#login-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.logo-container {
    margin-bottom: 40px;
}

.logo-container img {
    max-width: 200px;
}

.form-container {
    width: 100%;
    max-width: 320px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
}

.form-group button {
    width: 100%;
    padding: 12px;
    background-color: #e00;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.error-message {
    color: #e00;
    margin-top: 20px;
    text-align: center;
    display: none;
}

/* Devices Section */
#user-info {
    position: absolute;
    top: 5px;
    left: 10px;
    font-size: 12px;
    opacity: 0.8;
}

.search-container {
    padding: 10px;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
}

.search-container input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 16px;
}

.devices-list {
    overflow-y: auto;
    height: calc(100% - 120px);
    background-color: #fff;
}

/* Updated Device Item Styles */
.device-item {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    position: relative;
    cursor: pointer;
}

.device-item:active {
    background-color: #f5f5f5;
}

.device-icon-container {
    width: 50px;
    height: 50px;
    background-color: #0c0;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 20px; /* Increased spacing */
    position: relative;
}

.device-icon-container i {
    color: white;
    font-size: 24px;
}

.device-icon-container::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #0c0;
}

.device-info {
    flex-grow: 1;
}

.device-name {
    font-weight: bold;
    font-size: 18px;
}

.device-time {
    font-size: 12px;
    color: #999;
    position: absolute;
    top: 15px;
    right: 40px; /* Position to make room for status dot */
    text-align: right;
}

/* Updated Status Dot */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);
}

/* Status Colors */
.status-blu {
    background-color: #00f;
}

.status-verde {
    background-color: #0c0;
}

.status-rosso {
    background-color: #f00;
}

.status-giallo {
    background-color: #ff0;
}

/* Tracker Section */
#map-container {
    width: 100%;
    height: 60%;
    position: relative;
}

.status-indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-left: 10px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}

#info-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    transition: height 0.3s ease;
    height: 40%;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
}

.panel-header h2 {
    font-size: 18px;
    margin: 0;
}

.toggle-button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
}

.panel-content {
    padding: 15px;
    overflow-y: auto;
    flex-grow: 1;
}

.info-item {
    display: flex;
    margin-bottom: 15px;
    align-items: flex-start;
}

.info-item i {
    width: 24px;
    height: 24px;
    margin-right: 15px;
    margin-top: 2px;
    text-align: center;
    color: #e00;
    font-size: 20px;
}

.info-text {
    flex-grow: 1;
}

.info-text .label {
    display: block;
    font-weight: bold;
    margin-bottom: 2px;
}

.info-text .value {
    display: block;
    color: #666;
}

/* Loading and Modals */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    display: none;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid white;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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

#loading-overlay p {
    color: white;
    font-size: 18px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    display: none;
}

.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 320px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 15px;
}

.modal-content p {
    margin-bottom: 20px;
}

.modal-content button {
    padding: 10px 30px;
    background-color: #e00;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
}

/* Info Panel Collapsed State */
#info-panel.collapsed {
    height: 50px;
}

#info-panel.collapsed .panel-content {
    display: none;
}

#info-panel.collapsed .arrow-up {
    display: none;
}

#info-panel:not(.collapsed) .arrow-down {
    display: none;
}

/* Media Queries */
@media (min-height: 700px) {
    #map-container {
        height: 65%;
    }
    
    #info-panel {
        height: 35%;
    }
}

@media (min-height: 800px) {
    #map-container {
        height: 70%;
    }
    
    #info-panel {
        height: 30%;
    }
}

/* Map customization */
.gm-style-iw {
    max-width: 250px !important;
}

/* Fuel Section Styles - da aggiungere a xkey-mobile.css */

/* Fuel Chart Container (45% altezza) */
#fuel-chart-container {
    width: 100%;
    height: 45%;
    position: relative;
    background-color: #fff;
    border-bottom: 1px solid #eee;
}

#fuelChart {
    width: 100%;
    height: 100%;
}

.fuel-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    display: none;
}

.fuel-loading-overlay.active {
    display: flex;
}

/* Date Ticker (10% altezza) */
.date-ticker {
    width: 100%;
    height: 10%;
    min-height: 50px;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    overflow: hidden;
    position: relative;
}

.date-list {
    display: flex;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
    -webkit-overflow-scrolling: touch; /* iOS smooth scrolling */
    scroll-behavior: smooth;
}

.date-list::-webkit-scrollbar {
    display: none; /* Nasconde scrollbar su WebKit */
}

.date-item {
    flex-shrink: 0;
    min-width: 80px;
    height: 40px;
    margin: 0 3px;
    border-radius: 20px;
    background-color: #ddd;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.date-item:active {
    transform: scale(0.95);
}

.date-item.selected {
    background-color: #e00;
    color: white;
    box-shadow: 0 2px 4px rgba(224, 0, 0, 0.3);
}

.date-item.loading {
    background-color: #e00;
    color: white;
    position: relative;
    overflow: hidden;
}

.date-item.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Fuel Info Panel (35% altezza) */
.fuel-info-panel {
    width: 100%;
    height: 35%;
    background-color: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fuel-info-panel .panel-header {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    background-color: #f8f8f8;
}

.fuel-info-panel .panel-header h2 {
    font-size: 16px;
    margin: 0;
    color: #333;
}

.fuel-info-panel .panel-content {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
}

.fuel-info-panel .info-item {
    display: flex;
    margin-bottom: 12px;
    align-items: flex-start;
}

.fuel-info-panel .info-item:last-child {
    margin-bottom: 0;
}

.fuel-info-panel .info-item i {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    margin-top: 2px;
    text-align: center;
    color: #e00;
    font-size: 16px;
}

.fuel-info-panel .info-text {
    flex-grow: 1;
}

.fuel-info-panel .info-text .label {
    display: block;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 2px;
    color: #333;
}

.fuel-info-panel .info-text .value {
    display: block;
    color: #666;
    font-size: 14px;
}

/* Responsive adjustments */
@media (min-height: 700px) {
    #fuel-chart-container {
        height: 50%;
    }
    
    .fuel-info-panel {
        height: 30%;
    }
    
    .date-ticker {
        height: 8%;
    }
}

@media (min-height: 800px) {
    #fuel-chart-container {
        height: 55%;
    }
    
    .fuel-info-panel {
        height: 25%;
    }
}

/* Messaggi di stato nel grafico */
.no-data-message,
.chart-error-message {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    color: #666;
    padding: 20px;
}

.no-data-message i,
.chart-error-message i {
    font-size: 48px;
    margin-bottom: 15px;
    color: #ccc;
}

.chart-error-message i {
    color: #e00;
}

.no-data-message h3,
.chart-error-message h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: #333;
}

.no-data-message p,
.chart-error-message p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

/* Elemento fuel cliccabile nel tracker-section */
#fuel-info.clickable {
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 4px;
    margin: -5px;
    padding: 5px;
}

#fuel-info.clickable:hover {
    background-color: rgba(224, 0, 0, 0.1);
}

#fuel-info.clickable:active {
    background-color: rgba(224, 0, 0, 0.2);
    transform: scale(0.98);
}

#fuel-info.clickable .info-text .value::after {
    content: ' 📊';
    font-size: 12px;
    margin-left: 5px;
}

/* CSS aggiuntivo per il grafico carburante + velocità */
/* Da aggiungere a xkey-mobile.css */

/* Miglioramenti per la legenda del grafico */
.fuel-chart-container canvas {
    max-height: calc(100% - 40px); /* Spazio per la legenda */
}

/* Assicura che l'elemento velocità sia sempre visibile nel panel info */
.fuel-info-panel .info-item[data-info="speed"] {
    display: flex !important;
}

/* Migliora la visualizzazione della legenda su mobile */
#fuelChart {
    font-size: 12px;
}

/* Stili per messaggi di stato migliorati */
.no-data-message,
.chart-error-message {
    font-size: 14px;
}

.no-data-message i,
.chart-error-message i {
    font-size: 42px;
    margin-bottom: 12px;
}

/* Responsive adjustments per la legenda */
@media (max-width: 480px) {
    #fuelChart {
        font-size: 10px;
    }
    
    .fuel-info-panel .info-text .label {
        font-size: 13px;
    }
    
    .fuel-info-panel .info-text .value {
        font-size: 13px;
    }
}

/* Stili per distinguere meglio i due dataset nella legenda */
.chartjs-legend {
    margin-bottom: 10px;
}

.chartjs-legend li {
    margin: 0 10px;
}
