html { height: 100%; }
body.cx {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--top, #2f86e0), var(--bot, #a6d8f7));
  color: #142230;
  font-family: Barlow, "Segoe UI", sans-serif;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    calc(12px + env(safe-area-inset-bottom))
    env(safe-area-inset-left);
}
body.cx.cx-night { color: #f4f1ea; }
.cx-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 14px 14px 6px;
}
.cx-title { min-width: 180px; }
.cx-title p { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; opacity: .8; }
.cx-title h1 { margin: 2px 0 0; font: 650 clamp(28px, 4vw, 40px)/1 "Barlow Condensed", sans-serif; }
.cx-clock { margin: 0; }
#cxHms {
  display: block;
  font: 600 clamp(34px, 7vw, 58px)/.9 "Barlow Condensed", sans-serif;
  font-variant-numeric: tabular-nums;
}
.cx-clock small { display: block; margin-top: 2px; font-size: 14px; font-weight: 600; opacity: .85; }
.cx-clock small::first-letter { text-transform: uppercase; }
.cx-rain {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 252, 246, .88);
  color: #142230;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.cx-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.cx-actions a,
.cx-actions button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 252, 246, .94);
  color: #142230;
  font: 700 16px/1.1 Barlow, sans-serif;
  text-decoration: none;
  cursor: pointer;
}
.cx-actions button[hidden],
.cx-ferma[hidden],
.cx-ios[hidden] { display: none; }
.cx-ferma,
.cx-ios {
  width: min(1200px, calc(100% - 28px));
  margin: 8px auto 0;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 750;
}
.cx-ferma { background: #f3d48a; color: #2a2112; }
.cx-ios { background: rgba(255, 252, 246, .9); color: #142230; font-weight: 650; }
body.cx .m3{
  width: min(1200px, calc(100% - 16px));
  margin: 10px auto 0;
  border-radius: 18px;
}
body.cx:has(.m3.tv) .cx-bar,
body.cx:has(.m3.tv) .cx-ferma,
body.cx:has(.m3.tv) .cx-ios{ display: none !important; }
body.cx .kpi-strip {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px !important;
  width: min(1200px, 100%);
  margin: 10px auto 0;
  padding: 8px 12px 8px;
}
@media (min-width: 900px) {
  body.cx .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}
body.cx .kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 12px 10px 14px;
  border: 0;
  border-radius: 18px;
  background: rgba(251, 248, 242, .94);
  color: #1c2a30;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .18);
  text-align: center;
}
body.cx .kpi__head { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
body.cx .kpi__ico { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; }
body.cx .kpi__ico svg { width: 28px; height: 28px; }
body.cx .kpi__label {
  margin: 0;
  font: 750 22px/1.1 Barlow, sans-serif;
  color: #1c2a30 !important;
  cursor: default;
}
body.cx .kpi__val {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  font: 750 clamp(1.7rem, 5vw, 2.8rem)/1 "Barlow Condensed", sans-serif;
  font-variant-numeric: tabular-nums;
}
body.cx .kpi__val small { font-size: .42em; font-weight: 700; }
body.cx .kpi__dir { font: 750 18px/1 Barlow, sans-serif; }
body.cx .cx-medio {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.3;
  color: #314048;
}
body.cx .kpi__sub,
body.cx .kpi__trend,
body.cx .kpi__vista { display: none; }
body.cx .kpi .gauge {
  position: relative;
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  aspect-ratio: 1;
  margin: 4px auto;
  padding: 0;
  border: 0;
  background: transparent;
}
body.cx .kpi .gauge svg { width: 100%; height: 100%; display: block; }
body.cx .kpi .gauge[data-draw="cru"] canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
body.cx .gauge:has(canvas) svg { display: none !important; }
.cx-short { display: none; }
.cx-rain span + span::before { content: " · "; }
.cx-rain.is-piove { background: #1f5fd0; color: #f7fbff; }
.cx-rain.is-era { background: #8eadd4; color: #102033; }
body.cx .cx-moon {
  width: auto;
  margin: 2px 0 0;
  padding: 0 6px;
  font: 650 14px/1.3 Barlow, sans-serif;
  color: #314048;
}
@media (orientation: portrait) and (max-width: 820px) {
  .cx-title,
  .cx-full { display: none; }
  .cx-short { display: inline; }
  .cx-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 8px 4px;
  }
  .cx-clock { flex: 0 0 auto; width: max-content; max-width: 42vw; }
  #cxHms { font-size: clamp(26px, 7.4vw, 34px); white-space: nowrap; }
  .cx-clock small {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }
  .cx-rain {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 0 1 auto;
    min-width: 0;
    padding: 5px 8px;
    font-size: 13px;
    line-height: 1.15;
  }
  .cx-rain span + span::before { content: none; }
  .cx-actions { margin-left: auto; flex-wrap: nowrap; gap: 6px; }
  .cx-actions a,
  .cx-actions button { padding: 8px 8px; font-size: 14px; }
  body.cx .kpi-strip { gap: 8px !important; padding: 6px 8px 12px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  body.cx {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(132px, 158px) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    padding:
      env(safe-area-inset-top)
      env(safe-area-inset-right)
      env(safe-area-inset-bottom)
      env(safe-area-inset-left);
  }
  .cx-title p,
  .cx-clock small,
  .cx-full { display: none; }
  .cx-short { display: inline; }
  .cx-title { min-width: 0; }
  .cx-title h1 { font-size: 22px; }
  .cx-bar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 6px;
    width: auto;
    margin: 0;
    padding: 6px 8px 4px 6px;
  }
  #cxHms { font-size: 28px; }
  .cx-rain {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 6px 8px;
    font-size: 14px;
    line-height: 1.15;
  }
  .cx-rain span + span::before { content: none; }
  .cx-actions { margin-left: 0; flex-direction: column; align-items: stretch; }
  .cx-actions a,
  .cx-actions button { width: 100%; }
  .cx-ferma,
  .cx-ios {
    grid-column: 1;
    width: auto;
    margin: 0 8px 6px 6px;
    padding: 8px;
    font-size: 13px;
  }
  .cx-ferma { grid-row: 2; }
  .cx-ios { grid-row: 3; align-self: end; }
  body.cx .kpi-strip {
    grid-column: 2;
    grid-row: 1 / span 3;
    width: auto;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 6px 8px 6px 0;
    gap: 6px !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    align-content: stretch;
    overflow: hidden;
  }
  body.cx .kpi {
    min-height: 0;
    height: 100%;
    padding: 4px 6px 5px;
    gap: 1px;
    border-radius: 12px;
    overflow: hidden;
  }
  body.cx .kpi__ico { display: none; }
  body.cx .kpi__label { font-size: 13px !important; }
  body.cx .kpi__val { font-size: 1.15rem; }
  body.cx .kpi__dir { font-size: 13px; }
  body.cx .cx-medio,
  body.cx .cx-moon {
    font-size: 11px;
    line-height: 1.2;
    max-height: 2.4em;
    overflow: hidden;
  }
  body.cx .kpi .gauge {
    width: min(100%, calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) / 2 - 54px));
    max-width: min(100%, calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px) / 2 - 54px));
    margin: 0 auto;
    flex: 0 0 auto;
  }
}
/* Tablet e finestre larghe in orizzontale: due righe intere, senza tagliare la seconda. */
@media (orientation: landscape) and (min-height: 541px) and (min-width: 700px) {
  body.cx {
    box-sizing: border-box;
    --cx-extra: 0px;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding:
      env(safe-area-inset-top)
      env(safe-area-inset-right)
      calc(6px + env(safe-area-inset-bottom))
      env(safe-area-inset-left);
  }
  body.cx:has(#cxFerma:not([hidden])) { --cx-extra: 46px; }
  body.cx:has(#cxIos:not([hidden])) { --cx-extra: 52px; }
  body.cx:has(#cxFerma:not([hidden])):has(#cxIos:not([hidden])) { --cx-extra: 96px; }
  .cx-bar {
    box-sizing: border-box;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 8px 12px 2px;
    gap: 8px 14px;
  }
  .cx-title { min-width: 0; flex: 0 1 240px; }
  .cx-title p {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .cx-title h1 { font-size: clamp(22px, 3.2vw, 34px); white-space: nowrap; }
  .cx-clock { flex: 0 0 auto; }
  #cxHms { font-size: clamp(28px, 5.2vh, 48px); }
  .cx-clock small { font-size: 13px; white-space: nowrap; }
  .cx-rain { flex: 0 0 auto; white-space: nowrap; padding: 6px 12px; }
  .cx-actions { flex: 0 0 auto; flex-wrap: nowrap; margin-left: auto; }
  .cx-ferma,
  .cx-ios {
    box-sizing: border-box;
    flex: 0 0 auto;
    width: auto;
    margin: 4px 12px 0;
    padding: 8px 12px;
  }
  body.cx .kpi-strip {
    box-sizing: border-box;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 6px 10px 4px;
    gap: 8px !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    align-content: stretch;
    overflow: hidden;
  }
  body.cx .kpi {
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    height: 100%;
    padding: 6px 8px 4px;
    gap: 0;
    overflow: hidden;
    justify-content: flex-start;
    border-radius: 16px;
  }
  body.cx .kpi__ico { width: 26px; height: 26px; }
  body.cx .kpi__ico svg { width: 20px; height: 20px; }
  body.cx .kpi__label { font-size: 16px !important; }
  body.cx .kpi__val { font-size: clamp(1.15rem, 3vh, 1.7rem); }
  body.cx .kpi__dir { font-size: 14px; }
  body.cx .cx-medio,
  body.cx .cx-moon {
    width: 100%;
    margin: 0;
    padding: 0 4px;
    font-size: 12px;
    line-height: 1.2;
    max-height: 2.4em;
    overflow: hidden;
  }
  body.cx .kpi .gauge {
    width: min(100%, calc((100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 36px) / 3 - 8px), calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 118px - var(--cx-extra)) / 2 - 108px));
    max-width: min(100%, calc((100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 36px) / 3 - 8px), calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 118px - var(--cx-extra)) / 2 - 108px));
    margin: 1px auto;
    flex: 0 0 auto;
    min-height: 0;
  }
}
