/* V6 Phase 3 — responsive hardening.
   This layer only changes presentation. It must not change coaching meaning or data semantics. */

html,body{max-width:100%;overflow-x:clip}
img,svg,canvas{max-width:100%}
.shell,.workspace,.screen,.live-slot,.live-grid-12,.live-development-grid,.live-two,.three-grid,.surface,.live-panel,.echart-card,.live-chart-card,.live-map-card{min-width:0}

/* Tablet: retain the analytical desktop hierarchy, but reduce density before collapsing. */
@media(max-width:1280px){
  .workspace{padding-left:22px;padding-right:22px}
  .live-kpi-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
  .development-kpis{grid-template-columns:repeat(2,minmax(0,1fr))}
  .live-two{grid-template-columns:minmax(0,1.5fr) minmax(280px,1fr)}
  .live-span-8,.live-span-7{grid-column:span 7}
  .live-span-5,.live-span-4{grid-column:span 5}
}

@media(max-width:1080px){
  .shell{grid-template-columns:204px minmax(0,1fr)}
  .sidebar{padding-left:10px;padding-right:10px}
  .brand strong{font-size:17px}
  .workspace{padding:22px 18px 48px}
  .page-head h1{font-size:32px}
  .live-two{grid-template-columns:1fr}
  .live-span-8,.live-span-7,.live-span-6,.live-span-5,.live-span-4{grid-column:span 12}
  .echart,.live-chart{height:290px}
  .live-map{height:290px}
}

/* Mobile shell. Sidebar disappears; safe-area-aware bottom navigation becomes primary. */
@media(max-width:760px){
  html{scroll-padding-bottom:calc(82px + env(safe-area-inset-bottom,0px))}
  body{padding-bottom:env(safe-area-inset-bottom,0px)}
  .shell{display:block;min-height:100dvh}
  .sidebar{display:none}
  .workspace{max-width:none;padding:calc(14px + env(safe-area-inset-top,0px)) 12px calc(94px + env(safe-area-inset-bottom,0px))}
  .screen,.live-slot{width:100%;max-width:100%}
  .prototype-badge{display:none}

  .page-head{display:grid;grid-template-columns:1fr;gap:10px;padding-top:0;margin-bottom:14px}
  .page-head h1{font-size:clamp(27px,8vw,32px);line-height:1.03;overflow-wrap:anywhere}
  .subline{font-size:12px;line-height:1.45}
  .live-head-actions{display:flex;flex-direction:row;align-items:center;width:100%;overflow-x:auto;padding-bottom:2px}
  .live-status,.quiet-btn{flex:0 0 auto}
  .ride-select{max-width:none;width:100%;min-height:44px}

  /* Load strip: number and delta remain readable while the 14-day strip gets a full row. */
  .load-strip{grid-template-columns:minmax(0,1fr) auto;gap:10px 16px;padding:13px 14px;margin-bottom:12px}
  .load-strip>div:first-child{grid-column:1}
  .delta{grid-column:2;text-align:right}
  .mini-bars{grid-column:1/-1;order:3;width:100%;height:46px;gap:5px}
  .mini-bars i{max-width:none;min-width:4px}
  .load-strip strong{font-size:21px}

  /* Workout: information first. The decorative image is deliberately subdued on small screens. */
  .workout-hero{margin-bottom:12px;border-radius:16px}
  .hero-copy{max-width:none}
  .hero-main{font-size:clamp(37px,12vw,48px);line-height:1}
  .hero-metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0;width:100%;max-width:none}
  .hero-metrics>div{min-width:0;padding:0 8px;margin:0;border-right:1px solid var(--border)}
  .hero-metrics>div:first-child{padding-left:0}
  .hero-metrics>div:last-child{padding-right:0;border-right:0}
  .hero-metrics strong{font-size:clamp(15px,4.8vw,19px);overflow-wrap:anywhere}
  .hero-metrics span{font-size:10px}
  .hero-actions{display:grid;grid-template-columns:1fr;gap:10px;align-items:start}
  .primary-btn{min-height:46px;width:100%}
  .ftp-note{font-size:12px}

  /* On mobile, proportional interval widths become unreadable. Preserve order and content,
     but switch to a horizontally scrollable sequence of legible blocks. */
  .live-timeline,.workout-timeline{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(96px,max-content);gap:6px;overflow-x:auto;overscroll-behavior-x:contain;scroll-snap-type:x proximity;padding:2px 1px 8px;margin-right:-2px;scrollbar-width:thin}
  .live-timeline .segment,.workout-timeline .segment{min-width:96px;scroll-snap-align:start;flex:none}
  .segment span{white-space:normal;line-height:1.15}

  .three-grid{grid-template-columns:1fr;gap:10px;margin-bottom:12px}
  .focus-panel{min-height:0;padding:15px}
  .performance-strip{grid-template-columns:repeat(2,minmax(0,1fr));border-radius:16px}
  .performance-strip>div{min-width:0;padding:12px;border-right:1px solid var(--border);border-bottom:1px solid var(--border)}
  .performance-strip>div:nth-child(2n){border-right:0}
  .performance-strip>div:nth-last-child(-n+2){border-bottom:0}
  .performance-strip strong{font-size:19px;overflow-wrap:anywhere}

  /* Ride KPIs: 2 columns is materially more readable than six or three compressed tiles. */
  .live-kpi-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .live-kpi{padding:12px;min-height:74px}
  .live-kpi strong{font-size:19px;overflow-wrap:anywhere}
  .live-kpi span{font-size:10px;line-height:1.25}
  .live-two{grid-template-columns:1fr;gap:10px}
  .live-grid-12,.live-development-grid{display:grid;grid-template-columns:1fr;gap:10px}
  .live-span-8,.live-span-7,.live-span-6,.live-span-5,.live-span-4{grid-column:auto}
  .live-chart-card,.live-map-card,.live-panel,.echart-card{padding:13px}
  .card-head{gap:8px;align-items:flex-start}
  .card-head h3{font-size:15px;line-height:1.2}
  .legend{gap:8px;flex-wrap:wrap;justify-content:flex-end}

  /* Charts get a predictable viewport and no parent-level horizontal overflow. */
  .echart,.live-chart{width:100%;height:250px;min-height:230px;max-width:100%;overflow:hidden}
  .live-map{width:100%;height:235px;max-width:100%}
  .live-map .maplibregl-ctrl-top-right{display:none}
  .live-map .maplibregl-ctrl-attrib{font-size:8px;max-width:80%}

  /* Interval table turns into stacked records; no horizontal table scrolling required. */
  .compact-table,.compact-table tbody{display:block;width:100%}
  .compact-table tr{display:grid;grid-template-columns:1fr 1fr;gap:6px 10px;padding:10px 0;border-bottom:1px solid #edf1f5}
  .compact-table tr:last-child{border-bottom:0}
  .compact-table td{display:grid;grid-template-columns:1fr;gap:2px;padding:0;border:0;text-align:left;white-space:normal}
  .compact-table td:first-child{grid-column:1/-1;font-size:13px}
  .compact-table td:nth-child(2)::before{content:"Dauer"}
  .compact-table td:nth-child(3)::before{content:"Leistung"}
  .compact-table td:nth-child(4)::before{content:"Herzfrequenz"}
  .compact-table td:nth-child(n+2)::before{display:block;color:var(--muted);font-size:9px;font-weight:800;text-transform:uppercase;letter-spacing:.06em}

  .compare-list>div{grid-template-columns:minmax(0,1fr) auto 18px;gap:6px;font-size:11px}
  .live-assessment,.live-feedback{padding:14px}
  .live-feedback dl>div{gap:12px}
  .live-rides-list{width:calc(100% + 12px);margin-right:-12px;padding-right:12px;overflow-x:auto;overscroll-behavior-x:contain;scrollbar-width:none}
  .live-rides-list::-webkit-scrollbar{display:none}
  .ride-chip{min-height:38px}

  .development-kpis,.kpi-row.four{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .development-kpis .kpi{min-height:86px;padding:12px}
  .development-kpis .kpi strong{font-size:20px}
  .profile-item{grid-template-columns:45px minmax(0,1fr) 58px;gap:7px}

  /* Bottom navigation: keep all six destinations, but make the control safe on modern iPhones. */
  .mobile-nav{position:fixed;left:0;right:0;bottom:0;z-index:90;display:grid;grid-template-columns:repeat(6,minmax(0,1fr));padding:7px 5px calc(7px + env(safe-area-inset-bottom,0px));background:rgba(252,253,255,.94);border-top:1px solid var(--border);backdrop-filter:blur(18px);box-shadow:0 -8px 28px rgba(23,42,68,.08)}
  .mobile-nav button{min-width:0;min-height:52px;padding:4px 1px;border:0;background:transparent;color:#66768b;display:grid;place-items:center;align-content:center;gap:3px;border-radius:10px}
  .mobile-nav button.active{color:var(--blue);background:var(--blue-soft)}
  .mobile-nav svg{width:19px;height:19px}
  .mobile-nav small{font-size:9px;line-height:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}

  .auth-gate{padding:max(14px,env(safe-area-inset-top,0px)) 12px max(14px,env(safe-area-inset-bottom,0px))}
  .auth-card{max-height:calc(100dvh - 28px);overflow:auto;border-radius:18px;padding:18px}
}

/* Narrow phones. */
@media(max-width:430px){
  .workspace{padding-left:10px;padding-right:10px}
  .page-head h1{font-size:27px}
  .hero-metrics strong{font-size:15px}
  .hero-metrics span{font-size:9px}
  .live-kpi-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .development-kpis,.kpi-row.four{grid-template-columns:1fr 1fr}
  .echart,.live-chart{height:235px;min-height:220px}
  .live-map{height:220px}
  .mobile-nav small{font-size:8px}
}

@media(max-width:360px){
  .workspace{padding-left:8px;padding-right:8px}
  .hero-metrics{grid-template-columns:1fr 1fr}
  .hero-metrics>div{border-right:0;border-bottom:1px solid var(--border);padding:7px 0}
  .hero-metrics>div:nth-child(3){grid-column:1/-1;border-bottom:0}
  .performance-strip{grid-template-columns:1fr}
  .performance-strip>div{border-right:0;border-bottom:1px solid var(--border)!important}
  .performance-strip>div:last-child{border-bottom:0!important}
  .mobile-nav small{display:none}
  .mobile-nav button{min-height:46px}
}

@media(orientation:landscape) and (max-height:520px) and (max-width:900px){
  .workspace{padding-bottom:calc(72px + env(safe-area-inset-bottom,0px))}
  .mobile-nav button{min-height:42px}
  .mobile-nav small{display:none}
  .echart,.live-chart{height:210px;min-height:200px}
  .live-map{height:210px}
}

@media(prefers-reduced-motion:reduce){
  .live-timeline,.workout-timeline{scroll-behavior:auto}
}
