/* ============================================================
   style.css
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&family=JetBrains+Mono:wght@400;600&display=swap');

/* ===== ダークモード（デフォルト）===== */
:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #21262d;
  --border:     #30363d;
  --blue:       #388bfd;
  --green:      #3fb950;
  --orange:     #d29922;
  --red:        #f85149;
  --text:       #e6edf3;
  --text-sub:   #7d8590;
  --radius:     10px;
  --skip-bg:    rgba(248,81,73,.1);
  --skip-border:rgba(248,81,73,.4);
  --miss-bg:    rgba(210,153,34,.1);
  --miss-border:rgba(210,153,34,.4);
}

/* ===== ライトモード ===== */
body.light {
  --bg:         #f6f8fa;
  --surface:    #ffffff;
  --surface2:   #f0f2f5;
  --border:     #d0d7de;
  --blue:       #0969da;
  --green:      #1a7f37;
  --orange:     #9a6700;
  --red:        #cf222e;
  --text:       #1f2328;
  --text-sub:   #656d76;
  --skip-bg:    rgba(207,34,46,.06);
  --skip-border:rgba(207,34,46,.3);
  --miss-bg:    rgba(154,103,0,.06);
  --miss-border:rgba(154,103,0,.3);
}

/* 取り込みボタン */
#loadDataBtn {
  width: 100%; padding: 16px; border-radius: var(--radius);
  border: 2px dashed var(--border); background: var(--surface);
  color: var(--text-sub); font-family: inherit; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all .2s; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
#loadDataBtn:hover  { border-color: var(--blue); color: var(--blue); background: rgba(56,139,253,.05); }
#loadDataBtn.loading { opacity: .7; cursor: not-allowed; border-style: solid; }
#loadDataBtn.loaded  {
  border-style: solid; border-color: var(--green); color: var(--green);
  background: rgba(63,185,80,.06); font-size: .85rem;
}

/* メインコンテンツ（取り込み前は非表示） */
#mainContent { display: none; }

/* 再読み込みボタン（🔄） — 取り込みボタン内に統合したため不要 */

/* テーマ切り替えボタン */
#themeToggle {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
  color: var(--text-sub); font-family: inherit; font-size: .75rem;
  cursor: pointer; transition: all .2s; display: flex; align-items: center; gap: 5px;
}
#themeToggle:hover { border-color: var(--blue); color: var(--blue); }

/* 文字サイズボタン */
#fontToggle {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
  color: var(--text-sub); font-family: inherit; font-size: .75rem;
  cursor: pointer; transition: all .2s;
}
#fontToggle:hover { border-color: var(--blue); color: var(--blue); }

/* 文字サイズクラス — html要素に当てることでrem全体に効く */
html.font-md { font-size: 18px; }
html.font-lg { font-size: 22px; }

/* ===== リセット ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ===== レイアウト ===== */
.app { max-width: 600px; margin: 0 auto; padding: 16px 14px 48px; }

@media (min-width: 768px) {
  .app { max-width: 1200px; padding: 24px 28px 48px; }
  .main-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
}

/* ===== ヘッダー ===== */
header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .04em; }
header h1 span { color: var(--blue); }
.header-right { display: flex; align-items: center; gap: 10px; }

/* データ読み込みボタン */
#loadDataBtn {
  width: 100%; padding: 12px; border-radius: var(--radius);
  border: 2px dashed var(--border); background: var(--surface);
  color: var(--text-sub); font-family: inherit; font-size: .9rem; font-weight: 700;
  cursor: pointer; transition: all .2s; margin-bottom: 8px;
}
#loadDataBtn:hover  { border-color: var(--blue); color: var(--blue); }
#loadDataBtn.loaded { border-style: solid; border-color: var(--green); color: var(--green); background: rgba(63,185,80,.05); }
#loadDataBtn.loading { border-style: solid; border-color: var(--orange); color: var(--orange); cursor: not-allowed;
  animation: pulse 1.2s ease-in-out infinite; }
#loadDataBtn:disabled { cursor: not-allowed; }

#loadStatus {
  font-size: .72rem; color: var(--text-sub);
  margin-bottom: 10px; min-height: 1.2em; text-align: center;
}
#loadStatus.ok  { color: var(--green); }
#loadStatus.err { color: var(--red); }

/* ===== エラーボックス ===== */
.error-box {
  background: rgba(248,81,73,.08); border: 1px solid rgba(248,81,73,.35);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 12px;
  font-size: .8rem; color: var(--red); display: none; line-height: 1.6;
}

/* ===== ステータス選択 ===== */
.status-select-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px;
}
.status-select-box label {
  font-size: .7rem; color: var(--text-sub); white-space: nowrap;
  letter-spacing: .04em; text-transform: uppercase; flex-shrink: 0;
}
#statusSelect {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: .9rem;
  font-family: inherit; color: var(--text); outline: none;
  cursor: pointer; transition: border-color .15s;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237d8590' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}
#statusSelect:focus { border-color: var(--blue); }
#statusSelect option { background: var(--surface2); color: var(--text); }
.status-select-box.has-value { border-color: var(--blue); }

/* ===== スキャンボックス ===== */
.scan-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.scan-box label {
  font-size: .7rem; color: var(--text-sub); display: block;
  margin-bottom: 10px; letter-spacing: .04em; text-transform: uppercase;
}

/* カメラボタン */
#cameraBtn {
  width: 100%; padding: 12px; border-radius: 8px;
  border: 2px dashed var(--border); background: var(--surface2);
  color: var(--text); font-family: inherit; font-size: .9rem; font-weight: 700;
  cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 10px;
}
#cameraBtn:hover { border-color: var(--blue); color: var(--blue); }
#cameraBtn.active {
  border-style: solid; border-color: var(--green); color: var(--green);
  background: rgba(63,185,80,.07); animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(63,185,80,.3); }
  50%      { box-shadow: 0 0 0 7px rgba(63,185,80,.0); }
}

/* カメラビュー */
#cameraContainer {
  display: none; position: relative; border-radius: 8px;
  overflow: hidden; margin-bottom: 10px; background: #000; aspect-ratio: 4/3;
}
#cameraContainer.visible { display: block; }
#video { width: 100%; height: 100%; object-fit: cover; display: block; }

.scan-line {
  position: absolute; left: 8%; right: 8%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--green), transparent);
  animation: scanLine 2s ease-in-out infinite; top: 50%; pointer-events: none;
}
@keyframes scanLine {
  0%   { transform: translateY(-45px); opacity: 0; }
  20%  { opacity: 1; } 80% { opacity: 1; }
  100% { transform: translateY(45px); opacity: 0; }
}
.scan-frame {
  position: absolute; left: 8%; right: 8%;
  top: 50%; transform: translateY(-50%); height: 90px;
  border: 1.5px solid rgba(63,185,80,.5); border-radius: 6px; pointer-events: none;
}
.scan-frame::before,.scan-frame::after,
.scan-frame>span::before,.scan-frame>span::after {
  content: ''; position: absolute; width: 14px; height: 14px;
  border-color: var(--green); border-style: solid;
}
.scan-frame::before      { top:-2px;    left:-2px;   border-width: 2px 0 0 2px; }
.scan-frame::after       { top:-2px;    right:-2px;  border-width: 2px 2px 0 0; }
.scan-frame>span::before { bottom:-2px; left:-2px;   border-width: 0 0 2px 2px; }
.scan-frame>span::after  { bottom:-2px; right:-2px;  border-width: 0 2px 2px 0; }

#flashOverlay {
  position: absolute; inset: 0; background: rgba(63,185,80,.35);
  opacity: 0; pointer-events: none; transition: opacity .08s; border-radius: 8px;
}
#flashOverlay.flash { opacity: 1; }

#scanStatus {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.75); color: var(--text);
  font-size: .68rem; padding: 3px 12px; border-radius: 20px;
  white-space: nowrap; pointer-events: none;
}

/* 手入力 */
.scan-input-row { display: flex; gap: 6px; }
#barcodeInput {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: .9rem;
  font-family: 'JetBrains Mono', monospace; color: var(--text);
  outline: none; transition: border-color .15s;
}
#barcodeInput:focus { border-color: var(--blue); }
#addBtn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 14px; color: var(--text);
  font-size: 1.2rem; cursor: pointer; transition: background .15s; min-width: 46px;
}
#addBtn:hover { background: var(--border); }

/* ===== カウンター ===== */
.counter-row { display: flex; gap: 8px; margin-bottom: 10px; }
.counter-card {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 6px; text-align: center;
}
.counter-card .num { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.counter-card .lbl { font-size: .6rem; color: var(--text-sub); margin-top: 2px; }
.counter-card.c-total .num { color: var(--blue); }
.counter-card.c-ok    .num { color: var(--green); }
.counter-card.c-miss  .num { color: var(--red); }

/* ===== 送信ボタン ===== */
#submitBtn {
  width: 100%; padding: 14px; border-radius: var(--radius); border: none;
  font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer;
  transition: all .2s;
  background: linear-gradient(135deg, var(--blue), #6e40c9);
  color: #fff; letter-spacing: .04em;
}
#submitBtn:disabled { background: var(--surface2); color: var(--text-sub); cursor: not-allowed; }
#submitBtn.loading  { opacity: .7; }

/* ===== テーブル ===== */
.right-pane { margin-top: 16px; }
@media (min-width: 768px) { .right-pane { margin-top: 0; } }

.table-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.table-header h2 {
  font-size: .8rem; color: var(--text-sub);
  letter-spacing: .06em; text-transform: uppercase;
}
.clear-btn {
  font-size: .7rem; color: var(--red); background: none; border: none;
  cursor: pointer; font-family: inherit; padding: 4px 8px; border-radius: 6px;
  transition: background .15s;
}
.clear-btn:hover { background: rgba(248,81,73,.1); }

.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto;
  max-height: calc(100vh - 200px); min-height: 120px;
}

table {
  width: 100%; border-collapse: collapse;
  font-size: .78rem; min-width: 700px;
}
thead th {
  background: var(--surface2); color: var(--text-sub);
  padding: 8px 10px; text-align: center; font-size: .68rem;
  font-weight: 600; letter-spacing: .04em; white-space: nowrap;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
}
tbody td {
  padding: 8px 10px; text-align: center;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-normal:hover { background: rgba(56,139,253,.05); }
tbody tr.row-miss { background: var(--miss-bg); }
tbody tr.row-warn { background: rgba(207,34,46,.06); }

/* ステータスバッジ */
.status-badge {
  display: inline-block; font-size: .65rem; padding: 2px 8px;
  border-radius: 20px; font-weight: 700; white-space: nowrap;
}
.status-badge.s-ready   { background: rgba(56,139,253,.18);  color: var(--blue); }
.status-badge.s-packed  { background: rgba(63,185,80,.18);   color: var(--green); }
.status-badge.s-shipped { background: rgba(63,185,80,.28);   color: #58d68d; }
.status-badge.s-done    { background: rgba(125,133,144,.18); color: var(--text-sub); }
.status-badge.s-miss    { background: rgba(210,153,34,.18);  color: var(--orange); }
.status-badge.s-other   { background: rgba(125,133,144,.18); color: var(--text-sub); }

/* のし */
.noshi-none  { color: var(--text-sub); font-size: .7rem; }
.noshi-inner { color: var(--blue); font-weight: 700; }
.noshi-other { color: var(--orange); font-weight: 700; }

/* 出荷場所 */
.loc-gift   { color: #1a7f37; font-weight: 700; }
.loc-sendai { color: #cf222e; font-weight: 700; }
body.light .loc-gift   { color: #1a7f37; }
body.light .loc-sendai { color: #cf222e; }

/* 〇/ー */
.maru { color: var(--green); font-weight: 700; }
.dash { color: var(--text-sub); }

.empty-msg {
  text-align: center; color: var(--text-sub);
  font-size: .82rem; padding: 32px; display: none;
}

.arrow { color: var(--text-sub); font-size: .7rem; margin: 0 3px; }

/* 行ボタン */
.row-del-btn {
  background: none; border: none; color: var(--text-sub);
  cursor: pointer; font-size: .85rem; padding: 3px 6px;
  border-radius: 5px; transition: all .15s; line-height: 1;
}
.row-del-btn:hover { color: var(--red); background: rgba(248,81,73,.12); }

.row-detail-btn {
  background: none; border: none; color: var(--text-sub);
  cursor: pointer; font-size: .8rem; padding: 3px 6px;
  border-radius: 5px; transition: all .15s; line-height: 1;
}
.row-detail-btn:hover { color: var(--blue); background: rgba(56,139,253,.12); }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(13,17,23,.8); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: 100%; max-width: 480px;
  max-height: 85vh; overflow-y: auto;
  animation: modalIn .15s ease;
}
@keyframes modalIn {
  from { opacity:0; transform: scale(.96) translateY(8px); }
  to   { opacity:1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-size: .95rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text-sub);
  cursor: pointer; font-size: 1.1rem; padding: 2px 6px;
  border-radius: 6px; transition: all .15s; line-height: 1;
}
.modal-close:hover { color: var(--red); background: rgba(248,81,73,.1); }
.modal-barcode {
  padding: 16px 18px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center; background: #fff;
}
.modal-barcode canvas { max-width: 100%; height: auto; }
.modal-body { padding: 18px; }
.modal-row {
  display: flex; gap: 12px; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.modal-row:last-child { border-bottom: none; }
.modal-label {
  font-size: .7rem; color: var(--text-sub); min-width: 90px;
  flex-shrink: 0; letter-spacing: .04em; text-transform: uppercase;
}
.modal-value { font-size: .88rem; word-break: break-all; }
.modal-value code { font-family: 'JetBrains Mono', monospace; font-size: .82rem; }

/* ===== ローディングオーバーレイ ===== */
#loadingOverlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(13,17,23,.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; backdrop-filter: blur(3px);
}
#loadingOverlay.hidden { display: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: .9rem; color: var(--text-sub); }
.loading-sub  { font-size: .75rem; color: var(--text-sub); opacity: .6; }

.warn-row { background: rgba(207,34,46,.06); border-radius: 6px; margin-bottom: 4px; }

/* ===== パスワード画面 ===== */
#passwordScreen {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px;
}
.pw-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 28px; width: 100%; max-width: 340px;
  text-align: center;
}
.pw-icon { font-size: 2.5rem; margin-bottom: 12px; }
.pw-box h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.pw-box p  { font-size: .82rem; color: var(--text-sub); margin-bottom: 20px; }
.pw-input-wrap {
  display: flex; gap: 8px;
}
.pw-input-wrap input {
  flex: 1; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2);
  font-family: inherit; font-size: .9rem; color: var(--text); outline: none;
  transition: border-color .15s;
}
.pw-input-wrap input:focus { border-color: var(--blue); }
.pw-input-wrap button {
  padding: 10px 16px; border-radius: 8px; border: none;
  background: var(--blue); color: #fff; font-size: 1rem;
  cursor: pointer; transition: opacity .15s;
}
.pw-input-wrap button:hover { opacity: .85; }
.pw-error { margin-top: 10px; font-size: .78rem; color: var(--red); min-height: 1em; }

/* ===== 確認モードバー ===== */
.scan-mode-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding: 8px 12px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
}
.scan-mode-label { font-size: .78rem; color: var(--text-sub); font-weight: 600; }
.mode-toggle {
  display: flex; align-items: center; gap: 5px;
  background: none; border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 12px; font-family: inherit; font-size: .78rem; font-weight: 700;
  color: var(--text-sub); cursor: pointer; transition: all .2s;
}
.mode-toggle.active { border-color: var(--green); color: var(--green); background: rgba(26,127,55,.08); }

/* 確認モーダルフッター */
.confirm-footer {
  display: flex; gap: 10px; padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.confirm-cancel-btn {
  flex: 1; padding: 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-sub); font-family: inherit; font-size: .88rem; font-weight: 700;
  cursor: pointer; transition: all .15s;
}
.confirm-cancel-btn:hover { border-color: var(--text-sub); color: var(--text); }
.confirm-ok-btn {
  flex: 2; padding: 11px; border-radius: 8px;
  border: none; background: var(--blue);
  color: #fff; font-family: inherit; font-size: .88rem; font-weight: 700;
  cursor: pointer; transition: all .15s;
}
.confirm-ok-btn:hover { opacity: .85; }

/* ===== トースト通知 ===== */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--green); color: #fff;
  font-size: .9rem; font-weight: 700; padding: 12px 28px;
  border-radius: 30px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 300;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== アニメーション ===== */
@keyframes fadeIn { from { opacity:0; transform:translateY(-3px); } to { opacity:1; } }
.row-anim { animation: fadeIn .15s ease; }