/* ============================================================================
   On-screen numpad — shared between employee submission and inventory forms.
   Layout, key styling, error bar, focus/flash states all live here. Each
   consuming form supplies its own body.numpad-open rule for any
   form-specific layout shifts (e.g. inventory adds bottom padding so its
   sheet doesn't sit behind the keypad).
   ========================================================================== */

.numpad {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--bg-card);
  border-top: 2px solid var(--brand-primary);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.18);
  padding: var(--space-2) var(--space-3) var(--space-3);
  /* iPad safe-area inset (home indicator) */
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.numpad-context {
  text-align: center;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  padding: var(--space-1) var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-2);
  /* Allow up to two lines so long unit/assembly names stay legible
     instead of getting truncated mid-name with an ellipsis. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
  min-height: calc(1.25em * 2 + var(--space-1));
}

.numpad-context .ctx-kind {
  font-weight: 700;
  color: var(--brand-primary);
  margin-left: 0.4rem;
}

/* Error bar — surfaces validation errors hidden behind the numpad */
.numpad-error-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: 540px;
  margin: 0 auto var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-danger-soft);
  border: 1px solid var(--border-danger-soft);
  border-radius: var(--radius-md);
  color: var(--danger-600);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.numpad-error-bar:hover {
  background: color-mix(in srgb, var(--danger-600) 22%, transparent);
}
.numpad-error-icon { flex-shrink: 0; font-size: var(--text-lg); }
.numpad-error-text { flex: 1; min-width: 0; }
.numpad-error-cta {
  flex-shrink: 0;
  text-decoration: underline;
  font-weight: 700;
}
.numpad-error-bar.is-hidden { display: none; }

@keyframes np-flash {
  0%   { box-shadow: 0 0 0 0 var(--danger-600), 0 0 0 0 transparent; }
  35%  { box-shadow: 0 0 0 3px var(--danger-600), 0 0 0 8px var(--bg-danger-soft); }
  100% { box-shadow: 0 0 0 0 transparent, 0 0 0 0 transparent; }
}
.np-flash {
  animation: np-flash 1.2s ease-out;
  border-color: var(--danger-600);
}

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  max-width: 540px;
  margin: 0 auto;
}

.numpad-key {
  min-height: 56px;
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--surface-hi);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, transform 0.05s;
  touch-action: manipulation;
}

.numpad-key:active {
  background: var(--brand-primary);
  color: var(--text-inverse);
  transform: scale(0.97);
}

.numpad-key.numpad-back,
.numpad-key.numpad-tab,
.numpad-key.numpad-prev {
  font-size: var(--text-base);
  background: var(--bg-card);
}

.numpad-key.numpad-next {
  font-size: var(--text-base);
  background: var(--brand-primary);
  color: var(--text-inverse);
  border-color: var(--brand-primary);
}
.numpad-key.numpad-next:active { filter: brightness(1.1); }

/* Done is the primary terminal action — same cell size as the others but
   weighted heavier so it reads as the CTA at a glance. */
.numpad-key.numpad-done {
  font-size: var(--text-base);
  background: var(--success-600);
  color: var(--text-inverse);
  border-color: var(--success-600);
  border-width: 2px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* Stacked icon + caption layout used by ↔ (Switch), ◀ (Back), ▸ (Next),
   and ✓ (Done). The numpad cell is fixed-size, so a small caption fits
   under the icon without overflowing. */
.numpad-key.numpad-tab,
.numpad-key.numpad-prev,
.numpad-key.numpad-next,
.numpad-key.numpad-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  line-height: 1;
}
.numpad-key .numpad-key-icon {
  font-size: 1.4rem;
  line-height: 1;
}
.numpad-key.numpad-done .numpad-key-icon {
  font-size: 1.6rem;
}
.numpad-key .numpad-key-caption {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.92;
}

/* When the numpad is open, hide any sticky form-actions footer so it
   doesn't sit behind the keypad. Per-form CSS may add further shifts. */
body.numpad-open .form-actions { display: none; }

/* Active input highlighting — applied to whatever input has numpad focus */
.np-active {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 30%, transparent);
  background: color-mix(in srgb, var(--brand-primary) 8%, var(--bg-card));
}

/* Hide the optional "↔" tab key when the form doesn't use it */
.numpad.numpad-no-tab .numpad-tab { visibility: hidden; }

/* Hide the optional error bar slot when the form doesn't use it */
.numpad.numpad-no-error #numpad-error-bar { display: none !important; }
