/* ==========================================================================
   石井折箱店 棚卸し在庫チェックWebアプリ スタイルシート
   設計方針: Vanilla CSS / スマホ片手操作（タップ領域48px以上）/ 桁ズレ防止の高視認性
   ========================================================================== */

:root {
  --bg-page: #f3f4f6;
  --bg-card: #ffffff;
  --text-main: #111827;
  --text-sub: #4b5563;
  --text-muted: #6b7280;
  --border-color: #d1d5db;

  --primary: #1d4ed8;
  --primary-active: #1e40af;
  --success: #047857;
  --success-active: #065f46;
  --warning-bg: #fffbeb;
  --warning-border: #f59e0b;
  --warning-text: #92400e;
  --danger-bg: #fef2f2;
  --danger-border: #ef4444;
  --danger-text: #991b1b;

  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.code-font {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.02em;
}

/* テスト環境バナー */
.env-banner {
  background-color: #7c2d12;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
  letter-spacing: 0.02em;
}

/* 共通ヘッダー */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 10px 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--text-main);
}

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

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.84rem;
}

.meta-chip {
  color: var(--text-sub);
  font-weight: 600;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-ok {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-warn {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-muted {
  background-color: #e5e7eb;
  color: #374151;
}

/* メインコンテナ */
.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px 48px;
}

.view-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  margin: 0 0 8px;
  font-size: 1.02rem;
  font-weight: 800;
}

.section-desc {
  margin: 0 0 12px;
  font-size: 0.86rem;
  color: var(--text-sub);
}

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

/* フォーム部品 */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.req-mark {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
  background-color: #dc2626;
  border-radius: 4px;
  vertical-align: middle;
}

.opt-mark {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-sub);
  background-color: #e5e7eb;
  border-radius: 4px;
  vertical-align: middle;
}

.form-control {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--text-main);
  background-color: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  appearance: none;
}

select.form-control {
  background-image: linear-gradient(45deg, transparent 50%, #4b5563 50%),
    linear-gradient(135deg, #4b5563 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.18);
}

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

.field-help {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--text-sub);
}

/* ボタン共通（タップしやすさ最優先） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 16px;
  font-size: 0.98rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

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

.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-lg {
  min-height: 52px;
  font-size: 1.04rem;
}

.btn-xl {
  min-height: 58px;
  font-size: 1.12rem;
}

.btn-block {
  width: 100%;
}

.btn-nowrap {
  white-space: nowrap;
  flex-shrink: 0;
}

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

.btn-primary:active:not(:disabled) {
  background-color: var(--primary-active);
}

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

.btn-success:active:not(:disabled) {
  background-color: var(--success-active);
}

.btn-secondary {
  background-color: #e5e7eb;
  color: #1f2937;
}

.btn-outline {
  background-color: #ffffff;
  border-color: var(--border-color);
  color: #1f2937;
}

.btn-outline:active:not(:disabled) {
  background-color: #f3f4f6;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

/* アラート枠 */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
  word-break: break-word;
}

.alert-danger {
  background-color: var(--danger-bg);
  border: 1.5px solid var(--danger-border);
  color: var(--danger-text);
}

.alert-warning {
  background-color: var(--warning-bg);
  border: 1.5px solid var(--warning-border);
  color: var(--warning-text);
}

/* カメラスキャナ領域 */
.scanner-container {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scanner-guide {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  color: var(--primary);
}

.qr-reader {
  width: 100%;
  min-height: 220px;
  background-color: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* 直近履歴リスト */
.empty-text {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent-item {
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-md);
  background-color: #f9fafb;
}

.recent-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.recent-item-name {
  margin-top: 2px;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-main);
}

.recent-item-bottom {
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.86rem;
  color: var(--text-sub);
}

.recent-subtotal {
  font-weight: 800;
  color: var(--text-main);
}

/* 画面2：商品情報カード・備考強調 */
.nav-back-row {
  display: flex;
  align-items: center;
}

.status-note-banner {
  background-color: #fef3c7;
  border: 2.5px solid #d97706;
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  color: #78350f;
}

.status-note-title {
  font-size: 0.86rem;
  font-weight: 800;
}

.status-note-body {
  margin-top: 4px;
  font-size: 1.05rem;
  font-weight: 800;
}

.item-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.category-badge {
  display: inline-block;
  padding: 3px 10px;
  background-color: #eff6ff;
  color: #1e40af;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.item-code {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-sub);
}

.item-name {
  margin: 8px 0 12px;
  font-size: 1.24rem;
  font-weight: 800;
  line-height: 1.35;
  word-break: break-word;
}

.price-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
}

.price-main-box {
  display: flex;
  flex-direction: column;
}

.price-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
}

.price-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.price-value {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.01em;
}

.price-unit {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.price-sub-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed #cbd5e1;
}

.sub-stat {
  display: flex;
  flex-direction: column;
}

.sub-stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.sub-stat-value {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
}

.pack-notice {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--text-sub);
}

/* 数量入力・クイック加算・予想小計 */
.qty-input {
  font-size: 1.6rem;
  font-weight: 800;
  text-align: right;
  min-height: 58px;
  padding: 10px 14px;
}

.quick-qty-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.quick-qty-btn {
  font-size: 1.02rem;
}

.quick-qty-clear {
  color: #b91c1c;
}

.subtotal-box {
  margin-bottom: 18px;
  padding: 14px 16px;
  background-color: #ecfdf5;
  border: 2px solid #10b981;
  border-radius: var(--radius-lg);
  text-align: right;
}

.subtotal-box.is-excluded {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

.subtotal-box.is-high-warn {
  background-color: #fef2f2;
  border-color: #dc2626;
}

.subtotal-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-sub);
}

.subtotal-value {
  margin-top: 2px;
  font-size: 2.05rem;
  font-weight: 900;
  line-height: 1.2;
  color: #065f46;
  word-break: break-all;
}

.subtotal-box.is-excluded .subtotal-value {
  color: #4b5563;
}

.subtotal-box.is-high-warn .subtotal-value {
  color: #b91c1c;
}

.subtotal-sub {
  margin-top: 4px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-sub);
}

.high-subtotal-warn {
  margin-top: 10px;
  padding: 10px 12px;
  background-color: #dc2626;
  color: #ffffff;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 800;
  text-align: left;
}

/* 状態区分3択セグメントボタン */
.status-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.status-btn {
  min-height: 50px;
  padding: 8px 6px;
  font-size: 0.94rem;
  font-weight: 800;
  background-color: #ffffff;
  color: var(--text-sub);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
}

.status-btn.is-active[data-status="自社在庫"] {
  background-color: #dbeafe;
  border-color: var(--primary);
  color: #1e3a8a;
}

.status-btn.is-active[data-status="委託品"] {
  background-color: #fef3c7;
  border-color: #d97706;
  color: #78350f;
}

.status-btn.is-active[data-status="廃棄予定"] {
  background-color: #fee2e2;
  border-color: #dc2626;
  color: #7f1d1d;
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  width: calc(100% - 28px);
  max-width: 480px;
  padding: 13px 16px;
  background-color: #111827;
  color: #ffffff;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  text-align: center;
}
