/* Somerset Stock Take — Design System
   Theme: Industrial Utility — dark, monospace, high contrast */

/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden; /* App shell — individual screens scroll */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--accent2); text-decoration: none; }

/* ─── CSS Custom Properties ─────────────────────────────────────────────────── */

:root {
  /* Colours */
  --bg:           #0f0f0f;
  --surface:      #1a1a1a;
  --surface2:     #242424;
  --border:       #2e2e2e;
  --accent:       #e8ff47;   /* Primary CTA — yellow-green */
  --accent2:      #47d4ff;   /* Secondary — cyan */
  --red:          #ff4747;   /* Destructive / errors */
  --orange:       #ff8c47;   /* Warnings, out-of-scope */
  --green:        #47ff8c;   /* Success, complete */
  --text:         #f0f0f0;
  --text-muted:   #888;
  --text-dim:     #555;

  /* Typography */
  --font-mono: 'DM Mono', 'Courier New', monospace;
  --font-sans: 'DM Sans', system-ui, sans-serif;

  /* Spacing scale */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Safe areas */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── Screen Container ──────────────────────────────────────────────────────── */

.screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen.active {
  display: flex;
}

.screen-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-md);
}

/* ─── Top Bar ───────────────────────────────────────────────────────────────── */

.top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 52px;
  flex-shrink: 0;
}

.top-bar-title {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

.top-bar-back {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 22px;
  cursor: pointer;
  padding: var(--space-xs);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  touch-action: manipulation;
}

/* ─── Department Badge ──────────────────────────────────────────────────────── */

.dept-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: white;
  white-space: nowrap;
}

.dept-badge[data-dept="Clothing"]                    { background: #4f7fff; }
.dept-badge[data-dept="Food - Products"]             { background: #ff7f4f; }
.dept-badge[data-dept="Stationery"]                  { background: #7fff4f; color: #0f0f0f; }
.dept-badge[data-dept="Food - Made on Site"]         { background: #ff4f7f; }
.dept-badge[data-dept="Pool - Products"]             { background: #4fffff; color: #0f0f0f; }
.dept-badge[data-dept="PA Cafe External"]            { background: #bf4fff; }
.dept-badge[data-dept="Book Fair KIP"]               { background: #ffbf4f; color: #0f0f0f; }
.dept-badge[data-dept="Somerset Storyfest"]          { background: #ff4fbf; }
.dept-badge[data-dept="Events Office"]               { background: #4fff7f; color: #0f0f0f; }
.dept-badge[data-dept="Pool - Tennis"]               { background: #ffff4f; color: #0f0f0f; }
.dept-badge[data-dept="Pool - Swim Club - Uniforms"] { background: #4fbfff; }
.dept-badge[data-dept="Token"]                       { background: #ff9f4f; color: #0f0f0f; }
.dept-badge[data-dept="Parents and Friends Association"] { background: #9f4fff; }

/* ─── Department Card ───────────────────────────────────────────────────────── */

.dept-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  touch-action: manipulation;
  user-select: none;
}

.dept-card:active { background: var(--surface2); }

.dept-card.selected {
  border-color: var(--accent);
  background: rgba(232, 255, 71, 0.06);
}

.dept-card .dept-name {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dept-card .dept-count {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-muted);
}

.dept-card .checkmark {
  color: var(--accent);
  font-size: 20px;
  display: none;
  margin-left: var(--space-sm);
}

.dept-card.selected .checkmark { display: block; }

/* ─── Admin Override Banner ─────────────────────────────────────────────────── */

.admin-override-banner {
  background: rgba(255, 140, 71, 0.15);
  border-bottom: 1px solid var(--orange);
  color: var(--orange);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 16px;
  text-align: center;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 14px 24px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  width: 100%;
  min-height: 52px;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.1s;
}

.btn-primary:active { opacity: 0.85; }

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 20px;
  font-family: var(--font-sans);
  font-size: 15px;
  width: 100%;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-secondary:active { background: var(--surface2); }

.btn-danger {
  background: var(--red);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 12px 20px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-danger:active { opacity: 0.85; }

/* ─── Inputs ────────────────────────────────────────────────────────────────── */

.input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  padding: 12px 16px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.input::placeholder { color: var(--text-dim); }

/* ─── Modal ─────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: none;
  align-items: flex-end;
}

.modal-overlay.open {
  display: flex;
}

.modal-sheet {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + var(--safe-bottom));
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.25s ease-out;
}

.modal-drag-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto var(--space-md);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  animation: toastIn 0.2s ease-out, toastOut 0.2s ease-in 1.8s forwards;
}

.toast.error   { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--orange); }
.toast.info    { border-left-color: var(--accent2); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ─── Session Card ──────────────────────────────────────────────────────────── */

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
  position: relative;
}

.session-card:active { background: var(--surface2); }

.session-card .card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.session-card .card-name {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card .card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.session-card .progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.session-card .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.status-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-badge.active   { background: rgba(232, 255, 71, 0.15); color: var(--accent); }
.status-badge.complete { background: rgba(71, 255, 140, 0.15); color: var(--green); }

/* ─── Product List Row ──────────────────────────────────────────────────────── */

.product-row {
  display: flex;
  align-items: center;
  padding: 12px var(--space-md);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  gap: var(--space-sm);
}

.product-row:active { background: var(--surface2); }

.product-row .product-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-row .product-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.product-row .counted-badge {
  background: rgba(71, 255, 140, 0.15);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.product-row .oos-badge {
  background: rgba(255, 140, 71, 0.15);
  color: var(--orange);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
}

/* ─── Progress Pill ─────────────────────────────────────────────────────────── */

.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.progress-pill .pill-count { color: var(--accent); font-weight: 600; }

/* ─── Section Headers ───────────────────────────────────────────────────────── */

.section-header {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* ─── Empty State ───────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  gap: var(--space-md);
}

.empty-state .empty-icon {
  font-size: 48px;
  opacity: 0.3;
}

.empty-state .empty-title {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.empty-state .empty-sub {
  font-size: 13px;
  color: var(--text-dim);
}

/* ─── Bottom Action Bar ─────────────────────────────────────────────────────── */

.bottom-bar {
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  display: flex;
  gap: var(--space-sm);
  flex-direction: column;
}

/* ─── Numeric Stepper ───────────────────────────────────────────────────────── */

.qty-stepper {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  justify-content: center;
}

.qty-stepper .stepper-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 22px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.qty-stepper .stepper-btn:active { background: var(--border); }

.qty-stepper .qty-input {
  width: 100px;
  text-align: center;
  font-size: 28px;
  font-family: var(--font-mono);
  font-weight: 600;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 8px;
  -webkit-appearance: none;
  appearance: textfield;
}

.qty-stepper .qty-input:focus { outline: none; border-color: var(--accent); }

/* ─── PIN Keypad ────────────────────────────────────────────────────────────── */

.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: var(--space-lg);
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: background 0.1s;
}

.pin-dot.filled { background: var(--accent); border-color: var(--accent); }

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 64px;
  font-size: 22px;
  font-family: var(--font-mono);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.pin-key:active { background: var(--surface2); }

/* ─── Warning States ────────────────────────────────────────────────────────── */

.wrong-dept-warning {
  background: rgba(255, 140, 71, 0.1);
  border: 1px solid var(--orange);
  border-radius: 8px;
  padding: var(--space-md);
  color: var(--orange);
  font-size: 14px;
  text-align: center;
  margin: var(--space-md);
}

.storage-warning-banner {
  background: rgba(255, 71, 71, 0.1);
  border-bottom: 1px solid var(--red);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 16px;
  text-align: center;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* ─── Divider & Utility ─────────────────────────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-md) 0;
}

.text-muted { color: var(--text-muted); }
.text-dim   { color: var(--text-dim); }
.text-mono  { font-family: var(--font-mono); }
.text-accent { color: var(--accent); }
.text-orange { color: var(--orange); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }

.hidden { display: none !important; }

/* ─── Mobile Touch Optimisations ─────────────────────────────────────────────── */

button, [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.scrollable {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Scanner Viewfinder ────────────────────────────────────────────────────── */

#scanner-viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  overflow: hidden;
  border-radius: 8px;
}

#reader {
  width: 100%;
  height: 100%;
}

.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: scanMove 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes scanMove {
  0%   { top: 15%; }
  50%  { top: 85%; }
  100% { top: 15%; }
}

.scanner-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}

.scanner-corner.tl { top: 12%; left: 12%; border-top-width: 3px; border-left-width: 3px; }
.scanner-corner.tr { top: 12%; right: 12%; border-top-width: 3px; border-right-width: 3px; }
.scanner-corner.bl { bottom: 12%; left: 12%; border-bottom-width: 3px; border-left-width: 3px; }
.scanner-corner.br { bottom: 12%; right: 12%; border-bottom-width: 3px; border-right-width: 3px; }
