/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens — identical hues to ERP globals.css (light mode only) ──── */
/* Default = indigo (no unit selected yet) */
:root {
  --primary:          oklch(0.716 0.167 260);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 260);
  --navbar-bg:        oklch(0.48  0.16  260);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0.005 260);
  --muted-fg:         oklch(0.412 0.02  260);
  --border-color:     oklch(0.843 0.006 260);
  --ring:             oklch(0.631 0.193 260);
}

[data-theme="amber"] {
  --primary:          oklch(0.716 0.167 90);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 90);
  --navbar-bg:        oklch(0.82  0.19  90);
  --navbar-fg:        oklch(0.2   0.05  90);
  --muted:            oklch(0.922 0.005 90);
  --muted-fg:         oklch(0.412 0.02  90);
  --border-color:     oklch(0.843 0.006 90);
  --ring:             oklch(0.631 0.193 90);
}

[data-theme="blue"] {
  --primary:          oklch(0.716 0.167 239);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 239);
  --navbar-bg:        oklch(0.48  0.16  239);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0.005 239);
  --muted-fg:         oklch(0.412 0.02  239);
  --border-color:     oklch(0.843 0.006 239);
  --ring:             oklch(0.631 0.193 239);
}

[data-theme="green"] {
  --primary:          oklch(0.716 0.167 142);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 142);
  --navbar-bg:        oklch(0.48  0.16  142);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0.005 142);
  --muted-fg:         oklch(0.412 0.02  142);
  --border-color:     oklch(0.843 0.006 142);
  --ring:             oklch(0.631 0.193 142);
}

[data-theme="orange"] {
  --primary:          oklch(0.716 0.167 34.697);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 34.697);
  --navbar-bg:        oklch(0.48  0.16  34.697);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0.005 251.498);
  --muted-fg:         oklch(0.412 0.02  251.802);
  --border-color:     oklch(0.843 0.006 251.504);
  --ring:             oklch(0.631 0.193 29.743);
}

[data-theme="violet"] {
  --primary:          oklch(0.716 0.167 280);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0.025 280);
  --navbar-bg:        oklch(0.48  0.16  280);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0.005 280);
  --muted-fg:         oklch(0.412 0.02  280);
  --border-color:     oklch(0.843 0.006 280);
  --ring:             oklch(0.631 0.193 280);
}

[data-theme="slate"] {
  --primary:          oklch(0.716 0 0);
  --primary-fg:       oklch(1 0 180);
  --primary-light:    oklch(0.955 0 0);
  --navbar-bg:        oklch(0.48  0 0);
  --navbar-fg:        oklch(1 0 180);
  --muted:            oklch(0.922 0 0);
  --muted-fg:         oklch(0.412 0 0);
  --border-color:     oklch(0.843 0 0);
  --ring:             oklch(0.631 0 0);
}

/* ── App design tokens (reference theme vars above) ──────────────────────── */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #f0f0f5;
  --border: var(--border-color, #e0e0e8);
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-xs: #9ca3af;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --h-header: 56px;
  --h-safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body { overflow: hidden; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  height: var(--h-header);
  padding: 0 16px;
  background: var(--navbar-bg);
  color: var(--navbar-fg);
  flex-shrink: 0;
  gap: 12px;
  padding-top: env(safe-area-inset-top, 0px);
  transition: background 0.35s ease;
}

#header-back {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  display: none;
  line-height: 1;
}

#header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

#header-user {
  font-size: 13px;
  color: rgba(255,255,255,0.65);
  white-space: nowrap;
}

#header-logout {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
#header-logout:active { background: rgba(255,255,255,0.2); }

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(20px + var(--h-safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ── Auth Screen ──────────────────────────────────────────────────────────── */
#screen-login {
  justify-content: center;
  align-items: center;
  background: var(--navbar-bg);
  padding: 32px 24px;
}

.login-logo {
  text-align: center;
  margin-bottom: 40px;
  color: #fff;
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.login-logo p {
  font-size: 14px;
  color: rgba(255,255,255,0.55);
  margin-top: 4px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Form elements ────────────────────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  font-size: 16px; /* prevents zoom on iOS */
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus { border-color: var(--primary); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.85; transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: var(--surface2); color: var(--text); }
.btn-sm {
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  width: auto;
}

/* ── Unit picker ──────────────────────────────────────────────────────────── */
.unit-picker-header {
  padding: 32px 24px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.unit-picker-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.unit-picker-welcome {
  font-size: 17px;
  color: var(--text);
  margin-bottom: 4px;
}

.unit-picker-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.unit-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.unit-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: var(--shadow);
}
.unit-card:active { background: var(--surface2); }
.unit-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.unit-card-dot {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.unit-card.active .unit-card-dot {
  background: var(--primary);
  color: #fff;
}

.unit-card-info { flex: 1; min-width: 0; }
.unit-card-name { font-size: 15px; font-weight: 600; color: var(--text); }
.unit-card-slug { font-size: 12px; color: var(--text-muted); font-family: monospace; margin-top: 2px; }

.unit-card-check {
  font-size: 18px;
  color: var(--primary);
  opacity: 0;
  transition: opacity 0.15s;
}
.unit-card.active .unit-card-check { opacity: 1; }

/* Header unit button */
.header-unit-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-unit-btn:active { background: rgba(255,255,255,0.25); }

/* ── Menu Screen ──────────────────────────────────────────────────────────── */
#screen-menu {
  padding: 20px 16px;
  gap: 12px;
}

.menu-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-xs);
  padding: 0 4px;
  margin-top: 8px;
  margin-bottom: 4px;
}

.menu-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.menu-card:active { background: var(--surface2); }

.menu-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.menu-icon.indigo { background: var(--primary-light); }

.menu-card-text h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.menu-card-text p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Yarn Issue Screen ────────────────────────────────────────────────────── */
#screen-yarn-issue {
  padding: 0;
}

.yi-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.yi-section:last-child { border-bottom: none; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-xs);
  margin-bottom: 10px;
}

/* BJO info card */
.bjo-card {
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
}

.bjo-card-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.bjo-card-row:last-child { margin-bottom: 0; }
.bjo-label { color: var(--text-muted); min-width: 72px; flex-shrink: 0; }
.bjo-value { color: var(--text); font-weight: 500; }
.bjo-mono  { font-family: 'SF Mono', 'Courier New', monospace; }

/* Yarn lot rows */
.yarn-lot {
  margin-bottom: 12px;
}
.yarn-lot:last-child { margin-bottom: 0; }

.yarn-lot-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.yarn-lot-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.yarn-lot-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.lot-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.lot-badge-ok      { background: var(--success-light); color: var(--success); }
.lot-badge-warn    { background: var(--warning-light); color: var(--warning); }
.lot-badge-default { background: var(--surface2); color: var(--text-muted); }

/* Progress bar */
.issue-progress {
  height: 5px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 10px;
}
.issue-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.3s;
}
.issue-progress-fill.done { background: var(--success); }
.issue-progress-fill.over { background: var(--danger); }

/* Scanner area */
.scanner-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  background: var(--surface2);
  margin-bottom: 10px;
}

.scanner-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.scanner-btn:active { opacity: 0.9; }
.scanner-btn-icon { font-size: 22px; }

/* Bag list */
.bag-list { display: flex; flex-direction: column; gap: 8px; }

/* Per-yarn-group bag/box accordion (closed by default) */
.bag-accordion { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.bag-accordion-summary {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; cursor: pointer; list-style: none;
  background: var(--surface2); font-size: 13px; user-select: none;
}
.bag-accordion-summary::-webkit-details-marker { display: none; }
.bag-accordion-chevron { transition: transform 0.15s ease; color: var(--text-muted); }
.bag-accordion[open] .bag-accordion-chevron { transform: rotate(90deg); }
.bag-accordion-title { font-weight: 600; }
.bag-accordion-sel { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.bag-accordion .bag-list { padding: 10px 12px; }

.bag-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1.5px solid transparent;
}

.bag-item.selected {
  background: var(--primary-light);
  border-color: #818cf8;
}

.bag-item-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  cursor: pointer;
  color: transparent;
  background: var(--surface);
  transition: all 0.15s;
}
.bag-item.selected .bag-item-check {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.bag-item-info { flex: 1; min-width: 0; }
.bag-item-code { font-size: 18px; font-weight: 700; font-family: 'SF Mono', monospace; }
.bag-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.bag-item-cones {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.cone-input {
  width: 70px;
  padding: 6px 8px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  border-radius: 6px;
  border: 1.5px solid var(--border);
}
.bag-item.selected .cone-input { border-color: #818cf8; }
.cone-max { font-size: 11px; color: var(--text-xs); }

/* Bottom action bar */
.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--h-safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
}

/* Save Draft + Confirm & Issue side by side. When Confirm is hidden
   (display:none, before the draft is saved) Save spans the full width. */
.yi-action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.yi-action-buttons:has(> button[style*="display:none"]),
.yi-action-buttons:has(> button[style*="display: none"]) {
  grid-template-columns: 1fr;
}
.yi-action-buttons > .btn { margin: 0; }

.action-bar-summary {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 2px;
}

.action-bar-summary strong { color: var(--text); }

/* ── Inline scanner widget ────────────────────────────────────────────────── */
.inline-scanner {
  margin-top: 10px;
  border-radius: 0px;
  overflow: hidden;
  background: #111;
  /* Stick to the top of the scrolling screen: scrolls with the page until it
     reaches the top, then stays pinned while the yarn lots scroll underneath.
     Scrolling back up lets it return to normal flow. */
  position: sticky;
  top: 0;
  z-index: 20;
  height: 40vh;
  display: flex;
  flex-direction: column;
}

.inline-scanner video {
  width: 100%;
  flex: 1;            /* fill the box above the controls bar */
  display: block;
  min-height: 0;
  object-fit: cover;
}

/* scanning line animation inside the inline box */
.inline-scanner-line {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  pointer-events: none;
  display: none;
}
.inline-scanner.active .inline-scanner-line { display: block; animation: scan 2s linear infinite; }
.inline-scanner.paused .inline-scanner-line { display: block; animation: scan 2s linear infinite; animation-play-state: paused; opacity: 0.3; }

@keyframes scan {
  0%   { top: 0%; }
  100% { top: 100%; }
}

/* corner frame */
.inline-scanner-frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.inline-scanner-frame::before, .inline-scanner-frame::after,
.inline-scanner-frame > span::before, .inline-scanner-frame > span::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-color: #fff;
  border-style: solid;
}
.inline-scanner-frame::before  { top: 8px;  left: 8px;  border-width: 2px 0 0 2px; border-radius: 2px 0 0 0; }
.inline-scanner-frame::after   { top: 8px;  right: 8px; border-width: 2px 2px 0 0; border-radius: 0 2px 0 0; }
.inline-scanner-frame > span::before { bottom: 8px; left: 8px;  border-width: 0 0 2px 2px; border-radius: 0 0 0 2px; }
.inline-scanner-frame > span::after  { bottom: 8px; right: 8px; border-width: 0 2px 2px 0; border-radius: 0 0 2px 0; }

/* placeholder shown when paused and no video yet */
.inline-scanner-paused-msg {
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: rgba(255,255,255,0.55);
  background: #111;
  padding: 28px 16px;
}
.inline-scanner.paused .inline-scanner-paused-msg { display: flex; flex: 1; }
/* when paused, the (empty) video shouldn't take space — the message fills the box */
.inline-scanner.paused video { display: none; }
/* hide the paused msg once stream is active (video has content) */
.inline-scanner.active .inline-scanner-paused-msg { display: none; }

/* controls bar below video */
.inline-scanner-controls {
  position: absolute;
  bottom:0px;
  left:0px;
  display: flex;
  width:100%;
  padding: 0px 8px 8px 8px;
  background: transparent;
}

.inline-scanner-toggle {
  flex: 1;
  padding: 10px 6px;
  font-size: 20px;
  font-weight: 900;
  border: 1px solid #FFFFFF99;
  border-radius: 0px;
  /* background: var(--primary); */
  background: #FFFFFF66;
  color: #fff;
  cursor: pointer;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  min-width: 280px;
  max-width: 90vw;
}

.toast {
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  animation: toast-in 0.25s ease;
  text-align: center;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast-info    { background: var(--text);    color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.dark {
  border-color: color-mix(in oklch, var(--primary) 20%, transparent);
  border-top-color: var(--primary);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state-text  { font-size: 14px; }

/* ── Error banner ─────────────────────────────────────────────────────────── */
.error-banner {
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--danger);
  margin: 12px 0;
}

/* ── Splash screen ────────────────────────────────────────────────────────── */
#splash-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--navbar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 48px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.splash-icon {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  box-shadow: 0 8px 32px color-mix(in oklch, var(--primary) 50%, transparent);
}

.splash-name {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.splash-sub {
  font-size: 14px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.02em;
}

/* Dot loader */
.splash-spinner {
  display: flex;
  gap: 8px;
  align-items: center;
}

.splash-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.splash-dot:nth-child(2) { animation-delay: 0.2s; }
.splash-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ── Install prompt ───────────────────────────────────────────────────────── */
#install-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(0,0,0,0.55);
  align-items: flex-end;
  justify-content: center;
}
#install-overlay.active { display: flex; }

.install-sheet {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 28px 24px;
  padding-bottom: calc(28px + var(--h-safe-bottom));
  animation: sheet-in 0.3s ease;
  text-align: center;
}

.install-app-icon {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  margin-bottom: 4px;
  box-shadow: 0 4px 16px color-mix(in oklch, var(--primary) 30%, transparent);
}

.install-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.install-msg {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.install-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.install-ios-steps {
  margin-top: 20px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: center;
}

.install-ios-steps strong { color: var(--text); }

.ios-share-icon {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  line-height: 22px;
  text-align: center;
  vertical-align: middle;
  margin: 0 2px;
}

/* ── Confirm dialog ───────────────────────────────────────────────────────── */
#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.5);
  align-items: flex-end;
  justify-content: center;
}
#confirm-overlay.active {
  display: flex;
}

.confirm-sheet {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--h-safe-bottom));
  animation: sheet-in 0.25s ease;
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.confirm-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.confirm-msg {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.confirm-actions { display: flex; flex-direction: column; gap: 10px; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-center { text-align: center; }
.mono { font-family: 'SF Mono', 'Courier New', monospace; }
.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
}
.chip-blue { background: var(--primary-light); color: var(--primary); }
.chip-green { background: var(--success-light); color: var(--success); }
.chip-red { background: var(--danger-light); color: var(--danger); }

/* ── BJO selector card list (Yarn Issue Step 2) ──────────────────────────── */
.bjo-select-list { display: flex; flex-direction: column; align-items: stretch; gap: 6px; max-height: 340px; overflow-y: auto; }
.bjo-select-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.bjo-select-item {
  display: flex; flex-direction: column; gap: 4px;
  /* width:100% alone isn't honoured for <button> flex items on iOS Safari —
     align-self:stretch forces full-width; box-sizing is border-box globally. */
  width: 100%; align-self: stretch; box-sizing: border-box;
  text-align: left; cursor: pointer; font: inherit;
  background: var(--surface2); border: 1.5px solid transparent;
  border-radius: var(--radius-sm); padding: 10px 12px;
  -webkit-tap-highlight-color: transparent; -webkit-appearance: none; appearance: none;
}
.bjo-select-item.selected { background: var(--primary-light); border-color: var(--primary); }
.bjo-select-item:active { opacity: 0.9; }
.bjo-select-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bjo-select-number { font-weight: 600; font-size: 14px; color: var(--text); }
.bjo-select-style { color: var(--text-muted); font-size: 13px; }
.bjo-select-tick { margin-left: auto; color: var(--primary); font-weight: 700; }
.bjo-yarn-summary { display: flex; flex-direction: column; gap: 3px; }
.bjo-grp-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.bjo-grp-label { font-size: 10px; font-weight: 700; color: var(--text-muted); }
.bjo-grp-ends { font-size: 10px; color: var(--text-muted); }
.bjo-select-change-hint { text-align: center; font-size: 11px; color: var(--text-muted); padding: 4px 0 0; }

/* ── Reserved / cert / stock-type badges ─────────────────────────────────── */
.bag-item.bag-reserved { opacity: 0.55; }
.reserved-label { font-size: 11px; color: #b45309; margin-top: 2px; }
.free-cones-label { font-size: 11px; color: #2563eb; margin-top: 2px; }

.cert-badge {
  display: inline-flex;
  align-items: center;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: #166534;
  color: #bbf7d0;
  margin-left: 4px;
  vertical-align: middle;
}

.stock-type-badge {
  display: inline-flex;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: middle;
}
.stock-fresh   { background: #dbeafe; color: #1d4ed8; }
.stock-rewind  { background: #ede9fe; color: #6d28d9; }
.stock-cut     { background: #ffedd5; color: #c2410c; }

/* ── Yarn Transfer: type buttons ─────────────────────────────────────────── */
.type-button-group { display: flex; flex-direction: column; gap: 8px; }

.type-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--border-color);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.type-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
}
.type-btn-label { font-size: 14px; font-weight: 600; color: var(--text); }
.type-btn-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Yarn Transfer: form rows ────────────────────────────────────────────── */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.form-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border-color);
  background: var(--surface);
  font-size: 15px;
  color: var(--text);
  outline: none;
}
.form-input:focus { border-color: var(--primary); }
.form-input-sm {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1.5px solid var(--border-color);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  width: 100%;
}

/* ── Yarn Transfer: manual input row ─────────────────────────────────────── */
.manual-input-row { display: flex; gap: 8px; align-items: center; }
.manual-input-row .form-input { flex: 1; }

/* ── Yarn Transfer: bag rows ─────────────────────────────────────────────── */
.transfer-bag-row {
  border: 1.5px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface);
}
.transfer-bag-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.transfer-bag-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.transfer-field { display: flex; flex-direction: column; gap: 3px; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 14px;
  border-radius: 6px;
  line-height: 1;
}
.btn-remove { color: #dc2626; }
.btn-remove:hover { background: #fee2e2; }

.btn-outline {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}


/* ── Yarn Transfer — radio group + form hint ── */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.radio-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.radio-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.radio-label span {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border, #d1d5db);
  color: var(--text-muted);
  background: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}
.radio-label input[type="radio"]:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Yarn Transfer status badge ── */
.yt-status-badge {
  margin: 12px 0;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}
.yt-status-draft {
  background: #fef3c7;
  color: #92400e;
  border: 1.5px solid #fcd34d;
}
.yt-status-confirmed {
  background: #d1fae5;
  color: #065f46;
  border: 1.5px solid #6ee7b7;
}
.yt-badge-no {
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ── YT Draft List ── */
.yt-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
  margin-bottom: 12px;
}
.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 8px;
}
.yt-draft-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 16px;
}
.yt-list-loading,
.yt-list-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 0;
}
.yt-draft-card {
  background: var(--card-bg, #fff);
  border: 1.5px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.yt-draft-card:active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.yt-draft-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.yt-draft-number {
  font-family: monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}
.yt-draft-date {
  font-size: 12px;
  color: var(--text-muted);
}
.yt-draft-type {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.yt-draft-reason {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.yt-draft-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Weft Yarn Issue — collapsible yarn/lot groups ───────────────────────── */
.wi-group { margin-bottom: 8px; }
.wi-group-yarn {
  border: 1.5px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}
.wi-group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  background: var(--muted);
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}
.wi-lot-head {
  background: transparent;
  border-top: 1px solid var(--border-color);
  padding-left: 20px;
  font-size: 13px;
}
.wi-caret { width: 14px; flex-shrink: 0; color: var(--text-muted); font-size: 12px; }
.wi-group-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wi-group-total { flex-shrink: 0; font-weight: 700; font-size: 12px; color: var(--primary); white-space: nowrap; }
.wi-group-lot { margin: 0; }
.wi-group-lot .transfer-bag-row { margin: 8px 12px; }
.wi-st-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}
.wi-st-fresh  { background: #d1fae5; color: #065f46; }
.wi-st-rewind { background: #fef3c7; color: #92400e; }
.wi-st-cut    { background: #dbeafe; color: #1e40af; }

/* ── Roll Weight (scan sticker → enter weight) ───────────────────────────── */
.rw-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.rw-empty-icon { font-size: 40px; margin-bottom: 12px; }

/* One weighed piece in the batch list */
.rw-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
/* Scanned but not yet weighed — the row still needs the operator */
.rw-row-pending { border-style: dashed; border-color: var(--warning); }

.rw-row-main { flex: 1; min-width: 0; }
.rw-row-label {
  font-weight: 700;
  font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rw-row-meta  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.rw-row-where { font-size: 11px; color: var(--text-xs);    margin-top: 1px; }

.rw-row-weight {
  flex-shrink: 0;
  text-align: right;
  min-width: 76px;
  font-size: 12px;
  color: var(--text-muted);
}
.rw-row-weight strong { display: block; font-size: 19px; color: var(--primary); line-height: 1.1; }
.rw-row-tap { color: var(--warning); font-weight: 600; }

.rw-row-remove {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--muted);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

/* ── Bottom sheets (piece picker + weight entry) ─────────────────────────── */
.rw-sheet { position: fixed; inset: 0; z-index: 90; }
.rw-sheet.hidden { display: none; }
.rw-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.rw-sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + var(--h-safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
}
.rw-sheet-title { font-size: 18px; font-weight: 700; }
.rw-sheet-sub   { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.rw-prev        { color: var(--warning); font-weight: 600; }
.rw-sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.rw-sheet-actions .btn { flex: 1; }

/* Piece picker — one button per piece behind the scanned roll number */
.rw-piece-list { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.rw-piece-btn {
  width: 100%;
  padding: 12px;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.rw-piece-label { font-weight: 700; font-size: 15px; }
.rw-piece-meta  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.rw-piece-where { font-size: 11px; color: var(--text-xs);    margin-top: 1px; }

/* Weight field — big target, native numeric keypad via inputmode */
.rw-weight-field {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 18px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
}
.rw-weight-field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 38px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  /* Kill the spinner arrows some browsers add, which steal tap area */
  -moz-appearance: textfield;
}
.rw-weight-field input::-webkit-outer-spin-button,
.rw-weight-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rw-weight-unit { font-size: 18px; font-weight: 600; color: var(--text-muted); }
