/* ================================================================
   在庫補充入力システム — Style
   ================================================================ */

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

:root {
  --primary: #1976d2;
  --primary-dark: #1565c0;
  --success: #2e7d32;
  --success-dark: #1b5e20;
  --warn: #f57c00;
  --danger: #d32f2f;
  --bg: #f5f5f5;
  --card-bg: #fff;
  --text: #212121;
  --text-secondary: #757575;
  --border: #e0e0e0;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* --- Header --- */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}

#header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Badges --- */
.badge {
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,.2);
  color: #fff;
  white-space: nowrap;
}

.badge-warn {
  background: var(--warn);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  touch-action: manipulation;
}

.btn:active { opacity: .8; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }

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

.btn-block { width: 100%; padding: 12px; font-size: 1rem; }

.btn-resend {
  background: var(--warn);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: var(--radius);
  animation: pulse-resend 1.5s infinite;
}

@keyframes pulse-resend {
  0%, 100% { opacity: 1; }
  50% { opacity: .7; }
}

.btn-sync {
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: .85rem;
  padding: 6px 12px;
  border-radius: var(--radius);
}

.btn-icon {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  touch-action: manipulation;
}

/* --- Main --- */
main {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Card --- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Labels & Inputs --- */
label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  margin-top: 12px;
}

input[type="text"],
input[type="url"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}

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

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row input { flex: 1 1 0; min-width: 0; }

/* --- Quantity Row --- */
.qty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.qty-row input {
  text-align: center;
  flex: 1 1 0;
  min-width: 0;
  height: 96px;
  font-size: 1.6rem;
  font-weight: 700;
}

.btn-qty {
  flex: 1 1 0;
  height: 96px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background .15s;
  white-space: nowrap;
}

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

/* --- Remarks --- */
.remarks-input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  outline: none;
  margin-top: 8px;
  transition: border-color .15s;
}

.remarks-input:focus {
  border-color: var(--primary);
}

/* --- Product Info --- */
.product-info, .unknown-jan { margin-top: 12px; }

.product-name {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 12px;
  background: #e3f2fd;
  border-radius: var(--radius);
  color: var(--primary-dark);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.warn-text {
  font-size: .9rem;
  font-weight: 600;
  color: var(--warn);
  padding: 8px 12px;
  background: #fff3e0;
  border-radius: var(--radius);
}

/* --- Item List --- */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.count-badge {
  font-size: .75rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
}

.item-list {
  max-height: 480px;
  overflow-y: auto;
}

.empty-msg {
  text-align: center;
  color: var(--text-secondary);
  font-size: .85rem;
  padding: 16px 0;
}

.item-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.item-row:last-child { border-bottom: none; }

.item-row .item-name {
  flex: 1;
  font-weight: 600;
  font-size: .9rem;
}

.item-row .item-jan {
  font-size: .75rem;
  color: var(--text-secondary);
}

.item-row .item-qty {
  font-size: 1rem;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
}

.item-row .btn-remove {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  touch-action: manipulation;
}

.item-remarks {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--warn);
  color: #fff;
  margin-left: 4px;
}

.item-var-tag {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  margin-left: 4px;
}

/* History items */
.history-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-secondary);
}

.history-row:last-child { border-bottom: none; }

.history-row .history-time {
  font-size: .75rem;
}

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

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.modal-content h2 {
  margin-bottom: 12px;
}

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

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  border-radius: var(--radius);
  background: #333;
  color: #fff;
  font-size: .9rem;
  z-index: 300;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* --- Toggle Buttons (Var1/Var2) --- */
.toggle-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 10px;
  width: 100%;
}

.toggle-group-label {
  width: 100%;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.toggle-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 16px 4px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s, border-color .15s;
  text-align: center;
}

.toggle-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.toggle-btn:active {
  opacity: .8;
}

/* --- Category Search --- */
#catSearch {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cat-select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  background: var(--card-bg);
  color: var(--text);
  appearance: auto;
  outline: none;
  cursor: pointer;
}

.cat-select:focus {
  border-color: var(--primary);
}

/* --- Price Filter --- */
.price-filter {
  margin-top: 4px;
  padding: 10px 0;
}

.price-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.price-label-row #priceRangeLabel {
  color: var(--primary);
  font-weight: 700;
  font-size: .95rem;
}

.range-slider-wrap {
  position: relative;
  height: 40px;
  display: flex;
  align-items: center;
}

.range-slider {
  position: absolute;
  width: 100%;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: transparent;
  outline: none;
  margin: 0;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  cursor: pointer;
  pointer-events: all;
  position: relative;
  z-index: 2;
}

.range-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  cursor: pointer;
  pointer-events: all;
}

/* Track for the first slider (min) */
#priceMin::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}

#priceMax::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: transparent;
}

#priceMin::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
}

#priceMax::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: transparent;
}

.name-search {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}

.name-search:focus {
  border-color: var(--primary);
}

.product-list {
  max-height: 480px;
  overflow-y: auto;
  margin-top: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
}

.product-list-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  font-weight: 600;
  font-size: .95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.product-list-item .pl-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-list-item .pl-price {
  flex-shrink: 0;
  font-size: .8rem;
  font-weight: 700;
  color: var(--danger);
}

.product-list-item:last-child { border-bottom: none; }

.product-list-item:active {
  background: #e3f2fd;
}


/* --- Camera --- */
.btn-camera-large {
  flex: 0 0 168px;
  height: 42px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  font-size: 1.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.btn-camera-large:active {
  opacity: .8;
}

.jan-input {
  font-size: .9rem !important;
  font-weight: 700;
}

.camera-modal-content {
  background: #000;
  border-radius: var(--radius);
  width: 95%;
  max-width: 480px;
  overflow: hidden;
}

.camera-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #111;
  color: #fff;
  font-weight: 600;
}

.camera-header .btn-icon {
  color: #fff;
  font-size: 1.5rem;
}

#cameraReader {
  width: 100%;
}

/* html5-qrcode が生成する要素の調整 */
#cameraReader video {
  width: 100% !important;
  border-radius: 0;
}

#cameraReader img { display: none; }

.camera-hint {
  text-align: center;
  color: #aaa;
  font-size: .85rem;
  padding: 10px;
  background: #111;
}

/* --- Loading Overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
}

.loading-box {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 32px 36px;
  width: 85%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

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

.progress-bar-wrap {
  width: 100%;
  height: 14px;
  background: var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #42a5f5);
  border-radius: 7px;
  transition: width .15s ease;
}

.progress-label {
  margin-top: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.progress-status {
  font-size: .82rem;
  color: var(--text-secondary);
}

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

/* --- Responsive --- */
@media (max-width: 400px) {
  #header { padding: 10px 12px; }
  #header h1 { font-size: 1rem; }
  main { padding: 8px; }
  .card { padding: 12px; }
}
