:root {
  --primary-color: #3b82f6; /* Blue 500 */
  --primary-hover: #2563eb;
  --bg-color: #f8fafc; /* Slate 50 */
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --danger: #ef4444;
  --danger-hover: #dc2828;
  --success: #22c55e;
  --success-hover: #16a34a;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius-md: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  background: var(--card-bg);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.025em;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.icon-btn:hover {
  transform: rotate(45deg);
}

.app-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.hidden {
  display: none !important;
}

/* API Settings */
.description {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.primary-btn, .secondary-btn, .action-btn, .outline-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.primary-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.secondary-btn {
  background-color: #f1f5f9;
  color: var(--text-main);
}

.secondary-btn:hover {
  background-color: #e2e8f0;
}

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

/* Scanner */
.scanner-controls {
  margin-top: 16px;
}

.pulse-anim {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.manual-input-group {
  display: flex;
  gap: 10px;
}

.manual-input-group input {
  margin-bottom: 0;
}

.mt-15 { margin-top: 15px; }

/* Result Area */
.result-card {
  position: relative;
  text-align: center;
}

.jan-badge {
  display: inline-block;
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.product-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 24px;
}

.stock-display {
  background: var(--bg-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}

.stock-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stock-number {
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary-color);
  line-height: 1;
}

.stock-status-wrapper {
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
}

.stock-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: white;
  padding: 12px 15px; /* スマホでもはみ出さないように少しスリムに調整 */
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  min-width: 90px;
}

.stock-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 5px;
  white-space: nowrap; /* 意図しないテキストの改行を防ぐ */
}

.regular-badge {
  background-color: #e0f2fe; /* light blue */
  color: #0284c7; 
}

.special-badge {
  background-color: #fef08a; /* yellow-200 */
  color: #854d0e; 
}


/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: var(--radius-lg);
  z-index: 5;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 10px;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Scanner Custom Styling */
#reader {
  border-radius: 12px;
  overflow: hidden;
  border: none !important;
}
#reader__dashboard_section_csr span {
  color: var(--primary-color) !important;
}

/* モード切替スイッチ */
.mode-toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.toggle-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Modal & Candidate List */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

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

.candidate-list {
  list-style: none;
  overflow-y: auto;
  padding: 10px 0;
  margin: 0;
}

.candidate-item {
  padding: 12px 20px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background-color 0.2s;
}

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

.candidate-item:hover {
  background-color: #f8fafc;
}

.candidate-item-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
  color: var(--text-main);
  word-break: break-all;
}

.candidate-item-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Order Control UI */
.qty-control-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-top: 10px;
}
.qty-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.5rem;
  font-weight: bold;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-input {
  width: 70px;
  height: 44px;
  text-align: center;
  font-size: 1.25rem;
  font-weight: bold;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin: 0 !important;
}

/* Order List UI */
.order-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 400px;
  overflow-y: auto;
}
.empty-list-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 20px;
}
.order-item {
  display: flex;
  flex-direction: column;
  padding: 15px 0;
  border-bottom: 1px solid var(--border-color);
}
.order-item:last-child {
  border-bottom: none;
}
.order-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.order-item-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
  word-break: break-all;
  flex: 1;
  padding-right: 10px;
  line-height: 1.3;
}
.order-item-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 5px;
}
.order-item-del-btn:hover {
  color: var(--danger);
}
.order-item-details {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.order-item-qty-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.order-item-qty-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
}
.order-item-qty-btn:active {
  background: var(--bg-color);
}

