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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 24px 24px 16px;
  text-align: center;
}
header h1 { font-size: 1.8rem; font-weight: 700; }
header .subtitle { margin-top: 4px; opacity: 0.85; font-size: 0.9rem; }

.sign-out-btn {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: rgba(255,255,255,0.0);
  border: none;
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 99px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: none;
}
.sign-out-btn:hover {
  color: var(--text);
  background: var(--border);
  box-shadow: none;
}
.sign-out-btn:active { transform: translateX(-50%) translateY(1px); }

/* ── Pill Nav ── */
.pill-nav {
  background: var(--primary);
  padding: 16px 0 0;
  display: flex;
  justify-content: center;
}
.pill-nav-inner {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  padding: 0 16px;
  justify-content: center;
}

.pill {
  padding: 8px 22px;
  border-radius: 99px;
  border: 2px solid rgba(255,255,255,0.4);
  background: transparent;
  color: rgba(255,255,255,0.8);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pill:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.pill.active {
  background: #fff;
  color: var(--primary);
  border-color: #fff;
}

/* ── Tab Views ── */
.tab-view {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}
.tab-view.hidden { display: none; }

/* ── Search Mode Bar ── */
.search-mode-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-mode-btn {
  padding: 8px 18px;
  border-radius: 99px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  box-shadow: var(--shadow);
}
.search-mode-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.search-mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.search-mode-panel { margin-bottom: 8px; }
.search-mode-panel.hidden { display: none; }

/* ── QR Scanner ── */
.scanner-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 1;
}
.scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.scanner-canvas { display: none; }
.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scanner-frame {
  width: 65%;
  aspect-ratio: 1;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
}
.scanner-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 12px;
}

/* ── NFC Panel ── */
.nfc-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  text-align: center;
}
.nfc-panel.hidden { display: none; }
.nfc-icon {
  font-size: 3.5rem;
  margin-bottom: 14px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.75; }
}
.nfc-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.nfc-sub {
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 300px;
}

/* Scan status feedback */
.scan-status {
  margin-top: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  min-height: 1.4em;
  text-align: center;
}
.scan-status.success { color: #16a34a; }
.scan-status.error   { color: var(--danger); }
.scan-status.info    { color: var(--primary); }

/* Manual NFC input */
#nfcManualInput {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: var(--surface);
  color: var(--text);
}
#nfcManualInput:focus { border-color: var(--primary); }

/* ── Search Tab ── */
.search-bar-wrap {
  margin-bottom: 0;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  font-size: 1.1rem;
  pointer-events: none;
  opacity: 0.5;
}

#searchInput {
  width: 100%;
  padding: 14px 44px 14px 42px;
  border-radius: 12px;
  border: 2px solid var(--border);
  font-size: 1rem;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  box-shadow: var(--shadow);
}
#searchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.clear-search-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 50%;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.clear-search-btn:hover { background: var(--border); color: var(--text); }

/* Search empty state */
.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 20px 40px;
  text-align: center;
  color: var(--muted);
}
.search-empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.6;
}
.search-empty-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.search-empty-sub {
  font-size: 0.9rem;
  max-width: 300px;
}

/* Search results list (inline, not dropdown) */
.search-results-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search-results-list.hidden { display: none; }

.search-result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 14px;
}
.search-result-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}
.search-result-card .result-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.search-result-card .result-icon {
  width: 48px; height: 48px;
  border-radius: 8px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.search-result-card .result-info { flex: 1; min-width: 0; }
.search-result-card .result-name { font-weight: 600; font-size: 0.95rem; }
.search-result-card .result-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.search-result-card .result-type-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.result-type-badge.type-bucket { background: #dbeafe; color: #1e40af; }
.result-type-badge.type-item   { background: #dcfce7; color: #166534; }

.search-no-results {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── Buckets Tab ── */
.tab-toolbar {
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.bucket-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.bucket-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  border: 2px solid transparent;
}
.bucket-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.bucket-card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }
.bucket-card .item-count { font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
.bucket-card .tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 0.72rem; padding: 2px 9px; border-radius: 99px; }
.nfc-tag { background: #dbeafe; color: #1e40af; }
.qr-indicator { background: #dcfce7; color: #166534; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ── Items Tab ── */
.all-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.all-item-row {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}
.all-item-row:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}
.all-item-row .item-thumb {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.all-item-row .item-thumb-placeholder {
  width: 52px; height: 52px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.all-item-row .item-info { flex: 1; min-width: 0; }
.all-item-row .item-info h4 { font-size: 0.95rem; font-weight: 600; }
.all-item-row .item-info .item-bucket-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}
.all-item-row .item-info p {
  font-size: 0.82rem;
  color: #94a3b8;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.items-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 0.95rem;
}
.items-empty .icon { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ── Buttons ── */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); box-shadow: none; }

.btn.primary {
  background: var(--primary);
  color: #fff;
}
.btn.primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.btn.secondary {
  background: #8fa3b1;
  color: #fff;
}
.btn.secondary:hover {
  background: #7a909e;
  box-shadow: 0 4px 12px rgba(143,163,177,0.45);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}
.btn.danger:hover {
  background: var(--danger-dark);
  box-shadow: 0 4px 12px rgba(220,38,38,0.35);
}

.btn.ghost {
  background: transparent;
  color: #475569;
  border: 1.5px solid #cbd5e1;
  box-shadow: none;
}
.btn.ghost:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: var(--text);
}

.btn.small { padding: 6px 16px; font-size: 0.8rem; border-radius: 99px; }

/* ── Modals ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-box.wide { max-width: 680px; }
.modal-box.narrow { max-width: 360px; }
.modal-box h2 { margin-bottom: 20px; font-size: 1.25rem; }

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}
.modal-box label .hint { font-weight: 400; color: #94a3b8; font-size: 0.8rem; }
.modal-box input[type="text"],
.modal-box textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
}
.modal-box input[type="text"]:focus,
.modal-box textarea:focus { border-color: var(--primary); }
.modal-box textarea { resize: vertical; }

.checkbox-row { flex-direction: row !important; align-items: center; gap: 10px !important; }
.checkbox-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Detail Modal ── */
.detail-header { margin-bottom: 16px; }
.detail-header h2 { font-size: 1.4rem; }
.detail-meta { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.qr-container { margin-top: 14px; display: inline-block; }
.qr-container canvas, .qr-container img { border: 1px solid var(--border); border-radius: 6px; }
.detail-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.detail-toolbar .btn { border-radius: 99px; padding: 8px 20px; }

/* ── Item List (inside bucket detail) ── */
.item-list { display: flex; flex-direction: column; gap: 12px; }

.item-card {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.item-thumb {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.item-thumb-placeholder {
  width: 72px; height: 72px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.item-info { flex: 1; min-width: 0; }
.item-info h4 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.item-info p { font-size: 0.85rem; color: var(--muted); white-space: pre-wrap; }
.item-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ── UPC field ── */
.upc-field-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.upc-field-wrap input[type="text"] { flex: 1; }

.upc-scanner-wrap {
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}
.upc-viewfinder {
  width: 100%;
  position: relative;
  background: #000;
  min-height: 160px;
}
.upc-viewfinder video {
  width: 100%;
  display: block;
  max-height: 220px;
  object-fit: cover;
}
.upc-viewfinder canvas { display: none; }
.upc-scanner-wrap .scanner-hint,
.upc-scanner-wrap .btn { padding: 8px 12px; display: block; text-align: center; }

/* Amazon button */
.amazon-btn {
  background: #ff9900;
  color: #111;
  border: none;
  font-weight: 700;
  border-radius: 8px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.amazon-btn:hover { background: #e68a00; }

/* On Order badge */
.on-order-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 6px 3px 10px;
  border-radius: 99px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  margin-top: 6px;
}
.on-order-cancel {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  color: #92400e;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s;
  font-weight: 700;
}
.on-order-cancel:hover { opacity: 1; }

/* Quantity lock — visual indicator on card (no button, set via edit form) */
.qty-controls.locked .qty-btn { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
.qty-lock-icon { font-size: 0.85rem; margin-left: 2px; opacity: 0.5; }

/* Lock toggle inside edit form */
.qty-lock-field-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qty-lock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  flex-direction: row !important;
  margin-bottom: 0 !important;
}
.qty-lock-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── Quantity controls ── */
.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.qty-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.qty-btn:hover { background: var(--bg); border-color: var(--primary); }
.qty-btn.minus:hover { border-color: var(--danger); }
.qty-count {
  font-size: 0.95rem;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
  color: var(--text);
}
.qty-count.low  { color: #d97706; }
.qty-count.zero { color: var(--danger); }
.qty-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 99px;
  background: #f1f5f9;
  color: var(--muted);
  border: 1px solid var(--border);
}
.qty-badge.low  { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.qty-badge.zero { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

#itemQuantity {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
}
#itemQuantity:focus { border-color: var(--primary); }

#orderMoreQty {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
  margin-top: 8px;
}
#orderMoreQty:focus { border-color: var(--primary); }

/* ── NFC field in bucket modal ── */
.nfc-field-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.nfc-field-wrap input[type="text"] {
  flex: 1;
}
.nfc-scan-btn {
  white-space: nowrap;
  flex-shrink: 0;
}
.nfc-scan-btn.scanning {
  background: var(--primary);
  color: #fff;
  animation: pulse-btn 1.2s ease-in-out infinite;
}
@keyframes pulse-btn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* ── Image Preview ── */
.image-preview {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: inline-block;
}
.image-preview img { display: block; max-width: 100%; }
.image-preview.hidden { display: none; }

/* ── Utility ── */
.hidden { display: none !important; }
