:root {
  --primary: #0f6e8c;
  --primary-dark: #0b5468;
  --accent: #f2a516;
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1e2733;
  --text-muted: #6b7684;
  --border: #e1e6ea;
  --danger: #d9534f;
  --success: #2e8b57;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Topbar ---------- */
.pull-refresh-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  text-align: center;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  color: white;
  background: var(--primary-dark);
  transform: translateY(-100%);
  transition: transform 0.15s ease-out;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 18px;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
a.icon-btn {
  display: inline-block;
  text-decoration: none;
  line-height: 1;
}
.icon-btn:active { background: rgba(255,255,255,0.3); }
.icon-btn.lock-active {
  background: var(--accent);
}

/* ---------- Layout ---------- */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 60px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 14px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  padding: 13px 16px;
  border: none;
  cursor: pointer;
  transition: transform 0.05s ease-in;
}
.btn:active { transform: scale(0.98); }

.btn-block { width: 100%; margin-bottom: 10px; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:active { background: var(--primary-dark); }

.btn-outline {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-secondary {
  background: var(--accent);
  color: #3a2900;
}

.btn-small { padding: 9px 12px; font-size: 13px; white-space: nowrap; }

.btn-text {
  background: none;
  color: var(--primary);
  font-size: 14px;
  padding: 4px 8px;
}

.btn-danger {
  background: var(--danger);
  color: white;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 8px;
}

/* ---------- Fields ---------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  font-size: 15px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--bg);
}

.field-row { margin-bottom: 14px; }

.vendor-row { display: flex; gap: 8px; }
.vendor-row select { flex: 1; }

.capture-row { display: flex; flex-direction: column; gap: 0; margin-top: 6px; }

.upload-status {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
  margin-top: 4px;
}

.candidate-picker {
  margin-top: 10px;
  padding: 10px;
  background: #eef3f6;
  border-radius: 10px;
}

.candidate-picker-inline {
  margin: 6px 0;
  padding: 8px;
  background: #eef3f6;
  border-radius: 8px;
}

.ocr-pending-label {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin: 2px 0 6px 0;
}

.candidate-picker-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.candidate-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.candidate-chip {
  background: white;
  border: 1.5px solid var(--primary);
  color: var(--primary-dark);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.candidate-chip:active { background: var(--primary); color: white; }
.candidate-chip.used {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text-muted);
  text-decoration: line-through;
  cursor: not-allowed;
}

/* ---------- Send Card ---------- */
.send-mode-row select, .send-mode-row input {
  margin-bottom: 10px;
}

.override-email {
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.override-email input { margin-top: 8px; }

.send-status {
  font-size: 13px;
  margin-top: 8px;
  white-space: pre-line;
}
.send-status.success { color: var(--success); }
.send-status.error { color: var(--danger); }

/* ---------- Vendor Groups / Entries ---------- */
.vendor-group {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  scroll-margin-top: 90px; /* clears the sticky top bar when scrolled into view */
}

.vendor-group-header {
  background: #0b5468;
  border-bottom: 4px solid #f2a516;
  padding: 14px 16px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.3px;
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 10px;
}

.vendor-group-header span span {
  font-weight: 500;
  font-size: 13px;
  color: #cfe3ea;
  margin-left: 4px;
}

.vendor-group-header .add-slip-header-btn {
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 8px;
}

.add-slip-header-btn {
  width: auto;
  font-size: 12px;
  padding: 6px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

.return-slip-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 6px;
}

.return-slip-entry .part-thumb {
  border-color: var(--accent);
}

.vendor-group-body {
  padding: 12px;
}

.part-entry {
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.part-entry:last-child { border-bottom: none; }

.part-entry-main {
  display: flex;
  gap: 12px;
}

.verify-card {
  border: 2px solid var(--primary);
}
.verify-card .card-title {
  color: var(--primary);
}
.verify-entry .part-thumb {
  width: 110px;
  height: 110px;
}
.verify-vendor-label {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
}

.secondary-photo-row {
  margin-top: 10px;
}
.secondary-photo-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.secondary-photo-row img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  display: block;
}

.add-box-photo-btn {
  margin-top: 10px;
  width: auto;
}

.secondary-prompt {
  margin-top: 10px;
  padding: 10px 12px;
  background: #eef3f6;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.secondary-prompt-text {
  font-size: 13px;
  color: var(--text);
}
.secondary-prompt-actions {
  display: flex;
  gap: 8px;
}
.secondary-prompt-actions button {
  width: auto;
  padding: 7px 12px;
  font-size: 12px;
}

.part-thumb {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  cursor: pointer;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  box-sizing: border-box;
}

.lightbox-overlay[hidden] {
  display: none !important;
}

.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.part-fields { flex: 1; min-width: 0; }
.part-fields input { margin-bottom: 6px; font-size: 14px; padding: 8px 10px; }
.qty-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 2px 8px 4px 0;
  vertical-align: middle;
}
.qty-select {
  display: inline-block;
  width: auto;
  min-width: 60px;
  padding: 6px 8px;
  font-size: 13px;
  margin-bottom: 6px;
  vertical-align: middle;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin: 6px 0 4px 0;
  width: fit-content;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: relative;
  width: 46px;
  height: 26px;
  background: #ccc;
  border-radius: 26px;
  transition: background 0.15s ease-in;
  flex-shrink: 0;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s ease-in;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .switch-slider {
  background: var(--primary);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}
.switch-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.part-fields .comment-input { font-size: 13px; }

.part-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.part-timestamp { font-size: 11px; color: var(--text-muted); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 20px 0;
  font-size: 14px;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-card h1 {
  font-size: 22px;
  color: var(--primary-dark);
  margin-bottom: 4px;
}

.subtitle { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }

.login-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}

.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: white;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}

.modal-header {
  position: sticky;
  top: 0;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header .icon-btn { background: var(--bg); color: var(--text); }

.modal-body { padding: 20px; }
.modal-body h3 { font-size: 14px; margin: 18px 0 8px 0; color: var(--primary-dark); }
.modal-body h3:first-child { margin-top: 0; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 8px 0; }

.vendor-manage-list { margin-bottom: 12px; }

.vendor-manage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.vendor-manage-actions {
  display: flex;
  gap: 6px;
}

.vendor-add-row { display: flex; gap: 8px; }
.vendor-add-row input { flex: 1; }

.user-add-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
