:root {
  /* Braun "Cream White" Vintage Hardware Palette */
  --bg-color: #e8e5dc;          /* Chasis plástico cálido/hueso oscuro */
  --widget-bg: #f5f2eb;         /* Paneles de widgets blanco roto / crema */
  --text-main: #111111;         /* Negro azabache para máximo contraste */
  --text-muted: #8e8e93;        /* Gris piedra */
  --accent-orange: #AF2E1B;     /* Deep Red DR05 para Críticos */
  --accent-yellow: #CC6324;     /* Burnt Orange DR05 para Warnings */
  --accent-green: #3B4B59;      /* Slate DR05 para Normal/OK */
  --border-color: #e0e0e0;      /* Remates finos */

  /* Typography */
  --font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-weight-light: 300;
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;

  /* Layout */
  --gap: 24px;
  --widget-padding: 32px;
  --border-radius: 12px;        /* Bordes ligeramente menos redondeados para emular cajas clásicas */
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 380px 1fr; /* Columna más esbelta para acompañar el acercamiento */
  grid-template-rows: auto 1fr 1fr; /* Less rows since Clock and Weather are unified */
  gap: var(--gap);
  width: 95vw;
  max-width: 1400px;
  height: 90vh;
}

/* Widgets */
.widget {
  background-color: var(--widget-bg);
  border-radius: var(--border-radius);
  padding: var(--widget-padding);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05); /* Minimal shadow */
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

@media (prefers-color-scheme: dark) {
  .widget {
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  }
}

:root {
  --font-size-base: 14px;
}
/* Escala para tablets */
@media (max-width: 1024px) {
  :root {
    --font-size-base: 12px;
  }
}

.widget-title {
  font-size: var(--font-size-base);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* Entorno Local (Reloj + Clima Unidos) */
.time-weather-widget {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  flex-direction: row;
  justify-content: flex-start; /* Los agrupamos a la izquierda */
  gap: 32px;                   /* Mucho más concentrados, unidad visual monolítica */
  align-items: flex-start;     /* Forzamos que se anclen arriba, evitando desniveles por diferentes alturas totales */
  text-align: left;
}

.time-block, .weather-block {
  display: flex;
  flex-direction: column;
}

.time-display, .temperature {
  font-size: 3.5rem; /* Ajustado para caber perfectamente par a par */
  font-weight: var(--font-weight-light);
  line-height: 1;
  letter-spacing: -2px;
}

.date-display, .condition {
  font-size: 1.1rem; /* Un pelo más pequeña (bajamos de 1.25rem) para no competir con el dato principal */
  color: var(--text-muted);
  font-weight: var(--font-weight-medium);
  margin-top: 8px;
  text-transform: capitalize;
}

.weather-icon {
  width: 48px;
  height: 48px;
  color: var(--text-main);
  margin-bottom: 12px;
}

/* Calendario */
.calendar-widget {
  grid-column: 1 / 2;
  grid-row: 2 / 3; /* Shifted UP */
  overflow: hidden;
}

/* Tareas */
.tasks-widget {
  grid-column: 1 / 2;
  grid-row: 3 / 4; /* Shifted UP */
  overflow: hidden;
}

.events-list, .tasks-list {
  list-style: none;
  overflow-y: auto;
  padding-right: 8px;
}

.event-item, .task-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.event-item:last-child, .task-item:last-child {
  border-bottom: none;
}

.event-title {
  font-size: 1rem;
  font-weight: var(--font-weight-medium);
}

.event-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 16px;
}

/* Checkbox estilo Dieter Rams para Tareas */
.task-item {
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.view.active {
  display: flex !important;
  animation: fadeIn 0.3s ease;
}

.view.hidden {
  display: none !important;
}

/* Elevación de seguridad */
#details-view {
  z-index: 1000;
  position: relative;
}

.check-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.task-item.completed {
  opacity: 0.5;
}

.task-item.completed .check-circle {
  background-color: var(--text-muted);
  border-color: var(--text-muted);
  box-shadow: inset 0 0 0 2px var(--widget-bg);
}

.task-item.completed .task-title {
  text-decoration: line-through;
}

.task-title {
  font-size: 0.95rem;
  font-weight: var(--font-weight-medium);
  transition: all 0.2s ease;
}

/* Servicios Online - Matrix Layout */
.services-widget {
  grid-column: 2 / 3; /* Columna Derecha Completa */
  grid-row: 1 / 4; /* Span entirely */
  overflow: hidden;
}

/* Monitor Header (Button + LCD) */
.monitor-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.btn-back {
  background-color: var(--accent-green); /* Color pizarra DR05 */
  color: #f5f2eb;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: none; /* Solo en detalles */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.btn-details {
  background-color: var(--accent-green);
  color: #f5f2eb;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex; /* Visible desde el principio */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.btn-back svg, .btn-details svg {
  width: 18px;
  height: 18px;
  stroke: #f5f2eb;
}

.btn-back:hover, .btn-details:hover {
  background-color: var(--text-main);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.btn-back:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.system-details-display {
  flex: 1; /* Ocupa el resto del espacio */
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: monospace;
  font-size: 0.9rem;
  letter-spacing: -0.5px;
  color: var(--text-main);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
  cursor: pointer;
  transition: background-color 0.2s;
}

.system-details-display:hover {
  background-color: #d1bda9; /* Ligeramente oscurecido para UX */
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.05);
}

.sys-display-title {
  text-transform: uppercase;
}

.sys-display-status {
  text-transform: uppercase;
  font-weight: bold;
}

.sys-display-status.online { color: var(--text-muted); }
.sys-display-status.critical { color: var(--accent-orange); }
.sys-display-status.warning { color: var(--accent-yellow); }

.services-container {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.services-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-title {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

/* Speaker Grill Matrix */
.group-matrix {
  display: flex;
  flex-wrap: wrap;
  gap: 12px; /* Un poco más de aire entre agujeros para permitir el escalado */
  padding: 8px 4px; /* Espacio para que el brillo y el borde no se corten */
  overflow: visible;
}

/* Minimalist Button / Hole (Emulando perforaciones SK4 Snow White) */
.service-chip {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  background-color: #3B4B59; /* Slate Blue/Gray DR05 (Estado Normal / Buen Estado) */
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.7); /* Relieve cóncavo profundizado para agujero oscuro */
  transition: transform 0.1s ease-in-out, box-shadow 0.2s, background-color 0.2s;
}

.service-chip:hover {
  transform: scale(1.2);
}

.service-chip.active {
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.15), 0 0 0 2px var(--text-muted);
}

.status-indicator {
  /* Retain class definitions but move logic purely to the chip background and glow */
  display: none; 
}

/* Colors injected directly to the hole/chip when it is NOT purely online */
.service-chip.critical {
  background-color: var(--accent-orange); /* Deep Red DR05 */
  box-shadow: 0 0 8px rgba(175, 46, 27, 0.7), inset 0 1px 2px rgba(0,0,0,0.2);
}

.service-chip.warning {
  background-color: var(--accent-yellow); /* Burnt Orange DR05 */
  box-shadow: 0 0 8px rgba(204, 99, 36, 0.7), inset 0 1px 2px rgba(0,0,0,0.2);
}

/* --------------------------------------
   Module Swap / Transition Mechanics
   -------------------------------------- */
.view-portal {
  position: relative;
  flex: 1; /* Ocupa todo el alto sobrante */
  display: flex;
  flex-direction: column;
}

#details-view {
  overflow-y: auto;
  max-height: 100vh;
  padding-bottom: 2rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

#details-view::-webkit-scrollbar {
  width: 4px;
}

#details-view::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s ease-in-out, visibility 0.3s;
  display: flex;
  flex-direction: column;
}

.view.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.view.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* --------------------------------------
   Details View Aesthetics
   -------------------------------------- */
.details-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}

.btn-return {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: monospace;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-return:hover {
  background-color: var(--text-main);
  color: var(--bg-color);
}

.details-metrics {
  display: flex;
  flex-direction: column;
  gap: 8px; /* Reducido */
  margin-bottom: 16px; /* Reducido */
}

.details-metrics-inline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 4px;
}

.metric-col {
  display: flex;
  flex-direction: column;
  flex: 1;
  align-items: center;
}

.dial-container {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto;
}

.dial-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* Start at 12 o'clock */
}

.dial-bg {
  fill: none;
  stroke: rgba(59, 75, 89, 0.1);
  stroke-width: 3;
}

.dial-ring {
  fill: none;
  stroke: var(--accent-green);
  stroke-width: 3;
  stroke-dasharray: 251.327; /* 2 * PI * 40 radius */
  stroke-dashoffset: 251.327; 
  transition: stroke-dashoffset 1s cubic-bezier(0.2, 0.8, 0.2, 1), stroke 0.4s ease;
  stroke-linecap: butt; /* Braun purism, flat ends */
}

.dial-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.metric-label {
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--text-main);
  text-align: center;
  font-weight: var(--font-weight-medium);
}

.metric-subval {
  font-size: 0.70rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.history-panel {
  display: flex;
  flex-direction: column;
  flex-grow: 1; /* Ocupa todo el alto visible debajo de métricas */
  gap: 12px;
}

.history-header {
  display: flex;
  justify-content: flex-end; /* Alineado a la derecha compensando visualmente */
  padding: 0 4px;
}

.time-selector {
  display: flex;
  gap: 20px;
}

.time-btn {
  background: none;
  border: none;
  font-family: var(--font-family);
  font-size: 0.65rem;
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: 1px;
  position: relative;
  padding-bottom: 4px;
  transition: color 0.2s;
}

.time-btn.active {
  color: var(--text-main);
}

.time-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 3px;
  background-color: var(--accent-orange); /* Punto indicador estilo Braun */
  border-radius: 50%;
}

.time-btn:hover {
  color: var(--text-main);
}

.mini-charts-wrapper {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: 6px; /* Gap mínimo industrial */
}

.mini-chart-block {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.mini-chart-header {
  font-size: 0.65rem;
  letter-spacing: 2px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-weight: var(--font-weight-medium);
  margin-bottom: 2px;
}

.mini-chart-body {
  background-color: var(--widget-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px; 
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
  height: 110px; /* Recuperamos altura para legibilidad */
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.mini-chart-axis {
  position: relative;
  width: 50px; /* Ejes extra anchos para máxima legibilidad industrial */
  height: 100%;
  pointer-events: none;
  background-color: rgba(59, 75, 89, 0.02);
}

.left-axis { border-right: 1px solid rgba(59, 75, 89, 0.05); }
.right-axis { border-left: 1px solid rgba(59, 75, 89, 0.05); }

.mini-chart-axis span {
  position: absolute;
  font-size: 0.50rem;
  color: var(--text-muted);
  line-height: 1;
}
.left-axis span { left: 4px; }
.right-axis span { right: 4px; }

/* Gráficas SVG estéticas finas */
.mini-chart-svg-container {
  flex-grow: 1;
  position: relative;
  height: 100%;
  overflow: hidden; /* Asegura un clip perfecto para la gráfica pura */
}

.mini-chart-svg-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mini-chart-x-axis {
  display: flex;
  justify-content: space-between;
  padding: 4px 0 0 0;
  font-size: 0.55rem;
  color: var(--text-muted);
  font-family: monospace;
  letter-spacing: 0.5px;
}

/* Responsiveness for portrait orientation */
@media (max-aspect-ratio: 1/1) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr 1fr;
    height: 95vh;
  }
  
  .clock-widget, .weather-widget, .calendar-widget, .services-widget {
    grid-column: 1 / 2;
  }
  .weather-widget {
    grid-row: 2 / 3;
  }
  .calendar-widget {
    grid-row: 3 / 4;
  }
  .services-widget {
    grid-row: 4 / 5;
  }
}
