/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --success: #0e9f6e;
  --danger: #e02424;
  --warning: #d97706;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== レイアウト ===== */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar .user-info { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.topbar .user-info span { opacity: .9; font-weight: 600; }

/* トップバー専用ボタン */
.btn-topbar {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.13);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-topbar:hover  { background: rgba(255,255,255,.25); }
.btn-topbar:active { transform: scale(.95); }

/* 🔄 更新：他ボタンと同じスタイル */
.btn-topbar-update {
  font-size: 14px;
}

.main-container { display: flex; flex: 1; }

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
.sidebar-section { margin-bottom: 8px; }
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 16px 4px;
}
.sidebar a, .sidebar button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 16px;
  color: var(--text);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s;
  border-radius: 0;
}
.sidebar a:hover, .sidebar button:hover { background: var(--bg); }
.sidebar a.active { background: #eff6ff; color: var(--primary); font-weight: 600; }

.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 56px);
}

/* ===== ページ ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== カード ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 16px; font-weight: 600; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== フォーム ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color .15s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1); }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ===== テーブル ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--bg);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #f8faff; }
tbody tr:last-child td { border-bottom: none; }
/* 出荷済み行 */
tbody tr.row-shipped { background: #f1f5f9; color: #94a3b8; }
tbody tr.row-shipped:hover { background: #e9eef5; }
/* 引き取り行（在庫戻り） */
tbody tr.row-pickup { background: #fffbeb; color: #92400e; }
tbody tr.row-pickup:hover { background: #fef3c7; }

/* ===== スティッキーテーブル（在庫一覧・商品マスタ） ===== */
.sticky-table-wrapper {
  overflow: auto;
  max-height: calc(100vh - 220px);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.sticky-table-wrapper thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--border);
}
.sticky-table-wrapper thead tr.filter-row th {
  position: sticky;
  top: 41px;
  z-index: 3;
  background: #f0f4ff;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.filter-input {
  width: 100%;
  padding: 2px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
  min-width: 60px;
}
.filter-input:focus { outline: none; border-color: var(--primary); }
.sticky-table-wrapper thead tr:first-child th { transition: background .15s; }
.sticky-table-wrapper thead tr:first-child th:hover { background: #e8edf8; }
.sticky-table-wrapper thead tr:first-child th.drag-over { border-left: 3px solid var(--primary); background: #dde8ff; }
.sticky-table-wrapper thead tr:first-child th.dragging { opacity: 0.5; }

/* ===== テーブル横スクロールボタン ===== */
.table-scroll-btns {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-bottom: 4px;
}
.table-scroll-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1.6;
  transition: background .15s;
}
.table-scroll-btn:hover { background: #e8edf8; color: var(--primary); }

/* ===== 列幅リサイズ ===== */
.resizable-table { width: auto; min-width: 100%; }
.resizable-table tbody td { white-space: nowrap; }
.resizable-table th { position: relative; }
.col-resize-handle {
  position: absolute; right: 0; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 10; border-right: 2px solid transparent;
  user-select: none;
}
.col-resize-handle:hover { border-right-color: var(--primary); }
.col-resize-dragging { border-right-color: var(--primary) !important; background: rgba(99,102,241,.15); }

/* ===== バッジ ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ===== ログイン画面 ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a8a 0%, #1a56db 100%);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 8px; text-align: center; }
.login-card p { color: var(--text-muted); font-size: 13px; text-align: center; margin-bottom: 28px; }

/* ===== アラート ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ===== 在庫照合テーブル ===== */
.reconcile-wrapper {
  max-height: calc(100vh - 320px);
}
.reconcile-wrapper thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--border);
}
.reconcile-table th, .reconcile-table td { text-align: center; }
.reconcile-table thead th[onclick]:hover { background: #e8edf8; }
.reconcile-table .product-col { text-align: left; }
.discrepancy-row { background: #fff5f5 !important; }
.discrepancy-row td { color: #991b1b; }

/* ===== ファイルアップロード ===== */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: var(--bg);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}
.upload-area .icon { font-size: 36px; margin-bottom: 8px; }
.upload-area p { color: var(--text-muted); font-size: 13px; }

/* ===== 統計カード ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== プレビューパネル（PDF/Excel解析結果） ===== */
.preview-panel {
  background: #f8faff;
  border: 1px solid #c3d9ff;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}
.preview-panel h4 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--primary); }

/* ===== スピナー ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ハンバーガーメニュー ===== */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 199;
}

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
  .hamburger-btn { display: block; }
  .sidebar {
    display: block;
    position: fixed;
    top: 0;
    left: -240px;
    width: 240px;
    height: 100vh;
    z-index: 200;
    transition: left .25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.2);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 照合スキャンモーダル ===== */
#verify-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: #f0f2f5;
  overflow-y: auto;
}
.verify-header {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.verify-header h1 { font-size: 17px; font-weight: 700; flex: 1; }
.verify-header .back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.verify-body { padding: 14px; max-width: 700px; margin: 0 auto; }
.verify-progress-box {
  background: white;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}
.verify-progress-text { font-size: 14px; font-weight: 600; color: #333; margin-bottom: 8px; }
.verify-progress-bar-bg {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}
.verify-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #16a34a);
  border-radius: 4px;
  width: 0%;
  transition: width 0.4s ease;
}
.verify-complete-msg {
  display: none;
  margin-top: 10px;
  padding: 10px 14px;
  background: #d1fae5;
  color: #065f46;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
}
.verify-scan-box {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  margin-bottom: 12px;
  position: relative;
}
.verify-scan-label {
  font-size: 13px;
  color: #666;
  padding: 12px 14px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
/* 外側クリップラッパー：JSでモードに応じた高さに切替 */
#verify-reader-clip {
  position: relative;
  width: 95%;
  margin: 0 auto;
  height: 320px; /* QRモード(320px) / バーコードモード時はJS側で130pxに変更 */
  overflow: hidden;
  background: #000;
  border-radius: 8px;
}
#verify-reader { width: 100%; }
#verify-reader video { object-fit: cover; }
#verify-reader > div > div { border-color: #667eea !important; box-shadow: rgba(102,126,234,0.5) 0px 0px 0px 4px inset !important; }
/* スキャン成功フラッシュ（カメラ内） */
#verify-scan-success {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(34, 197, 94, 0.45);
  border-radius: 16px;
  pointer-events: none;
  opacity: 0;
  z-index: 30;
  transition: opacity 0.15s ease-in;
}
#verify-scan-success.show { opacity: 1; }
#verify-scan-success.hide { opacity: 0; transition: opacity 0.5s ease-out; }
#verify-scan-success span {
  font-size: 80px;
  font-weight: 700;
  color: #14532d;
  text-shadow: 0 2px 8px rgba(255,255,255,0.4);
}
/* エラーオーバーレイ（赤） */
#verify-scan-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(220, 38, 38, 0.45);
  border-radius: 16px;
  pointer-events: none;
  opacity: 0;
  z-index: 30;
  transition: opacity 0.15s ease-in;
}
#verify-scan-error.show { opacity: 1; }
#verify-scan-error.hide { opacity: 0; transition: opacity 0.5s ease-out; }
#verify-scan-error span {
  font-size: 80px;
  font-weight: 700;
  color: #7f1d1d;
  text-shadow: 0 2px 8px rgba(255,255,255,0.4);
}
/* 読取済オーバーレイ（青） */
#verify-scan-done {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 165, 233, 0.45);
  border-radius: 16px;
  pointer-events: none;
  opacity: 0;
  z-index: 30;
  transition: opacity 0.15s ease-in;
}
#verify-scan-done.show { opacity: 1; }
#verify-scan-done.hide { opacity: 0; transition: opacity 0.5s ease-out; }
#verify-scan-done span {
  font-size: 72px;
  font-weight: 700;
  color: #0c4a6e;
  text-shadow: 0 2px 8px rgba(255,255,255,0.4);
}
.verify-scan-hint {
  text-align: center;
  padding: 10px 12px;
  font-size: 13px;
  color: #888;
  background: #fafafa;
  border-top: 1px solid #eee;
}
/* QR/バーコード切替ボタン */
.verify-mode-btns {
  display: flex;
  gap: 0;
  margin: 0 14px 12px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #ddd;
}
.verify-mode-btn {
  flex: 1;
  padding: 8px 6px;
  background: white;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #666;
  transition: background 0.15s, color 0.15s;
}
.verify-mode-btn.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}
.verify-manual-row { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid #f0f0f0; }
.verify-manual-row input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
.verify-manual-row input:focus { outline: none; border-color: #667eea; }
.verify-manual-row button {
  padding: 10px 18px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.verify-item {
  background: white;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 4px solid #e5e7eb;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: all 0.2s;
}
.verify-item.verified {
  border-left-color: #16a34a;
  background: #f0fdf4;
}
.verify-item.no-match {
  border-left-color: #dc2626;
  background: #fff5f5;
  animation: shake 0.3s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.verify-status { font-size: 26px; width: 30px; text-align: center; flex-shrink: 0; }
.verify-info { flex: 1; min-width: 0; }
.verify-coil { font-weight: 700; font-size: 14px; color: #333; }
.verify-sub { font-size: 12px; color: #888; margin-top: 3px; }
.stat-card.clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(102,126,234,0.2); }
.verify-flash {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  z-index: 500;
  pointer-events: none;
  animation: verifyFlash 1s ease forwards;
}
@keyframes verifyFlash {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  30%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}
.verify-flash-done {
  font-size: 56px;
  font-weight: 700;
  text-align: center;
  background: transparent;
  color: #0ea5e9 !important;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 8px solid #0ea5e9;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: verifyFlashDone 1.1s ease forwards;
}
@keyframes verifyFlashDone {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  25%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  65%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}
.scan-verify-btn {
  padding: 6px 14px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
