:root{
  --bg:#05060a;
  --card:#141620;
  --border:#262a38;
  --text:#f4f5f8;
  --muted:#9a9fb0;
  --accent:#ff6a00;
  --accent-soft:rgba(255,106,0,.12);
  --danger:#e53935;
  --danger-soft:rgba(229,57,53,.12);
}
*{box-sizing:border-box;}
body{
  margin:0;
  font:14px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  background:radial-gradient(circle at top,#1b2030 0,#05060a 55%);
  color:var(--text);
  height:100%;
  overflow:hidden;
}
html{
  height:100%;
  overflow:hidden;
}
.app{
  width:100%;
  max-width:100%;
  margin:0 auto;
  padding:10px 10px 16px;
  height:100%;
  display:flex;
  flex-direction:column;
}
main{
  flex:1;
  display:flex;
  flex-direction:column;
  min-height:0;
  overflow:hidden;
}
.app-header h1{
  margin:0;
  font-size:1.6rem;
}
.global-status{padding:4px 8px;min-height:1.2rem;}

.subtitle{
  margin:2px 0 10px;
  color:var(--muted);
  font-size:.9rem;
}
.tabs{
  display:flex;
  gap:4px;
  border-bottom:1px solid var(--border);
}
.tab-button{
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.06);
  background:rgba(10,12,20,0.95);
  color:var(--muted);
  padding:6px 14px;
  cursor:pointer;
  font-size:.9rem;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  min-width:38px;
  height:38px;
  box-shadow:none;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
}
.tab-button:hover{
  border-color:var(--accent-soft);
  color:var(--text);
  background:rgba(18,20,30,1);
  box-shadow:none;
}
.tab-button.active{
  background:var(--accent);
  border-color:transparent;
  color:#07131e;
  box-shadow:none;
}
.tab-panel{
  display:none;
  padding-top:10px;
}
.tab-panel.active{
  display:flex;
  flex-direction:column;
  gap:12px;
  flex:1;
  min-height:0;
}
.card{
  background:radial-gradient(circle at top left, rgba(255,255,255,0.02), var(--card));
  border:1px solid rgba(255,255,255,0.03);
  border-radius:18px;
  padding:14px 16px;
  margin-bottom:14px;
  box-shadow:0 18px 45px rgba(0,0,0,0.55);
}
.card h2{
  margin:0 0 6px;
  font-size:1rem;
}
h3{
  margin:0 0 4px;
  font-size:.9rem;
}
.muted{color:var(--muted);}
.small{font-size:.8rem;}

.field-row{
  margin-top:8px;
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:flex-end;
}
.field-row label{
  flex:1;
  display:flex;
  flex-direction:column;
  gap:4px;
  font-size:.8rem;
}
.field-row input{
  width:100%;
  background:#070812;
  color:var(--text);
  border:1px solid var(--border);
  border-radius:9px;
  padding:6px 8px;
  font-size:.85rem;
}
.btn{
  border-radius:999px;
  border:1px solid var(--border);
  background:#10121b;
  color:var(--text);
  padding:7px 13px;
  font-size:.8rem;
  cursor:pointer;
  box-shadow:none;
}
.btn.primary{
  border-color:transparent;
  background:var(--accent);
  color:#fff;
  box-shadow:none;
}
.btn.secondary{
  border-color:#2563eb;
  background:rgba(37,99,235,.12);
}
.btn.danger{
  border-color:transparent;
  background:var(--danger);
  color:#fff;
  box-shadow:none;
}

/* legacy connection styles neutralised by new design */ 
.connection-bar{}
.conn-group{}
.conn-pill{
  border-radius:999px;
  padding:4px 10px;
  font-size:.8rem;
  cursor:pointer;
}
.conn-pill.on{
  /* state handled by .btn-connect.on */
}
.conn-label{
  font-size:.8rem;
  color:var(--muted);
}

.grid.metrics-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
  gap:8px;
}
.metric-card{
  text-align:left;
}
.metric-value{
  font-size:1.6rem;
  font-weight:600;
}
.metric-unit{
  font-size:.75rem;
  color:var(--muted);
}

.chart-wrapper{
  position:relative;
  height:220px;   /* altezza fissa per evitare grafici giganti */
}
.chart-wrapper canvas{
  width:100% !important;
  height:100% !important;
}

.planned-table-wrapper{
  max-height:260px;
  overflow:auto;
}
.planned-table{
  width:100%;
  border-collapse:collapse;
  font-size:.8rem;
}
.planned-table th,
.planned-table td{
  border-bottom:1px solid var(--border);
  padding:4px 6px;
}
.planned-table th{
  text-align:left;
  color:var(--muted);
  position:sticky;
  top:0;
  background:var(--card);
}
.planned-table tr:hover{
  background:rgba(255,255,255,.04);
}

.debug-log-wrapper{
  max-height:220px;
  overflow:auto;
  background:#05060a;
  border-radius:8px;
  border:1px solid var(--border);
  padding:6px 8px;
  margin-top:6px;
}
#debugLog{
  margin:0;
  font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size:11px;
  white-space:pre-wrap;
}

.chart-wrapper.workout-chart{
  height:100%;
  min-height:140px;
}

.workout-main-card{
  flex:1;
  display:flex;
  flex-direction:column;
  min-height:0;
}

.workout-main-card .chart-wrapper{
  flex:1;
  height:auto;
}

.planned-filters{
  display:flex;
  flex-wrap:wrap;
  gap:0.5rem;
  margin-bottom:0.75rem;
}
.planned-filters .planned-filter{
  cursor:pointer;
}
.recovery-grid{
  gap:0.75rem;
  margin-top:0.5rem;
}
.planned-legend{
  margin-top:0.75rem;
}

.legend-item{
  display:inline-flex;
  align-items:center;
  gap:0.25rem;
  margin-right:0.5rem;
}
.legend-color{
  width:12px;
  height:12px;
  border-radius:2px;
  display:inline-block;
}


/* Recovery & semaforo */
.recovery-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
  gap:0.75rem;
  margin-top:0.5rem;
}

.traffic-row{
  display:flex;
  align-items:center;
  gap:1rem;
  margin-top:0.75rem;
}

.traffic-dot{
  width:1.6rem;
  height:1.6rem;
  border-radius:50%;
  background:#555;
  box-shadow:0 0 0 1px rgba(255,255,255,0.08);
}

.traffic-dot-green{
  background:#4caf50;
}

.traffic-dot-yellow{
  background:#ffc107;
}

.traffic-dot-red{
  background:#f44336;
}

.traffic-dot-grey{
  background:#555;
}

.traffic-label{
  font-weight:600;
  margin-bottom:0.15rem;
}

.traffic-reason{
  max-width:32rem;
}


.app-header{
  padding:0.5rem 1rem 0.5rem;
}
.app-header-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:1rem;
}
.app-title-block h1{
  margin:0;
}
.app-title-block .subtitle{
  margin:0.15rem 0 0;
}
.tabs-centered{
  display:flex;
  justify-content:center;
  gap:0.5rem;
  margin-top:0.9rem;
  padding:0.35rem 0.65rem;
  border-radius:999px;
  background:radial-gradient(circle at top, rgba(255,255,255,0.07), rgba(10,13,24,0.96));
  box-shadow:0 20px 45px rgba(0,0,0,0.65);
  backdrop-filter:blur(18px);
}
.icon-gear{
  border:none;
  background:rgba(20,22,32,0.9);
  color:#f4f5f8;
  border-radius:999px;
  width:2.2rem;
  height:2.2rem;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  box-shadow:0 0 0 1px rgba(255,255,255,0.06);
}
.icon-gear:hover{
  box-shadow:0 0 10px rgba(255,255,255,0.15);
}

/* UI uplift v2 */
body{font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;}
.app-header h1{letter-spacing:.2px}
.tab-button{
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.06);
  background:rgba(10,12,20,0.95);
  color:var(--muted);
  padding:6px 14px;
  cursor:pointer;
  font-size:.9rem;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  min-width:38px;
  height:38px;
  box-shadow:none;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
}
.tab-button.active{
  background:var(--accent);
  border-color:transparent;
  color:#07131e;
  box-shadow:none;
}
.card{backdrop-filter:blur(6px);box-shadow:0 8px 24px rgba(0,0,0,.25);} 
.metric-card h3{font-weight:600}
.legend-color{box-shadow:0 0 0 1px rgba(0,0,0,.35)}

/* Connessione tab status colors */
.tab-button.connection-tab.status-red{
  border-color:rgba(239,68,68,.7);
}
.tab-button.connection-tab.status-yellow{
  border-color:rgba(234,179,8,.8);
}
.tab-button.connection-tab.status-green{
  border-color:rgba(34,197,94,.8);
}

/* Mobile layout tweaks */
@media (max-width: 768px){
  .app{
    padding:8px 6px 16px;
  }
  .app-header{
    padding:0.5rem 0.75rem 0.25rem;
  }
  .app-title-block h1{
    font-size:1.2rem;
  }
  .app-title-block .subtitle{
    display:none;
  }
  .tabs-centered{
    margin-top:0.4rem;
    overflow-x:auto;
    justify-content:flex-start;
  }
  .tab-button{
  border-radius:14px;
  border:1px solid rgba(255,255,255,0.06);
  background:rgba(10,12,20,0.95);
  color:var(--muted);
  padding:6px 14px;
  cursor:pointer;
  font-size:.9rem;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  min-width:38px;
  height:38px;
  box-shadow:none;
  transition:background .15s ease, color .15s ease, border-color .15s ease;
}

  /* Workout actions compact layout */
  .workout-actions{
    display:grid;
    grid-template-columns:auto 1fr auto auto auto;
    grid-column-gap:4px;
    align-items:center;
    margin-top:6px;
  }
  .btn-main{
    justify-self:stretch;
    display:flex;
    align-items:center;
    justify-content:center;
    gap:4px;
    padding:6px 8px;
  }
  .btn-main .btn-label{
    font-size:0.85rem;
    white-space:nowrap;
  }
  .btn-circle{
    width:32px;
    height:32px;
    padding:0;
    border-radius:999px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:0.8rem;
  }
  .btn-ghost{
    width:28px;
    height:28px;
    padding:0;
    border-radius:999px;
    font-size:0.75rem;
    background:transparent;
  }

  /* Metrics grid more compact */
  .grid.metrics-grid{
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:4px;
    margin-top:6px;
  }
  .metric-card{
    padding:6px 6px;
  }
  .metric-card h3{
    font-size:0.7rem;
  }
  .metric-value{
    font-size:1.1rem;
  }
  .metric-unit{
    font-size:0.65rem;
  }

  /* Chart height reduced */
  .chart-wrapper.workout-chart{
    height:170px;
  }
}

.planned-actions{
  display:flex;
  justify-content:flex-end;
  gap:4px;
}
.planned-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  padding:4px 8px;
  min-width:28px;
}


.workout-controls-card{
  margin-top:10px;
}
.workout-controls-card .field-row{
  justify-content:center;
}


/* === New connection cards design === */
.connection-list{
  display:flex;
  flex-direction:column;
  gap:10px;
}
.connection-card{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.connection-main{
  display:flex;
  align-items:center;
  gap:12px;
}
.connection-icon{
  width:44px;
  height:44px;
  border-radius:16px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:1.4rem;
  background:rgba(255,255,255,0.03);
  box-shadow:none;
}
.connection-title{
  font-weight:600;
  margin-bottom:2px;
}
.connection-status{
  font-size:.8rem;
  color:var(--muted);
}
.btn-connect{
  border-radius:999px;
  padding:6px 18px;
  background:var(--accent);
  border:none;
  color:#f9fafb;
  font-weight:600;
  font-size:.85rem;
  box-shadow:none;
}
.btn-connect:hover{
  opacity:0.9;
}
.btn-connect.on{
  background:#16a34a;
}


/* Material Symbols icon font */
.material-symbols-rounded{
  font-variation-settings:
    "FILL" 1,
    "wght" 500,
    "GRAD" 0,
    "opsz" 24;
  font-size:20px;
  line-height:1;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

/* Specific sizing for contexts */
.tab-button .material-symbols-rounded{
  font-size:21px;
}
.connection-icon .material-symbols-rounded{
  font-size:24px;
}


/* Sporty tab icon colors */
.tab-button .material-symbols-rounded{
  color:#8ea4ff;
}
.tab-btn-connections .material-symbols-rounded{
  color:#ffb347;
}
.tab-btn-workout .material-symbols-rounded{
  color:#ff6a00;
}
.tab-btn-planned .material-symbols-rounded{
  color:#ffd447;
}
.tab-btn-recovery .material-symbols-rounded{
  color:#40e0d0;
}
.tab-btn-config .material-symbols-rounded{
  color:#e5e7eb;
}
.tab-button.active .material-symbols-rounded{
  color:#fff;
}

.planned-btn .material-symbols-rounded{
  font-size:18px;
}

.btn-icon .material-symbols-rounded{
  font-size:18px;
}
