/* ============================================
   Comic Scanner — Mobile-First Styles
   ============================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #222633;
  --bg-input: #2a2e3b;
  --accent: #4a9eff;
  --accent-hover: #6ab4ff;
  --accent-dim: rgba(74, 158, 255, 0.15);
  --success: #4caf50;
  --success-dim: rgba(76, 175, 80, 0.15);
  --warning: #ff9800;
  --warning-dim: rgba(255, 152, 0, 0.15);
  --danger: #f44336;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-dim: #5f6368;
  --border: #333845;
  --border-light: #404552;
  --shadow: rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* ---- Header ---- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(10px);
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header h1 span {
  color: var(--accent);
}

.header .badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
}

/* ---- Main Content ---- */
.main {
  padding: 16px;
  padding-bottom: 100px;
  max-width: 600px;
  margin: 0 auto;
}

/* ---- Mode Toggle ---- */
.mode-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 4px;
}

.mode-btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn[data-mode="pull"].active {
  background: var(--warning);
  color: #000;
}

/* ---- Scan Section ---- */
.scan-section {
  margin-bottom: 20px;
}

.scan-btn {
  width: 100%;
  padding: 18px 24px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.scan-btn.primary {
  background: var(--accent);
  color: #fff;
}

.scan-btn.primary:hover {
  background: var(--accent-hover);
}

.scan-btn.primary:active {
  transform: scale(0.98);
}

.scan-btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  margin-top: 10px;
}

.scan-btn .icon {
  font-size: 22px;
}

/* ---- Scanner View ---- */
.scanner-container {
  display: none;
  margin-bottom: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--accent);
  position: relative;
}

.scanner-container.active {
  display: block;
}

#scanner-view {
  width: 100%;
}

#scanner-view video {
  width: 100% !important;
  border-radius: var(--radius) !important;
}

.scanner-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: #fff;
  text-align: center;
  padding: 8px;
  font-size: 13px;
}

.cancel-scan {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Result Card ---- */
.result-card {
  display: none;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  animation: slideUp 0.3s ease;
}

.result-card.active {
  display: block;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
}

.result-cover {
  width: 80px;
  height: 120px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-input);
  flex-shrink: 0;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.3;
}

.result-meta {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.result-meta strong {
  color: var(--text-primary);
}

.result-price {
  display: inline-block;
  background: var(--success-dim);
  color: var(--success);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.result-picker {
  margin-bottom: 14px;
}

.result-picker label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.result-picker select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
}

/* ---- Location Input ---- */
.location-section {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.location-input-wrap {
  flex: 1;
}

.location-input-wrap label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.location-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.location-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.location-input::placeholder {
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.scan-location-btn {
  padding: 12px 14px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---- Quantity Controls ---- */
.quantity-section {
  margin-top: 14px;
}

.quantity-section label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.quantity-controls {
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 160px;
}

.qty-btn {
  width: 44px;
  height: 44px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.qty-btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.qty-btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.qty-btn:active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.quantity-input {
  width: 60px;
  height: 44px;
  text-align: center;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-left: none;
  border-right: none;
  font-size: 18px;
  font-weight: 700;
  -moz-appearance: textfield;
}

.quantity-input::-webkit-inner-spin-button,
.quantity-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quantity-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  z-index: 1;
  position: relative;
}

/* ---- Action Buttons ---- */
.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-confirm {
  background: var(--success);
  color: #fff;
}

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

.btn-cancel {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

/* ---- Inventory Table ---- */
.inventory-section {
  margin-top: 24px;
}

.inventory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.inventory-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.export-btn {
  padding: 8px 16px;
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.export-btn:hover {
  background: var(--accent-dim);
}

.export-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.inventory-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.inventory-empty .empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.inventory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  position: relative;
}

.inv-item-cover {
  width: 40px;
  height: 60px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-input);
  flex-shrink: 0;
}

.inv-item-info {
  flex: 1;
  min-width: 0;
}

.inv-item-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-item-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

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

.inv-item-location {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.inv-item-qty {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.inv-item-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.inv-item-remove:hover {
  color: var(--danger);
}

/* ---- Manual Entry Section ---- */
.manual-section {
  display: none;
  margin-bottom: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.manual-section.active {
  display: block;
}

.manual-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.manual-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  padding: 0 4px;
  align-items: center;
}

.manual-input-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

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

.manual-input-row .btn {
  flex: 0 0 auto;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
}

/* ---- Toast / Notifications ---- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px var(--shadow);
  border: 1px solid var(--border);
  z-index: 1000;
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

/* ---- Loading Spinner ---- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 12px;
}

.loading-overlay.active {
  display: flex;
}

.loading-overlay .spinner {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

.loading-overlay p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---- Stats Bar ---- */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  flex: 1;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ---- Scan Confirmation Card ---- */
.scan-confirm-card {
  display: none;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--accent);
  animation: slideUp 0.3s ease;
}

.scan-confirm-card.active {
  display: block;
}

.scan-confirm-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.scanned-barcode {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  text-align: center;
}

.scanned-barcode-value {
  font-size: 20px;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 2px;
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
  word-break: break-all;
}

.scanned-format {
  font-size: 11px;
  color: var(--text-dim);
}

.supplement-section {
  margin-bottom: 14px;
}

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

.supplement-optional {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 12px;
}

.supplement-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 20px;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 4px;
  text-align: center;
}

.supplement-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.supplement-input::placeholder {
  font-size: 14px;
  letter-spacing: 1px;
  font-weight: 400;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-dim);
}

.supplement-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--warning-dim);
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

.full-upc-note {
  background: var(--success-dim);
  color: var(--success);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 14px;
  text-align: center;
}

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

.btn-lookup {
  background: var(--accent);
  color: #fff;
}

/* ---- Variant Name Badge ---- */
.result-variant-name {
  display: inline-block;
  background: var(--warning-dim);
  color: var(--warning);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

/* ---- Issue Picker (multiple results) ---- */
.issue-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.issue-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.issue-option:hover,
.issue-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.issue-option-cover {
  width: 36px;
  height: 54px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.issue-option-info {
  flex: 1;
  min-width: 0;
}

.issue-option-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.issue-option-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (min-width: 500px) {
  .main {
    padding: 24px;
  }
}
