/**
 * File: public/assets/css/kyn-gateway.css
 * Purpose: Styles the KYN Gateway front door, unified login board, same-document handoff, and build badge.
 *
 * Owns:
 * - Cream Gateway entrance.
 * - Huge navy logo state.
 * - Login board with original message-board structure + Staff / Manager tabs.
 *
 * Does NOT own:
 * - Workspace shell styling.
 * - FlowOS POS styling.
 * - Authentication logic.
 *
 * Build: HC001G.
 */

:root {
  --kyn-gateway-cream: #f7efd8;
  --kyn-gateway-cream-2: #fffaf0;
  --kyn-gateway-blue: #e8f7ff;
  --kyn-gateway-navy: #061f3f;
  --kyn-gateway-action: #1f6fb2;
  --kyn-gateway-muted: #64748b;
  --kyn-gateway-gold: #d8a83e;
  --kyn-gateway-red: #8b1e2d;
  --kyn-gateway-radius-lg: 18px;
  --kyn-gateway-radius-md: 14px;
  --kyn-gateway-radius-sm: 12px;
  --kyn-gateway-shadow: 0 20px 54px rgba(6, 31, 63, 0.14);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
}

body.kyn-gateway-body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--kyn-gateway-cream);
  color: var(--kyn-gateway-navy);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.kyn-gateway {
  min-height: 100vh;
  background: var(--kyn-gateway-cream);
}

.kyn-gateway-stage {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(42vh, 1fr) auto minmax(0, auto);
  place-items: center;
  padding: 28px;
}

.kyn-gateway-logo-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--kyn-gateway-navy);
  width: min(58vw, 580px);
  min-width: min(82vw, 300px);
  aspect-ratio: 1 / 1;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.kyn-gateway-logo-button:focus-visible {
  outline: 4px solid rgba(6, 31, 63, 0.34);
  outline-offset: 10px;
}

.kyn-gateway-logo-mark {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.kyn-gateway-logo-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.kyn-gateway-logo-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--kyn-gateway-navy);
  font-size: clamp(2rem, 8vw, 5rem);
  line-height: 1;
  font-weight: 950;
  letter-spacing: 0.04em;
  text-align: center;
}

.is-logo-image-loaded .kyn-gateway-logo-fallback { display: none; }
.is-logo-image-failed .kyn-gateway-logo-fallback { display: grid; }
.is-logo-image-failed .kyn-gateway-logo-image { display: none; }

.kyn-gateway-status {
  min-height: 24px;
  margin: 0 0 18px;
  color: #173a5f;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.kyn-gateway.is-login-visible .kyn-gateway-stage {
  display: grid;
  grid-template-rows: 1fr;
  align-content: center;
  justify-items: center;
  overflow: hidden;
}

.kyn-gateway.is-login-visible .kyn-gateway-logo-button,
.kyn-gateway.is-login-visible .kyn-gateway-status {
  display: none;
}

.kyn-gateway-login-board {
  width: min(1120px, calc(100vw - 34px));
  max-height: calc(100vh - 44px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  gap: 18px;
  align-items: stretch;
}

.kyn-gateway-message-board,
.kyn-gateway-pin-card {
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: var(--kyn-gateway-radius-lg);
  background: rgba(255, 255, 255, 0.66);
  box-shadow: var(--kyn-gateway-shadow);
  backdrop-filter: blur(12px);
}

.kyn-gateway-message-board {
  min-height: 520px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kyn-gateway-board-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.kyn-gateway-board-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.kyn-gateway-board-brand img {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.kyn-gateway-board-brand strong {
  color: var(--kyn-gateway-navy);
  font-size: 24px;
  font-weight: 950;
  letter-spacing: -0.04em;
}

.kyn-gateway-mode-pill {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 248, 235, 0.82);
  border: 1px solid rgba(216, 168, 62, 0.24);
  color: var(--kyn-gateway-navy);
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}

.kyn-gateway-message-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(6,31,63,.34) rgba(255,255,255,.28);
}

.kyn-gateway-message-card {
  width: 100%;
  min-height: 84px;
  border: 1px solid rgba(255,255,255,.88);
  border-radius: var(--kyn-gateway-radius-md);
  background: rgba(255,255,255,.62);
  color: inherit;
  display: grid;
  grid-template-columns: 6px minmax(0, 1fr) 84px;
  gap: 12px;
  align-items: center;
  text-align: left;
  padding: 11px 12px 11px 0;
  cursor: pointer;
}

.kyn-gateway-message-card:focus-visible {
  outline: 3px solid rgba(31,111,178,.22);
  outline-offset: 2px;
}

.kyn-gateway-message-accent {
  height: 100%;
  border-radius: 999px;
  background: var(--kyn-gateway-action);
}

.kyn-gateway-message-copy strong,
.kyn-gateway-message-empty strong {
  display: block;
  color: var(--kyn-gateway-navy);
  font-size: 16px;
  line-height: 1.12;
}

.kyn-gateway-message-copy small,
.kyn-gateway-message-empty small {
  display: block;
  margin-top: 6px;
  color: #344054;
  font-size: 13px;
  line-height: 1.32;
}

.kyn-gateway-message-meta {
  align-self: start;
  justify-self: end;
  text-align: right;
}

.kyn-gateway-message-meta em {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 6px;
  background: rgba(216,168,62,.20);
  color: var(--kyn-gateway-navy);
  font-size: 9px;
  font-style: normal;
  font-weight: 950;
}

.kyn-gateway-message-meta small {
  display: block;
  margin-top: 6px;
  color: var(--kyn-gateway-muted);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.kyn-gateway-message-empty {
  border: 1px dashed rgba(6,31,63,.20);
  border-radius: var(--kyn-gateway-radius-md);
  background: rgba(255,255,255,.54);
  padding: 18px;
}

.kyn-gateway-pin-panel {
  min-height: 520px;
}

.kyn-gateway-pin-card {
  min-height: 100%;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.86), rgba(242,251,255,.88));
}

.kyn-gateway-pin-head {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.kyn-gateway-pin-head img {
  width: 62px;
  height: 62px;
  object-fit: contain;
}

.kyn-gateway-pin-head strong {
  display: block;
  color: var(--kyn-gateway-navy);
  font-size: 22px;
  font-weight: 950;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.kyn-gateway-pin-head small {
  display: block;
  margin-top: 5px;
  color: var(--kyn-gateway-muted);
  font-size: 13px;
  font-weight: 850;
}

.kyn-gateway-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.kyn-gateway-tabs button,
.kyn-gateway-keypad button,
.kyn-gateway-noscript-submit {
  min-height: 46px;
  border: 1px solid rgba(6, 31, 63, 0.22);
  border-radius: var(--kyn-gateway-radius-sm);
  background: rgba(255, 255, 255, 0.82);
  color: var(--kyn-gateway-navy);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 16px rgba(6,31,63,.055);
}

.kyn-gateway-tabs button.is-active {
  background: var(--kyn-gateway-navy);
  color: var(--kyn-gateway-cream-2);
}

.kyn-gateway-pin-dots {
  display: flex;
  justify-content: center;
  gap: 9px;
  min-height: 18px;
  margin: 6px 0 12px;
}

.kyn-gateway-pin-dots span {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 1px solid rgba(6, 31, 63, 0.16);
  background: rgba(6, 31, 63, 0.10);
}

.kyn-gateway-pin-dots span.is-filled {
  background: var(--kyn-gateway-action);
  border-color: rgba(31,111,178,.38);
}

.kyn-gateway-error {
  min-height: 38px;
  margin: 0 0 10px;
  border-radius: var(--kyn-gateway-radius-sm);
  padding: 10px 11px;
  color: #415267;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
  background: rgba(255,255,255,.58);
  border: 1px solid rgba(255,255,255,.84);
  visibility: hidden;
}

.kyn-gateway-error.is-visible {
  visibility: visible;
  color: #8a3328;
  background: rgba(184,74,59,.12);
  border-color: rgba(184,74,59,.20);
}

.kyn-gateway-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

.kyn-gateway-keypad button {
  aspect-ratio: 1 / 1;
  min-height: 74px;
  font-size: 22px;
}

.kyn-gateway-keypad button:active { transform: translateY(1px); }
.kyn-gateway-keypad-utility { font-size: 14px !important; }

.kyn-gateway-pin-help {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--kyn-gateway-muted);
  font-size: 12px;
  font-weight: 850;
}

.kyn-gateway-pin-help span:first-child {
  color: var(--kyn-gateway-navy);
  font-weight: 950;
}

.kyn-gateway-noscript-pin {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  font-weight: 850;
}

.kyn-gateway-noscript-pin input {
  min-height: 44px;
  border: 1px solid rgba(6, 31, 63, 0.24);
  border-radius: var(--kyn-gateway-radius-sm);
  padding: 8px 10px;
  font: inherit;
}

.kyn-gateway-noscript-submit {
  width: 100%;
  margin-top: 10px;
}

.kyn-gateway-loading {
  margin-top: 14px;
  color: var(--kyn-gateway-navy);
  font-size: 0.98rem;
  font-weight: 900;
  text-align: center;
}

.kyn-gateway.is-loading .kyn-gateway-login-form,
.kyn-gateway.is-loading .kyn-gateway-tabs {
  opacity: 0.48;
  pointer-events: none;
}

.kyn-gateway-message-modal[hidden] { display: none !important; }

.kyn-gateway-message-modal {
  position: fixed;
  inset: 0;
  z-index: 2147482500;
  display: grid;
  place-items: center;
  padding: 18px;
}

.kyn-gateway-message-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3,14,28,.58);
  backdrop-filter: blur(6px);
}

.kyn-gateway-message-modal-card {
  position: relative;
  width: min(540px, calc(100vw - 28px));
  border-radius: var(--kyn-gateway-radius-lg);
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(255,255,255,.92);
  box-shadow: 0 26px 70px rgba(3,14,28,.32);
  overflow: hidden;
}

.kyn-gateway-message-modal-card header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid rgba(8,33,61,.10);
  background: rgba(255,255,255,.90);
}

.kyn-gateway-message-modal-card header small {
  display: block;
  color: var(--kyn-gateway-muted);
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.kyn-gateway-message-modal-card header strong {
  display: block;
  color: var(--kyn-gateway-navy);
  font-size: 18px;
}

.kyn-gateway-message-modal-card header button {
  min-width: 72px;
  min-height: 44px;
  border-radius: var(--kyn-gateway-radius-sm);
  border: 1px solid rgba(8,33,61,.18);
  background: var(--kyn-gateway-navy);
  color: #fff;
  font-weight: 950;
}

.kyn-gateway-message-modal-card p {
  margin: 0;
  padding: 18px;
  color: #344054;
  line-height: 1.45;
}

.kyn-build-badge {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 3px 8px;
  border: 1px solid rgba(6, 31, 63, 0.18);
  border-radius: 999px;
  background: rgba(255, 252, 242, 0.84);
  color: rgba(6, 31, 63, 0.72);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

@media (max-width: 900px) {
  body.kyn-gateway-body { overflow: auto; }
  .kyn-gateway-stage { padding: 16px; }
  .kyn-gateway-login-board {
    width: min(520px, calc(100vw - 24px));
    max-height: none;
    grid-template-columns: 1fr;
  }
  .kyn-gateway-message-board,
  .kyn-gateway-pin-panel { min-height: auto; }
  .kyn-gateway-message-list { max-height: 300px; }
}

@media (max-width: 640px) {
  .kyn-gateway-logo-button { width: min(84vw, 420px); }
  .kyn-gateway-message-board,
  .kyn-gateway-pin-card { padding: 14px; }
  .kyn-gateway-keypad button { min-height: 62px; }
  .kyn-gateway-board-brand img,
  .kyn-gateway-pin-head img { width: 50px; height: 50px; }
}

/*
 * HC001H — Gateway visual split + scroll safety hotfix.
 * Goal:
 * - State 1: huge logo only.
 * - State 2: login board only.
 * - Bad state blocked: huge logo + login board together.
 * - Allow page scroll when the login board is taller than the viewport.
 */
[hidden] {
  display: none !important;
}

body.kyn-gateway-body {
  min-height: 100svh;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

.kyn-gateway,
.kyn-gateway-stage {
  min-height: 100svh;
}

/* State 1 — entrance page: logo only. */
.kyn-gateway:not(.is-login-visible) .kyn-gateway-login-board {
  display: none !important;
}

.kyn-gateway:not(.is-login-visible) .kyn-gateway-logo-button {
  display: grid !important;
  width: clamp(280px, 46vw, 560px);
}

/* State 2 — login page: board only. */
.kyn-gateway.is-login-visible .kyn-gateway-logo-button,
.kyn-gateway.is-login-visible .kyn-gateway-status {
  display: none !important;
}

.kyn-gateway.is-login-visible .kyn-gateway-stage {
  display: grid;
  grid-template-rows: auto;
  place-items: center;
  align-content: center;
  justify-items: center;
  min-height: 100svh;
  padding: clamp(14px, 2.4vh, 28px);
  overflow: visible !important;
}

.kyn-gateway.is-login-visible .kyn-gateway-login-board {
  display: grid !important;
  width: min(1120px, calc(100vw - 34px));
  max-height: none !important;
}

/* Desktop height safety — keep PIN pad visible on laptop screens. */
@media (min-width: 901px) and (max-height: 840px) {
  .kyn-gateway.is-login-visible .kyn-gateway-stage {
    align-content: start;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .kyn-gateway-message-board,
  .kyn-gateway-pin-panel {
    min-height: 0 !important;
  }

  .kyn-gateway-message-board {
    max-height: calc(100svh - 32px);
  }

  .kyn-gateway-pin-card {
    min-height: 0 !important;
  }

  .kyn-gateway-board-brand img,
  .kyn-gateway-pin-head img {
    width: 52px;
    height: 52px;
  }

  .kyn-gateway-board-brand strong {
    font-size: 22px;
  }

  .kyn-gateway-pin-head {
    grid-template-columns: 52px minmax(0, 1fr);
    margin-bottom: 10px;
  }

  .kyn-gateway-pin-head strong {
    font-size: 20px;
  }

  .kyn-gateway-tabs {
    margin-bottom: 10px;
  }

  .kyn-gateway-pin-dots {
    margin: 4px 0 8px;
    min-height: 16px;
  }

  .kyn-gateway-error:not(.is-visible) {
    display: none;
  }

  .kyn-gateway-keypad {
    gap: 8px;
  }

  .kyn-gateway-keypad button {
    min-height: 62px;
  }

  .kyn-gateway-pin-help {
    margin-top: 10px;
  }
}

@media (max-width: 900px) {
  .kyn-gateway.is-login-visible .kyn-gateway-stage {
    align-content: start;
    place-items: start center;
  }
}
