/* ============================================================
   Screens
   ============================================================ */

/* ── PIN Screen ── */
.pin-screen {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at top, var(--surface) 0%, var(--bg) 70%);
  position: relative;
  overflow-y: auto;  /* fallback: if content is taller than viewport, scroll */
  -webkit-overflow-scrolling: touch;
}
.pin-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  margin: auto;  /* keeps content centered even when scrollable */
}
.pin-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--info));
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #1A1810;
  box-shadow: var(--shadow-md);
}
.pin-title {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}
.pin-subtitle {
  color: var(--text-secondary);
  margin: 0 0 18px;
  font-size: 13px;
}
.pin-display {
  display: flex;
  justify-content: center;
  gap: var(--gap-md);
  margin-bottom: 18px;
  height: 40px;
  align-items: center;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-light);
  border: 2px solid var(--border);
  transition: all .15s;
}
.pin-dot.is-filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.1);
}
.pin-dot.is-error {
  background: var(--danger);
  border-color: var(--danger);
  animation: shake .4s ease;
}
@keyframes shake {
  0%, 100% { transform: scale(1.1) translateX(0); }
  25% { transform: scale(1.1) translateX(-6px); }
  75% { transform: scale(1.1) translateX(6px); }
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.pin-key {
  height: 56px;  /* reduced from 64 — fits 4 rows comfortably */
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-size: 21px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background .12s, transform .08s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pin-key:hover { background: var(--card-hover); }
.pin-key:active { transform: scale(0.94); }
.pin-key.is-action { color: var(--accent); font-size: 18px; }
.pin-key.is-clear { color: var(--danger); font-size: 14px; }
.pin-demo-hint {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-muted);
}

.pin-hint {
  margin-top: var(--gap-lg);
  font-size: 12px;
  color: var(--text-muted);
}
.pin-hint kbd {
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  color: var(--accent);
  font-family: var(--font-mono);
}

.pin-help-btn {
  position: absolute;
  top: calc(44px + 12px);  /* below the demo topbar (44px) + small gap */
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  z-index: 10;
  white-space: nowrap;
}
.pin-help-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}
/* Tablet/small desktop — keep label but compact */
@media (max-width: 560px) {
  .pin-help-btn {
    padding: 7px 12px;
    font-size: 12.5px;
    gap: 5px;
  }
}
/* Mobile — icon-only, away from logo */
@media (max-width: 480px) {
  .pin-help-btn span:not(.icon) { display: none; }
  .pin-help-btn {
    padding: 8px;
    width: 36px;
    height: 36px;
    justify-content: center;
    top: calc(44px + 10px);
    right: 10px;
  }
}

/* ── Shift screen ── */
.shift-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: var(--gap-xl);
  text-align: center;
  background: radial-gradient(ellipse at top, var(--surface) 0%, var(--bg) 70%);
}
.shift-icon {
  font-size: 64px;
  color: var(--accent);
  margin-bottom: var(--gap-lg);
}
.shift-title { font-size: 22px; font-weight: 700; margin: 0 0 var(--gap-sm); }
.shift-sub { color: var(--text-secondary); margin: 0 0 var(--gap-xl); }
.shift-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--gap-xl);
  width: 100%;
  max-width: 380px;
  margin-bottom: var(--gap-xl);
}
.shift-info-row {
  display: flex;
  justify-content: space-between;
  padding: var(--gap-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.shift-info-row:last-child { border-bottom: none; }
.shift-info-row .label-col { color: var(--text-secondary); }

/* ── Tables grid ── */
.tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--gap-md);
  padding: var(--gap-lg);
  padding-bottom: calc(var(--gap-lg) + env(safe-area-inset-bottom, 0px) + 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  width: 100%;
  height: 100%;
  align-content: start;
  box-sizing: border-box;
}
@media (max-width: 480px) {
  .tables-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px) + 24px);
  }
}
.table-card {
  aspect-ratio: 1.05;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--gap-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, transform .1s, border-color .15s;
  position: relative;
}
@media (max-width: 480px) {
  .table-card {
    padding: 8px;
    aspect-ratio: 1.15;     /* slightly less square — saves vertical space */
  }
  .table-card .table-num { font-size: 22px; }
  .table-card .table-status { font-size: 9.5px; letter-spacing: 0.3px; }
  .table-card .table-total { font-size: 11px; }
}
.table-card:active { transform: scale(0.97); }
.table-card.is-free {
  border-color: var(--success);
}
.table-card.is-occupied {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.table-card.is-locked {
  border-color: var(--text-muted);
  opacity: 0.55;
  cursor: not-allowed;
}
.table-card .table-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
}
.table-card .table-status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}
.table-card.is-free .table-status { color: var(--success); }
.table-card.is-occupied .table-status { color: var(--accent); }
.table-card.is-locked .table-status { color: var(--text-muted); }
.table-card .table-total {
  margin-top: var(--gap-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-light);
}
.table-card .lock-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--text-muted);
}

/* ── Order screen ── */
.order-screen {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.order-sidebar {
  width: 110px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.cat-item {
  padding: 16px 8px;
  text-align: center;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background .15s, color .15s;
  line-height: 1.3;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  word-break: break-word;
}
.cat-item:hover { background: var(--surface-light); }
.cat-item.is-active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
  border-left: 3px solid var(--accent);
  padding-left: calc(var(--gap-sm) - 3px);
}

.order-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--gap-md);
  padding-bottom: calc(var(--gap-md) + env(safe-area-inset-bottom, 0px) + 16px);
}
.order-sidebar {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--gap-md);
}
.product-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-md);
  cursor: pointer;
  transition: background .15s, transform .1s, border-color .15s;
  position: relative;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.product-card:hover { background: var(--card-hover); border-color: var(--accent); }
.product-card:active { transform: scale(0.97); }
.product-card .product-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  color: var(--text-primary);
  margin-bottom: var(--gap-sm);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.product-card .product-price {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.product-card .product-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--info-bg);
  color: var(--info);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
/* Quantity badge — shows count in cart */
.product-card .product-qty-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--accent);
  color: #1A1810;
  font-size: 12px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(203,168,101,0.4);
  z-index: 2;
  font-family: var(--font-mono);
  letter-spacing: -0.3px;
}
/* Highlight cards that have items in cart */
.product-card.is-in-cart {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.product-card.is-in-cart .product-price {
  color: var(--accent-light);
  font-weight: 700;
}

/* Cart bottom bar — always sticks to bottom, respects safe-area-inset */
.cart-bottom-bar {
  background: var(--accent);
  color: #1A1810;
  padding: 12px var(--gap-lg);
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  cursor: pointer;
  transition: filter .15s;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
}
.cart-bottom-bar:hover { filter: brightness(1.06); }
.cart-bottom-bar:active { filter: brightness(0.95); }
.cart-bottom-bar .cart-count {
  background: rgba(0,0,0,0.25);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.cart-bottom-bar .cart-label {
  flex: 1;
  font-weight: 600;
}
.cart-bottom-bar .cart-total {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
}

/* Active group banner (family grouping) */
.family-banner {
  background: var(--accent-dim);
  border-bottom: 1px solid var(--accent);
  padding: 8px var(--gap-lg);
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  transition: background .15s;
}
.family-banner.is-empty {
  background: var(--surface-light);
  color: var(--text-secondary);
  border-bottom-color: var(--border);
  font-weight: 400;
}
.family-banner:hover { filter: brightness(1.1); }
.family-banner .label-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Responsive breakpoints — mobile-first, covers all phone sizes ── */

/* ALL phones up to 480px — Galaxy S25, iPhone 14, iPhone Plus, all Android */
@media (max-width: 480px) {
  /* Order screen — compact sidebar */
  .order-sidebar { width: 88px; }
  .cat-item {
    font-size: 11.5px;
    padding: 10px 6px;
    line-height: 1.25;
  }
  /* Products: 2-column grid that scales tight on small phones */
  .products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .product-card {
    padding: 10px;
    min-height: 78px;
  }
  .product-card .product-name { font-size: 13px; }
  .product-card .product-price { font-size: 12.5px; }
  .order-content { padding: 10px; }

  /* Cart bottom bar */
  .cart-bottom-bar { padding: 11px 14px; gap: 10px; }
  .cart-bottom-bar .cart-total { font-size: 14px; }
  .cart-bottom-bar .cart-label { font-size: 13px; }

  /* Family banner */
  .family-banner { padding: 7px 14px; font-size: 12.5px; }

  /* PIN keypad — fit nicely on mobile */
  .pin-screen { padding: 12px 16px; }
  .pin-card { max-width: 340px; }
  .pin-logo { width: 60px; height: 60px; font-size: 26px; margin-bottom: 10px; }
  .pin-title { font-size: 18px; }
  .pin-subtitle { font-size: 12.5px; margin-bottom: 14px; }
  .pin-display { height: 32px; margin-bottom: 14px; }
  .pin-dot { width: 12px; height: 12px; }
  .pin-keypad { gap: 8px; }
  .pin-key { height: 52px; font-size: 20px; }
  .pin-key.is-action { font-size: 16px; }
  .pin-demo-hint { margin-top: 12px; font-size: 10.5px; }

  /* Shift screen */
  .shift-screen { padding: 16px; }
  .shift-card { max-width: 100%; padding: 18px; }
  .shift-title { font-size: 19px; }
  .shift-icon { font-size: 52px; }
}

/* Short-height phones (landscape or older devices) */
@media (max-height: 700px) {
  .pin-logo { width: 56px; height: 56px; font-size: 24px; margin-bottom: 8px; }
  .pin-title { font-size: 17px; }
  .pin-subtitle { margin-bottom: 10px; }
  .pin-display { height: 28px; margin-bottom: 10px; }
  .pin-key { height: 46px; font-size: 19px; }
  .pin-keypad { gap: 7px; }
}

/* VERY small phones (iPhone SE, older Android, < 360px) */
@media (max-width: 359px) {
  .order-sidebar { width: 78px; }
  .cat-item { font-size: 10.5px; padding: 8px 4px; }
  .products-grid { gap: 6px; }
  .product-card { padding: 8px; min-height: 72px; }
  .pin-key { height: 54px; font-size: 18px; }
  .pin-logo { width: 56px; height: 56px; font-size: 24px; }
}

/* Final defensive layer: ANY portrait phone — guarantees PIN fits even on devices
   that report misleading viewport heights (iOS Safari, browser address bars, etc.) */
@media (max-width: 600px) and (orientation: portrait) {
  .pin-screen { padding: 8px 12px; }
  .pin-keypad { gap: 6px; }
  .pin-key {
    /* Cap height to a percentage of viewport so it ALWAYS fits */
    height: min(52px, 7vh);
    font-size: 19px;
  }
  .pin-logo {
    width: min(64px, 9vh);
    height: min(64px, 9vh);
    font-size: min(28px, 4.5vh);
    margin-bottom: min(12px, 1.5vh);
  }
  .pin-title { font-size: min(18px, 2.6vh); }
  .pin-subtitle { font-size: min(13px, 1.9vh); margin-bottom: min(14px, 2vh); }
  .pin-display { height: min(32px, 4.5vh); margin-bottom: min(14px, 2vh); }
  .pin-dot { width: min(13px, 1.7vh); height: min(13px, 1.7vh); }
  .pin-demo-hint { margin-top: min(12px, 1.6vh); }
}

/* Tablet portrait (Galaxy Tab, iPad Mini) */
@media (min-width: 600px) and (max-width: 899px) {
  .order-sidebar { width: 120px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* Tablet landscape + small desktop */
@media (min-width: 900px) {
  .order-sidebar { width: 140px; }
  .cat-item { font-size: 13px; padding: 14px 10px; }
  .tables-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
