/**
 * KDS — Zyareo Phase 4B
 * Operational kitchen display. Prefixed .kds-* only.
 * High contrast, touch-first, status-driven. Not a dashboard.
 */

body.kds {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--zy-font-sans);
  background: var(--zy-emerald-dark);
  color: #f3efe6;
  overflow-x: hidden;
}

.kds-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--zy-space-2);
  padding: var(--zy-space-3) var(--zy-space-4);
  padding-top: max(var(--zy-space-3), env(safe-area-inset-top));
  background: #041f1b;
  border-bottom: 1px solid rgba(243, 239, 230, 0.12);
  position: sticky;
  top: 0;
  z-index: 5;
}

.kds-identity {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-right: auto;
  min-width: 0;
}

.kds-identity strong {
  font-size: var(--zy-text-md);
  letter-spacing: var(--zy-tracking-wide);
}

.kds-kitchen {
  color: rgba(243, 239, 230, 0.72);
  font-size: var(--zy-text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(70vw, 28rem);
}

.kds-pill {
  font-size: var(--zy-text-xs);
  font-weight: var(--zy-weight-semibold);
  padding: 0.35rem 0.65rem;
  border-radius: var(--zy-radius-sm);
  background: rgba(255, 255, 255, 0.1);
  color: rgba(243, 239, 230, 0.9);
  white-space: nowrap;
}

.kds-pill.ok {
  background: var(--zy-emerald);
  color: #fff;
}

.kds-pill.warn {
  background: var(--zy-gold);
  color: var(--zy-charcoal);
}

.kds-pill.bad {
  background: var(--zy-error);
  color: #fff;
}

.kds-banner {
  margin: 0;
  padding: var(--zy-space-3) var(--zy-space-4);
  font-size: var(--zy-text-sm);
}

.kds-banner.error {
  background: #4a1812;
  color: #ffd7d0;
}

.kds-banner.setup {
  background: #3a2e12;
  color: #ffe9b8;
}

/* —— Board layout ——
 * Mobile: single stacked lane (ticket list)
 * Tablet: denser stack or 2 cols mid-width
 * Desktop: 3 status columns
 */
.kds-main {
  display: grid;
  gap: var(--zy-space-3);
  padding: var(--zy-space-3);
  padding-bottom: max(var(--zy-space-4), env(safe-area-inset-bottom));
  grid-template-columns: 1fr;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}

.kds-col {
  background: rgba(4, 31, 27, 0.55);
  border: 1px solid rgba(243, 239, 230, 0.12);
  border-radius: var(--zy-radius-lg);
  padding: var(--zy-space-3);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.kds-col[data-col='QUEUED'] {
  border-top: 3px solid var(--zy-gold);
}

.kds-col[data-col='PREPARING'] {
  border-top: 3px solid var(--zy-emerald);
}

.kds-col[data-col='READY'] {
  border-top: 3px solid #5ecf9a;
}

.kds-col h2 {
  margin: 0 0 var(--zy-space-3);
  font-size: var(--zy-text-xs);
  letter-spacing: var(--zy-tracking-caps);
  text-transform: uppercase;
  color: rgba(243, 239, 230, 0.72);
  font-weight: var(--zy-weight-semibold);
  position: sticky;
  top: 0;
  z-index: 1;
  background: #062e28;
  padding: var(--zy-space-2) 0;
  margin-top: calc(-1 * var(--zy-space-1));
}

.kds-cards {
  display: grid;
  gap: var(--zy-space-3);
  align-content: start;
}

.kds-card {
  background: #0a3a33;
  border: 1px solid rgba(243, 239, 230, 0.14);
  border-radius: var(--zy-radius-lg);
  padding: var(--zy-space-3);
  display: grid;
  gap: var(--zy-space-3);
  min-width: 0;
}

.kds-card.age-fresh {
  border-left: 4px solid #3d8f6a;
}

.kds-card.age-warming {
  border-left: 4px solid var(--zy-gold);
}

.kds-card.age-urgent {
  border-left: 4px solid #d4533a;
  box-shadow: inset 0 0 0 1px rgba(212, 83, 58, 0.35);
}

.kds-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--zy-space-2) var(--zy-space-3);
  align-items: baseline;
}

.kds-card-head .order {
  font-size: clamp(1.25rem, 3.5vw, 1.5rem);
  font-weight: var(--zy-weight-bold);
  letter-spacing: var(--zy-tracking-tight);
  color: #fff;
}

.kds-card-head .meta {
  color: rgba(243, 239, 230, 0.72);
  font-size: var(--zy-text-sm);
  font-weight: var(--zy-weight-medium);
}

.kds-chip {
  font-size: var(--zy-text-xs);
  font-weight: var(--zy-weight-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: var(--zy-radius-sm);
  background: rgba(243, 239, 230, 0.14);
  color: #f3efe6;
}

.kds-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--zy-space-2);
}

.kds-items li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--zy-space-2);
  padding: var(--zy-space-2) var(--zy-space-3);
  border-radius: var(--zy-radius-md);
  color: rgba(243, 239, 230, 0.55);
  font-size: var(--zy-text-md);
  min-width: 0;
}

.kds-items li.mine {
  background: rgba(15, 107, 92, 0.45);
  color: #fff;
  font-weight: var(--zy-weight-bold);
  font-size: clamp(1.05rem, 2.5vw, 1.2rem);
  border: 1px solid rgba(94, 207, 154, 0.35);
}

.kds-items li > span {
  min-width: 0;
  word-break: break-word;
}

.kds-items .notes {
  display: block;
  font-weight: var(--zy-weight-medium);
  font-size: var(--zy-text-sm);
  color: var(--zy-gold-soft);
  margin-top: 0.2rem;
}

.kds-siblings {
  font-size: var(--zy-text-sm);
  color: rgba(243, 239, 230, 0.7);
  line-height: var(--zy-leading-snug);
}

.kds-siblings .partial {
  color: #ffc978;
  font-weight: var(--zy-weight-semibold);
  margin-top: var(--zy-space-1);
}

.kds-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--zy-space-2);
}

.kds-actions .kds-btn.primary {
  flex: 1 1 100%;
  min-height: 3rem;
  font-size: var(--zy-text-md);
}

.kds-btn {
  appearance: none;
  border: 1px solid rgba(243, 239, 230, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #f3efe6;
  border-radius: var(--zy-radius-md);
  padding: 0.75rem 1rem;
  font: inherit;
  font-weight: var(--zy-weight-semibold);
  min-height: 2.75rem;
  cursor: pointer;
}

.kds-btn.primary {
  background: var(--zy-emerald);
  border-color: var(--zy-emerald);
  color: #fff;
}

.kds-btn.ghost {
  background: transparent;
}

.kds-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.kds-btn:focus-visible {
  outline: none;
  box-shadow: var(--zy-focus-ring-gold);
}

.kds-empty {
  color: rgba(243, 239, 230, 0.4);
  padding: var(--zy-space-4) var(--zy-space-1);
  font-size: var(--zy-text-sm);
}

.kds-dialog {
  border: 1px solid rgba(243, 239, 230, 0.2);
  border-radius: var(--zy-radius-lg);
  padding: 0;
  max-width: 26rem;
  width: calc(100% - 2rem);
  max-height: min(90dvh, 40rem);
  overflow: auto;
  background: #062e28;
  color: #f3efe6;
}

.kds-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.kds-dialog-body {
  margin: 0;
  padding: var(--zy-space-4);
  display: grid;
  gap: var(--zy-space-3);
}

.kds-dialog-body h2 {
  margin: 0;
  font-size: var(--zy-text-lg);
}

.kds-dialog-body label {
  display: grid;
  gap: var(--zy-space-1);
  font-size: var(--zy-text-sm);
}

.kds-dialog-body label.inline {
  display: flex;
  align-items: center;
  gap: var(--zy-space-2);
}

.kds-dialog-body input,
.kds-dialog-body select {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border-radius: var(--zy-radius-md);
  border: 1px solid rgba(243, 239, 230, 0.22);
  background: #041f1b;
  color: #f3efe6;
  min-height: 2.75rem;
}

.kds-dialog-line {
  font-weight: var(--zy-weight-bold);
  font-size: var(--zy-text-lg);
  margin: 0;
}

.kds-dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--zy-space-2);
  margin-top: var(--zy-space-1);
}

.kds-dialog-actions .kds-btn {
  flex: 1 1 auto;
  min-width: 6.5rem;
}

.muted {
  color: rgba(243, 239, 230, 0.7);
}

.tiny {
  font-size: var(--zy-text-xs);
}

.xfer-btn {
  flex-shrink: 0;
  min-height: 2.75rem;
  min-width: 5.5rem;
  padding: 0.45rem 0.75rem;
  font-size: var(--zy-text-sm);
}

/* Tablet portrait / phablet: single readable ticket stream */
@media (min-width: 768px) and (max-width: 1023px) {
  .kds-main {
    grid-template-columns: 1fr;
    max-width: 40rem;
    margin: 0 auto;
  }

  .kds-card {
    padding: var(--zy-space-4);
  }

  .kds-actions .kds-btn.primary {
    flex: 1 1 auto;
    min-width: min(12rem, 100%);
  }
}

/* Landscape tablet / small desktop: three status lanes */
@media (min-width: 1024px) {
  .kds-main {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: none;
    min-height: calc(100dvh - 4.5rem);
    align-items: stretch;
    gap: var(--zy-space-3);
  }

  .kds-col {
    overflow: auto;
    max-height: calc(100dvh - 5.5rem);
  }

  .kds-col h2 {
    background: #062e28;
  }
}

/* Large desktop: more breathing room */
@media (min-width: 1440px) {
  .kds-main {
    gap: var(--zy-space-4);
    padding: var(--zy-space-4);
  }

  .kds-col {
    max-height: calc(100dvh - 5.75rem);
  }
}

@media (max-width: 360px) {
  .kds-main {
    padding-left: var(--zy-space-2);
    padding-right: var(--zy-space-2);
  }

  .kds-items li {
    flex-direction: column;
    align-items: stretch;
  }

  .xfer-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.kds *,
  body.kds *::before,
  body.kds *::after {
    animation: none !important;
    transition: none !important;
  }
}
