/* Tela da cozinha (KDS).
   Hierarquia de urgência: verde calmo, amarelo evidente, vermelho impossível de ignorar.
   Tamanhos da comanda em "em": o zoom (A−/A+ e modo TV) escala tudo junto. */

.kds {
  --kds-zoom: var(--kds-user-zoom, 1);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
  padding: 14px clamp(12px, 1.5vw, 22px) 0;
}

body.tv .kds {
  --kds-zoom: calc(var(--kds-user-zoom, 1) * 1.14);
  padding-top: 10px;
}

body.tv .tv-hide {
  display: none !important;
}

/* ───────── Cabeçalho ───────── */
.kds-head {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto auto;
  grid-template-areas: 'brand stats clock conn';
  align-items: center;
  gap: clamp(14px, 2vw, 32px);
  padding: 12px 18px 12px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.kds-brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.kds-logo {
  flex: none;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  overflow: hidden;
  font-family: var(--font-display);
  font-stretch: 75%;
  font-weight: 800;
  font-size: 19px;
}

.kds-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.kds-title {
  min-width: 0;
}

.kds-title h1 {
  font-family: var(--font-display);
  font-stretch: 66%;
  font-weight: 800;
  font-size: clamp(28px, 2.5vw, 42px);
  line-height: 0.92;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.kds-title p {
  margin-top: 5px;
  color: var(--text-3);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kds-stats {
  grid-area: stats;
  display: flex;
  justify-content: center;
  margin: 0;
  min-width: 0;
}

.stat {
  padding: 2px clamp(12px, 1.7vw, 28px);
  border-left: 1px solid var(--line);
  min-width: 0;
}

.stat:first-child {
  border-left: 0;
}

.stat dt {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}

.stat dd {
  margin: 3px 0 0;
  font-family: var(--font-display);
  font-stretch: 68%;
  font-weight: 800;
  font-size: clamp(30px, 2.8vw, 46px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-late[data-hot='true'] dt,
.stat-late[data-hot='true'] dd {
  color: var(--late);
}

.kds-clock {
  grid-area: clock;
  display: grid;
  justify-items: end;
  line-height: 1;
}

.clock-time {
  font-size: clamp(26px, 2.3vw, 36px);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.clock-sec {
  font-size: 0.5em;
  color: var(--text-3);
  letter-spacing: 0;
}

.clock-date {
  margin-top: 7px;
  font-size: 12px;
  color: var(--text-3);
}

.kds-conn {
  grid-area: conn;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
}

/* ───────── Barra de filtros e ferramentas ───────── */
.kds-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.kds-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip.chip-late:not([aria-pressed='true']) .count {
  background: var(--late);
  color: #fff;
}

.kds-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.kds-sound-lock {
  border-color: var(--warn-line);
  background: var(--warn-soft);
  color: var(--warn);
}

.kds-pending {
  align-self: center;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--info-soft);
  border: 1px solid var(--info-line);
  color: var(--info-ink);
  font-weight: 700;
}

/* ───────── Quadro ───────── */
.kds-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(320px * var(--kds-zoom)), 1fr));
  gap: calc(14px * var(--kds-zoom));
  align-items: start;
  padding-bottom: 12px;
}

.kds-empty {
  flex: 1;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-2);
  border-radius: 18px;
  margin-bottom: 12px;
}

/* ───────── Quadro kanban (tela com duas ou mais etapas) ─────────
   A tela ocupa a altura da área principal e cada coluna rola sozinha: na TV o cabeçalho
   e o nome das colunas ficam sempre à vista. */
.kds.is-kanban {
  height: 100%;
  min-height: 0;
}

.kds-board.is-kanban {
  flex: 1;
  min-height: 0;
  grid-template-columns: repeat(var(--kds-cols, 3), minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  gap: calc(12px * var(--kds-zoom));
  padding-bottom: 0;
}

.kds-col {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

.kds-col-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.kds-col-head h2 {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-family: var(--font-display);
  font-stretch: 70%;
  font-weight: 800;
  font-size: calc(21px * var(--kds-zoom));
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ponto com a mesma cor da pílula de status (novo azul, pronto verde, o resto neutro) */
.kds-col-head h2::before {
  content: '';
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-2);
}

.kds-col[data-col='novo'] .kds-col-head h2::before {
  background: var(--info);
}

.kds-col[data-col='pronto'] .kds-col-head h2::before {
  background: var(--ok);
}

.kds-col-late {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--late);
  white-space: nowrap;
}

.kds-col-count {
  min-width: 36px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  font-family: var(--font-display);
  font-stretch: 70%;
  font-weight: 800;
  font-size: calc(18px * var(--kds-zoom));
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.kds-col-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(300px * var(--kds-zoom))), 1fr));
  /* altura fixa + comanda com overflow:hidden = linha "auto" encolhe até esmagar a comanda; a linha segue o conteúdo e a coluna rola */
  grid-auto-rows: max-content;
  align-content: start;
  gap: calc(12px * var(--kds-zoom));
  padding: calc(12px * var(--kds-zoom)) calc(12px * var(--kds-zoom)) calc(56px * var(--kds-zoom));
}

.kds-col-empty {
  flex: none;
  margin: 12px 12px 0;
  padding: 18px 12px;
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
}

.kds-col-more {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-3);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 1000px) {
  /* três colunas não cabem lado a lado: deslizam na horizontal, uma de cada vez */
  .kds-board.is-kanban {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(min(86vw, 380px), 1fr);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 4px;
  }

  .kds-board.is-kanban .kds-col {
    scroll-snap-align: start;
  }
}

/* ───────── Comanda ───────── */
.ticket {
  --tone: var(--ok);
  --tone-soft: var(--ok-soft);
  --tone-line: var(--ok-line);
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: calc(15px * var(--kds-zoom));
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 1.05em;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  content-visibility: auto;
  contain-intrinsic-size: auto 360px;
  transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
  animation: ticket-in 0.35s var(--ease);
}

.ticket:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 3px;
}

.ticket.is-ok {
  border-color: rgba(52, 209, 127, 0.26);
}

.ticket.is-warn {
  --tone: var(--warn);
  --tone-soft: var(--warn-soft);
  --tone-line: var(--warn-line);
  border-color: var(--warn-line);
  animation: warn-flash 0.9s ease-in-out 2;
}

.ticket.is-fresh {
  box-shadow: 0 0 0 2px var(--info), 0 0 36px rgba(90, 162, 255, 0.28);
}

.ticket.is-late {
  --tone: var(--late);
  --tone-soft: var(--late-soft);
  --tone-line: var(--late-line);
  border-color: var(--late);
  background: linear-gradient(180deg, rgba(255, 79, 79, 0.14), rgba(255, 79, 79, 0.02) 42%), var(--surface);
  box-shadow: inset 0 0 0 1px var(--late), 0 12px 40px rgba(255, 79, 79, 0.2);
  animation: late-alarm 1.1s ease-in-out 3;
}

.ticket.is-frozen:not(.is-late) {
  border-color: var(--line-2);
}

/* pavio: quanto do prazo já foi consumido; marca = limite amarelo */
.ticket-fuse {
  position: relative;
  height: 0.42em;
  background: var(--surface-3);
  flex: none;
}

.fuse-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
  background: var(--tone);
  transition: transform 0.9s linear, background-color 0.3s;
}

.fuse-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--m, 0.66) * 100%);
  width: 2px;
  background: var(--bg);
}

.ticket-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6em;
  padding: 0.8em 0.95em 0;
}

.ticket-ident {
  display: grid;
  gap: 0.3em;
  min-width: 0;
}

.ticket-num {
  font-family: var(--font-display);
  font-stretch: 68%;
  font-weight: 800;
  font-size: 2.05em;
  line-height: 0.9;
}

.ticket-source {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  color: var(--text-2);
  font-size: 0.78em;
  font-weight: 600;
  white-space: nowrap;
}

.ticket-source .i {
  width: 1.1em;
  height: 1.1em;
}

.ticket-timer {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 0.25em;
  padding: 0.3em 0.55em 0.34em;
  border-radius: 0.65em;
  background: var(--tone-soft);
  border: 1px solid var(--tone-line);
  color: var(--tone);
}

.t-value {
  font-size: 1.72em;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
}

.t-unit {
  font-size: 0.68em;
  font-weight: 700;
  opacity: 0.75;
}

.ticket.is-late .ticket-timer {
  background: var(--late);
  border-color: var(--late);
  color: #fff;
}

.ticket.is-frozen .ticket-timer {
  opacity: 0.8;
}

.ticket-who {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6em;
  padding: 0.5em 0.95em 0;
}

.ticket-customer {
  min-width: 0;
  font-family: var(--font-display);
  font-stretch: 76%;
  font-weight: 750;
  font-size: 1.38em;
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.ticket-sla {
  flex: none;
  font-size: 0.7em;
}

.ticket-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4em;
  padding: 0.4em 0.95em 0;
  color: var(--text-3);
  font-size: 0.8em;
  font-weight: 600;
}

.ticket-status {
  margin-left: auto;
}

.ticket-status .pill {
  height: 1.6em;
  font-size: 0.82em;
}

.dot-sep {
  color: var(--text-3);
}

.ticket-alert {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0.6em 0.95em 0;
  padding: 0.45em 0.7em;
  border-radius: 0.6em;
  background: var(--late-soft);
  color: var(--late);
  font-weight: 700;
  font-size: 0.85em;
}

.ticket-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  margin: 0.6em 0.95em 0;
  padding: 0.45em 0.7em;
  border-radius: 0.6em;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--text-2);
  font-size: 0.84em;
}

.ticket-strip b {
  color: var(--text);
  font-size: 1.1em;
}

.ticket-body {
  display: grid;
  gap: 0.7em;
  margin-top: 0.8em;
  padding: 0.8em 0.95em 0.2em;
  border-top: 1px dashed var(--line-3);
}

/* ───────── Itens e modificações (também usados no painel de detalhes) ───────── */
.items {
  display: grid;
  gap: 0.6em;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 0.7em;
}

.item-photo {
  flex: none;
  width: 3.7em;
  height: 3.7em;
  border-radius: 0.65em;
  object-fit: cover;
  background: var(--surface-3);
  border: 1px solid var(--line-2);
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-line {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
}

.item-qty {
  flex: none;
  min-width: 1.9em;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.92em;
  color: var(--text-2);
}

.item-qty.is-multi {
  min-width: 0;
  padding: 0.05em 0.35em;
  border-radius: 0.35em;
  background: var(--text);
  color: var(--bg);
}

.item-name {
  font-family: var(--font-display);
  font-stretch: 80%;
  font-weight: 750;
  font-size: 1.22em;
  line-height: 1.1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.mods {
  display: grid;
  gap: 0.3em;
  margin-top: 0.4em;
}

.mod {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.98em;
  font-weight: 650;
  line-height: 1.2;
}

.mod-glyph {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 0.4em;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 0.92em;
  line-height: 1;
}

.mod-remove .mod-glyph {
  background: rgba(255, 79, 79, 0.17);
  color: var(--remove);
}

.mod-add .mod-glyph {
  background: var(--info-soft);
  color: var(--info);
}

.mod-choice .mod-glyph {
  background: var(--surface-3);
  color: var(--text-2);
}

.mod-choice .mod-text {
  color: var(--text-2);
}

.mod-note .mod-glyph {
  background: var(--warn-soft);
  color: var(--warn);
}

.mod-note .mod-text {
  font-style: italic;
  font-weight: 550;
}

.order-note {
  display: flex;
  gap: 0.6em;
  padding: 0.6em 0.7em;
  border-radius: 0.7em;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
}

.order-note .mod-glyph {
  margin-top: 0.1em;
  background: var(--warn-soft);
  color: var(--warn);
}

.order-note-label {
  display: block;
  font-size: 0.68em;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}

.order-note p {
  margin-top: 0.15em;
  font-weight: 650;
  font-size: 0.98em;
}

.order-note.is-important {
  background: var(--warn-soft);
  border-color: var(--warn-line);
}

.order-note.is-important .order-note-label {
  color: var(--warn);
}

/* ───────── Ação ───────── */
.ticket-foot {
  margin-top: auto;
  padding: 0.8em 0.95em 0.95em;
}

.ticket-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  width: 100%;
  min-height: 3.4em;
  border-radius: 0.8em;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-display);
  font-stretch: 85%;
  font-weight: 800;
  font-size: 1.02em;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transition: background-color 0.15s, transform 0.08s;
}

.ticket-action:hover {
  background: #fff;
}

.ticket-action:active {
  transform: scale(0.99);
}

.ticket-action .i {
  width: 1.2em;
  height: 1.2em;
  stroke-width: 2.4;
}

.ticket[data-status='novo'] .ticket-action {
  background: var(--info);
  color: #051224;
}

.ticket[data-status='novo'] .ticket-action:hover {
  background: #7ab5ff;
}

.ticket-action[aria-busy='true'] {
  opacity: 0.55;
  pointer-events: none;
}

.ticket-waiting {
  padding: 0.7em;
  border: 1px dashed var(--line-3);
  border-radius: 0.8em;
  color: var(--text-3);
  font-size: 0.86em;
  text-align: center;
}

/* ───────── Rodapé ───────── */
.kds-foot {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: auto;
  padding: 18px 4px 14px;
  background: linear-gradient(180deg, rgba(10, 12, 15, 0), var(--bg) 45%);
  color: var(--text-3);
  font-size: 12.5px;
}

.kds-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

.kds-legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.kds-legend b {
  color: var(--text-2);
  font-weight: 650;
}

.lg {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.lg-ok {
  background: var(--ok);
}

.lg-warn {
  background: var(--warn);
}

.lg-late {
  background: var(--late);
}

.kds-overflow {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-3);
  color: var(--text);
  font-weight: 700;
}

.kds-links {
  display: flex;
  gap: 4px;
}

.kds-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 600;
}

.kds-links a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.kds-links .i {
  width: 15px;
  height: 15px;
}

/* ───────── Animações ───────── */
@keyframes ticket-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

@keyframes warn-flash {
  50% {
    box-shadow: 0 0 0 5px rgba(255, 194, 51, 0.28);
  }
}

@keyframes late-alarm {
  0%,
  100% {
    box-shadow: inset 0 0 0 1px var(--late), 0 12px 40px rgba(255, 79, 79, 0.2);
  }
  50% {
    box-shadow: inset 0 0 0 1px var(--late), 0 0 0 7px rgba(255, 79, 79, 0.35), 0 12px 52px rgba(255, 79, 79, 0.38);
  }
}

/* ───────── Responsivo ───────── */
@media (max-width: 1320px) {
  .kds-head {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      'brand clock conn'
      'stats stats stats';
    row-gap: 12px;
  }

  .kds-stats {
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }

  .stat {
    flex: 1;
  }
}

@media (max-width: 760px) {
  .kds {
    padding: 10px 10px 0;
    gap: 10px;
  }

  .kds-head {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'brand clock'
      'stats stats'
      'conn conn';
    padding: 10px 12px;
  }

  .kds-logo {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }

  .kds-title p {
    display: none;
  }

  .kds-conn {
    justify-self: start;
  }

  .kds-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stat {
    padding: 0 8px;
  }

  .stat dt {
    font-size: 9px;
    letter-spacing: 0.06em;
    white-space: normal;
  }

  .stat dd {
    font-size: 28px;
  }

  .kds-board {
    grid-template-columns: minmax(0, 1fr);
  }

  .kds-tools .btn span {
    display: none;
  }

  .kds-tools .btn {
    width: var(--h);
    padding: 0;
  }

  .kds-sound-lock span {
    display: inline !important;
  }

  .kds-tools .kds-sound-lock {
    width: auto;
    padding: 0 12px;
  }

  .kds-links,
  .kds-legend {
    display: none;
  }

  .kds-foot:has(.kds-overflow[hidden]) {
    display: none;
  }
}
