/**
 * Main stylesheet - Dark Theme Edition (Simplified)
 */

/* Import Montserrat Font */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
  /* Colors */
  --color-background: #0f172a;
  --color-surface: #1e293b;
  --color-text: #e2e8f0;
  --color-text-secondary: #94a3b8;
  --color-primary: #0ea5e9;
  --color-primary-hover: #0284c7;
  --color-border: #334155;
  
  /* Typography */
  --font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  
  /* Spacing */
  --space-2: 0.5rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  
  /* Border Radius */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  
  /* Transitions */
  --transition: all 0.3s ease;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-family);
  background-color: var(--color-background);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
}

/* Utilities */
.text-center { text-align: center; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

/* Loading Spinner */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Alpine.js - Previene flash of unstyled content */
[x-cloak] {
  display: none !important;
}

/* Assicura che il body occupi tutto lo spazio */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

/* ========== APP LAYOUT ========== */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Previene scroll */
}

/* ========== HEADER TV - Compatto in alto ========== */
.mobile-header.tv-mode {
  padding: 1rem 2rem;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 2px solid #334155;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.mobile-header.tv-mode h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ========== LAYOUT TV (4 DATASET IN GRIGLIA) ========== */
.tv-layout {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 1.5rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  height: calc(100vh - 80px); /* Sottrae l'altezza dell'header */
  overflow: hidden;
  position: relative;
}

.tv-center-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7); 
  width: 70px;          
  height: 70px;        
  background: linear-gradient(135deg, #ee6c09 0%, #eea509 100%);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px rgba(233, 182, 14, 0.6),
              0 0 80px rgba(14, 165, 233, 0.3);
  z-index: 100;
  border: 4px solid rgba(255, 255, 255, 0.2);
  animation: pulse-glow 3.14s ease-in-out infinite;
}

.tv-center-badge-title {
  font-size: 0.5rem;     
  font-weight: 700;
  color: white;
  text-align: center;
  line-height: 1.2;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  margin-bottom: 0.25rem;
}

.tv-center-badge-subtitle {
  font-size: 0.7rem;   
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  text-align: center;
}


@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 0 40px rgba(233, 193, 14, 0.6),
                0 0 80px rgba(229, 233, 14, 0.3);
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    box-shadow: 0 0 60px rgba(233, 145, 14, 0.8),
                0 0 120px rgba(229, 233, 14, 0.4);
    transform: translate(-50%, -50%) scale(1.05);
  }
}

/* Card dataset per TV */
.chart-card-tv {
  background: rgba(30, 41, 59, 0.95);
  border: 2px solid #ee6c0975;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chart-card-tv:hover {
  border-color: #0ea5e9;
  box-shadow: 0 10px 40px rgba(14, 165, 233, 0.2);
  transform: translateY(-2px);
}

.chart-card-tv canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Canvas wrapper - occupa tutto lo spazio disponibile */
.chart-canvas-wrapper {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0; /* Importante per flex */
}

/* Header della card con nome dataset */
.chart-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.chart-title {
  font-size: 1.125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Info dataset compatte */
.chart-card-info {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}

/* BADGE UTILIZZO */
.usage-badge {
  background: #0ea5e9;
  color: white;
  padding: 0.375rem 0.875rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 50px;
  text-align: center;
}

.usage-badge.highlight {
  background: #ff7b00;
  box-shadow: 0 0 20px rgba(249, 115, 22, 0.5);
  animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* ========== LAYOUT MOBILE ========== */
.mobile-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

/* Intestazione mobile */
.mobile-header {
  padding: 1.5rem;
  background: #1e293b;
  border-bottom: 2px solid #ee6b09;
  text-align: center;
}

.mobile-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.mobile-header a {
  color: #ee6c09;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  border-bottom: 1px solid transparent;
}

.mobile-header a:hover {
  color: var(--color-primary-hover);
  border-bottom-color: var(--color-primary-hover);
}

/* Contenitore principale mobile */
.mobile-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
}

/* Sezione upper: Grid di 4 dataset selezionabili */
.dataset-grid-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  flex: 0;
}

/* Card dataset selezionabile */
.dataset-card {
  background: #1e293b;
  border: 2px solid #ee6b09;
  border-radius: 10px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  position: relative;
}

.dataset-card:hover {
  border-color: #cecece;
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.2);
}

.dataset-card.active {
  background: linear-gradient(135deg, #ee6b09 0%, #ee7809 100%);
  border-color: #cecece;
  color: white;
}

.dataset-card-icon {
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dataset-card-icon svg {
  width: 2rem;
  height: 2rem;
  stroke: currentColor; /* Eredita il colore dal parent */
}

.dataset-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.dataset-card-unit {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Sezione lower: Chart del dataset selezionato */
.chart-display-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 250px;
}

.chart-display-title {
  font-weight: 600;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #ee6b09;
}

.chart-display-container {
  flex: 1;
  position: relative;
}

#chart-container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ========== MESSAGGI DI ERRORE ========== */
.error-notification {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #dc2626;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(220, 38, 38, 0.3);
  z-index: 1000;
  animation: slideDown 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.error-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 1;
}

.app-footer {
  padding: 1rem 2rem;
  background: #1e293b;
  border-top: 1px solid #ee6c0986;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.app-footer p {
  margin: 0;
  line-height: 1.4;
}
.app-footer a {
  color: #ee6c09;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  border-bottom: 1px solid transparent;
}

.app-footer a:hover {
  color: var(--color-primary-hover);
  border-bottom-color: var(--color-primary-hover);
}

.app-footer a:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}


@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

/* ========== LOADER/LOADING SPINNER ========== */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ========== RESPONSIVE: Tablet e Desktop ========== */
@media (min-width: 768px) {
  .tv-layout {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    padding: 1.5rem;
  }
  
  .dataset-grid-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ========== RESPONSIVE: Grande schermo (TV) - 16:9 ========== */
@media (min-width: 1200px) {
  .tv-layout {
    height: calc(100vh - 80px);
    gap: 1.5rem;
    padding: 1.5rem;
  }
  
  .chart-card-tv {
    padding: 1.25rem;
  }
  
  .tv-center-badge {
    width: 110px;
    height: 110px;
  }
  
  .tv-center-badge-title {
    font-size: 1.1rem;
  }
}

/* ========== FULLSCREEN TV MODE (F11) ========== */
@media (min-width: 1920px) {
  .mobile-header.tv-mode {
    padding: 1.25rem 2.5rem;
  }
  
  .mobile-header.tv-mode h1 {
    font-size: 2rem;
  }
  
  .tv-layout {
    gap: 2rem;
    padding: 2rem;
  }
  
  .chart-card-tv {
    padding: 1.5rem;
  }
  
  .chart-title {
    font-size: 1.25rem;
  }
  
  .tv-center-badge {
    width: 120px;
    height: 120px;
  }
  
  .tv-center-badge-title {
    font-size: 1rem;
  }
  
  .tv-center-badge-subtitle {
    font-size: 1rem;
  }
}