/* Widget arrivi ATAC - richiede assets/kiosk/kiosk.css (font Roboto, token, baseline touch) */

:root {
  --atac: var(--k-atac, #84092c);
  --atac-dark: var(--k-atac-dark, #460412);
  --live: var(--k-live, #0F9D58);
  --ink: #1d1d1b;
  --muted: #5c5c5c;
  --rule: rgba(132, 9, 44, 0.22);
  --fs: clamp(18px, min(4.4vw, 6.2vh), 60px);
  --fs-s: max(14px, calc(var(--fs) * 0.46));
  --pad: clamp(10px, min(2.2vw, 2.6vh), 32px);
  --band: clamp(10px, 5vh, 64px);
  --aside-w: clamp(180px, 23vw, 300px);
  --bg: #ffffff;
}

html, body { height: 100%; }

body.atac {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--k-font-ui, 'Roboto', system-ui, sans-serif);
  font-size: var(--fs);
  line-height: 1.15;
}

.atac__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-w);
  grid-template-rows: auto minmax(0, 1fr) var(--band);
  grid-template-areas:
    "head  aside"
    "board aside"
    "band  band";
  column-gap: var(--pad);
  height: 100%;
  padding: var(--pad) max(var(--pad), env(safe-area-inset-right)) 0 max(var(--pad), env(safe-area-inset-left));
}

/* Intestazione */
.atac__head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: var(--pad);
  min-width: 0;
}

.atac__logo {
  display: block;
  width: auto;
  height: clamp(40px, min(9vw, 13vh), 120px);
  flex: none;
  pointer-events: none;
}

.atac__titles { min-width: 0; }

.atac__title {
  margin: 0;
  color: var(--atac);
  font-size: calc(var(--fs) * 0.92);
  font-weight: 700;
  line-height: 1.1;
}

.atac__stop {
  margin: 0.15em 0 0;
  color: var(--ink);
  font-size: calc(var(--fs) * 0.6);
  font-weight: 400;
}

.atac__stop strong { color: var(--atac); font-weight: 700; }

/* Tabella arrivi */
.atac__board {
  grid-area: board;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.atac__board::-webkit-scrollbar { display: none; }

.atac__table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: calc(var(--pad) * 0.6);
}

.atac__table thead th {
  padding: 0 0 0.3em;
  border-bottom: 3px solid var(--atac);
  color: var(--atac);
  font-size: calc(var(--fs) * 0.5);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
}

.atac__table thead th:first-child { text-align: center; }
.col-route { width: calc(var(--fs) * 2.9); }
.col-eta { width: 40%; }

.line > * {
  padding: calc(var(--pad) * 0.55) 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
  text-align: left;
}

.line:last-child > * { border-bottom: 0; }

.line__route { text-align: center !important; }

.line__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.3em;
  padding: 0.12em 0.3em;
  border-radius: 0.22em;
  background: var(--atac);
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.line__dir { font-weight: 700; }

.dir {
  display: flex;
  align-items: center;
  gap: 0.3em;
  min-width: 0;
  padding-right: 0.3em;
}

.line__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line__metro {
  display: block;
  flex: none;
  width: auto;
  height: 0.95em;
}

.line__metro-txt {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  background: #0071bb;
  color: #fff;
  font-size: 0.7em;
}

.eta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.15em 0.45em;
}

.eta__time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink);
}

.line.is-live .eta__time { color: var(--live); }
.line.is-soon .eta__time { color: var(--live); }
.line.is-sched.is-soon .eta__time { color: var(--ink); }
.line.is-empty .eta__time,
.line.is-unknown .eta__time {
  color: var(--muted);
  font-size: calc(var(--fs) * 0.5);
  font-weight: 500;
  white-space: normal;
}

.eta__next {
  margin-top: 0.15em;
  color: var(--muted);
  font-size: var(--fs-s);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eta__next:empty { display: none; }

/* Indicatore tempo reale */
.live-dot {
  position: relative;
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  flex: none;
  border-radius: 50%;
  background: var(--live);
}

.live-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--live);
  animation: atac-pulse 1.6s ease-out infinite;
}

@keyframes atac-pulse {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(2.6); opacity: 0; }
}

.sched-tag {
  display: inline-block;
  padding: 0.1em 0.45em;
  border: 2px solid currentColor;
  border-radius: 0.35em;
  color: var(--muted);
  font-size: max(12px, calc(var(--fs) * 0.34));
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.1;
  white-space: nowrap;
}

/* Stato e attribuzione */
.atac__info {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.2em 1em;
  margin-top: auto;
  padding: calc(var(--pad) * 0.5) 0 calc(var(--pad) * 0.4);
  border-top: 3px solid var(--atac);
  font-size: max(13px, calc(var(--fs) * 0.36));
}

.atac__info p { margin: 0; }

.atac__status { font-weight: 700; color: var(--ink); }
.atac__status.is-warn { color: #a05a00; }
.atac__status.is-error { color: var(--atac); }

.atac__attr { color: var(--muted); }

/* Colonna QR + mappa */
.atac__aside {
  grid-area: aside;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: var(--pad);
  min-height: 0;
  padding-bottom: calc(var(--pad) * 0.5);
}

.atac__qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3em;
  min-height: var(--k-tap, 64px);
  min-width: 0;
  padding: 10px;
  border: 3px solid var(--atac);
  border-radius: 16px;
  background: #fff;
  color: var(--atac);
  font: inherit;
  font-size: max(14px, calc(var(--fs) * 0.42));
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  flex: 0 1 auto;
}

.atac__qr-img {
  display: block;
  width: 100%;
  max-width: min(220px, 26vh);
  height: auto;
  aspect-ratio: 1;
  pointer-events: none;
}

.atac__qr:active { background: #f6e9ed; transform: scale(0.98); }

.atac__where.k-btn {
  width: 100%;
  min-height: max(64px, var(--k-tap, 64px));
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--atac);
  color: #fff;
  font-family: inherit;
  font-size: max(16px, calc(var(--fs) * 0.46));
  font-weight: 700;
  line-height: 1.15;
  box-shadow: 0 4px 12px rgba(70, 4, 18, 0.3);
}

.atac__where.k-btn svg { width: 1.6em; height: 1.6em; }
.atac__where.k-btn:active { background: var(--atac-dark); }
.atac__qr:focus { outline: none; }
.atac__qr:focus-visible { outline: 4px solid var(--atac); outline-offset: 3px; }

@media (hover: hover) {
  .atac__where.k-btn:hover { background: var(--atac-dark); }
  .atac__qr:hover { background: #fbf3f5; }
}

/* Banda decorativa diagonale */
.atac__band {
  grid-area: band;
  margin: 0 calc(-1 * max(var(--pad), env(safe-area-inset-right))) 0 calc(-1 * max(var(--pad), env(safe-area-inset-left)));
  background:
    linear-gradient(to bottom right, transparent 49.5%, var(--atac) 50%),
    linear-gradient(to bottom left, transparent 49.5%, var(--atac-dark) 50%);
}

/* Overlay */
.atac-dlg {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: var(--pad);
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: hidden;
}

.atac-dlg::backdrop { background: rgba(20, 2, 8, 0.72); }

.atac-dlg[open] { display: flex; align-items: center; justify-content: center; }

.atac-dlg__box {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  padding: calc(var(--pad) * 1.4);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.atac-dlg__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--atac);
  color: #fff;
  font: 700 44px/1 var(--k-font-ui, sans-serif);
  cursor: pointer;
}

.atac-dlg__close:active { background: var(--atac-dark); }

.atac-dlg__title {
  margin: 0 72px 0.3em;
  color: var(--atac);
  font-size: var(--fs);
  font-weight: 700;
  line-height: 1.1;
}

.atac-dlg__text {
  margin: 0 0 0.6em;
  font-size: max(16px, calc(var(--fs) * 0.5));
  line-height: 1.3;
}

.atac-dlg__hint {
  margin: 0.6em 0 0;
  color: var(--muted);
  font-size: max(13px, calc(var(--fs) * 0.34));
}

.atac-dlg--qr .atac-dlg__box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.atac-dlg__qr {
  display: block;
  width: min(70vw, 100vh - 260px, 760px);
  min-width: 160px;
  height: auto;
  aspect-ratio: 1;
}

/* Mappa fermata: pannello testo + immagine scorrevole */
.atac-dlg--map .atac-dlg__box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: var(--pad);
  width: min(100%, 1400px);
  height: 100%;
  text-align: left;
}

.atac-dlg--map .atac-dlg__side {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.atac-dlg--map .atac-dlg__title { margin: 0 0 0.4em; }

.atac-dlg__scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border-radius: 12px;
  background: #f4f4f4;
}

.atac-dlg__map {
  display: block;
  width: 100%;
  max-width: 888px;
  height: auto;
  margin: 0 auto;
  pointer-events: none;
}

/* Iframe/schermi alti: mappa intera in colonna */
@media (min-aspect-ratio: 1/1) and (max-height: 900px) {
  .atac-dlg--map .atac-dlg__box { width: 100%; }
}

@media (max-aspect-ratio: 3/4) {
  .atac-dlg--map .atac-dlg__box {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .atac-dlg--map .atac-dlg__side { padding-right: 72px; }
  .atac-dlg__map { width: auto; max-width: 100%; max-height: none; }
}

/* Iframe largo e basso (home): le righe occupano tutta l'altezza disponibile */
@media (min-width: 761px) and (min-aspect-ratio: 3/4) {
  .atac__table { flex: 1 1 auto; max-height: calc(var(--fs) * 10); }
}

/* Larghezze ridotte o pagina verticale: QR e pulsante passano sotto la tabella */
@media (max-width: 760px), (max-aspect-ratio: 3/4) {
  :root {
    --fs: clamp(16px, min(5.2vw, 6vh), 60px);
    --band: clamp(8px, 3vh, 48px);
  }
  .atac__layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto var(--band);
    grid-template-areas: "head" "board" "aside" "band";
  }
  .atac__aside {
    flex-direction: row;
    align-items: stretch;
    padding: calc(var(--pad) * 0.5) 0;
  }
  .atac__qr {
    flex-direction: row;
    flex: 0 1 auto;
    padding: 6px 10px;
  }
  .atac__qr-img { width: clamp(52px, 12vh - 40px, 200px); max-width: none; }
  .atac__where.k-btn { flex: 1 1 auto; width: auto; font-size: max(16px, calc(var(--fs) * 0.55)); }
}

/* Pagina verticale alta (uso standalone): tabella centrata e righe piu' ariose */
@media (max-aspect-ratio: 3/4) and (min-height: 1000px) {
  .atac__table { margin-block: auto; }
  .line > * { padding: calc(var(--pad) * 1.2) 0; }
}

/* Altezze ridotte (iframe basso): niente intestazioni colonna, righe compatte */
@media (max-height: 420px) {
  .atac__table thead { display: none; }
  .atac__table { margin-top: 0.2em; }
  .atac__stop { margin-top: 0; }
  .atac__logo { height: 36px; }
  .line > * { padding: 3px 0; }
  .atac__info { padding: 3px 0; }
  .atac__aside { padding: 4px 0; gap: 8px; }
  .atac__qr { padding: 4px 8px; border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot::after { animation: none; opacity: 0; }
  .atac__qr:active { transform: none; }
}
