* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #f5f7fa;
  color: #2c3e50;
  min-height: 100vh;
}
header {
  background: linear-gradient(135deg, #2c5282, #2b6cb0);
  color: white;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 20px; display: flex; align-items: center; gap: 10px; }
header h1::before { content: "📦"; font-size: 24px; }
nav {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 24px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.tab {
  padding: 14px 20px;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 14px;
  color: #64748b;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
  font-weight: 500;
}
.tab:hover { color: #2b6cb0; background: #f8fafc; }
.tab.active { color: #2b6cb0; border-bottom-color: #2b6cb0; }
main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border-left: 4px solid #2b6cb0;
}
.stat-card.warn { border-left-color: #ed8936; }
.stat-card.danger { border-left-color: #e53e3e; }
.stat-card.success { border-left-color: #38a169; }
.stat-card .label { font-size: 12px; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; color: #1a202c; }
.stat-card .sub { font-size: 12px; color: #94a3b8; margin-top: 4px; }

.panel {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.panel-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  background: white;
}
.toolbar input[type="search"] { flex: 1; min-width: 200px; }

button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #2b6cb0;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
button:hover { background: #2c5282; }
button.secondary { background: #e2e8f0; color: #2c3e50; }
button.secondary:hover { background: #cbd5e0; }
button.danger { background: #e53e3e; }
button.danger:hover { background: #c53030; }
button.success { background: #38a169; }
button.success:hover { background: #2f855a; }
button.small { padding: 4px 10px; font-size: 12px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  padding: 12px;
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
td { padding: 12px; border-bottom: 1px solid #f1f5f9; }
tr:hover { background: #f8fafc; }
.stock-low { color: #e53e3e; font-weight: 600; }
.stock-warn { color: #ed8936; font-weight: 600; }
.stock-ok { color: #38a169; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: #e2e8f0;
  color: #475569;
  font-weight: 500;
}
.badge.in { background: #c6f6d5; color: #22543d; }
.badge.out { background: #fed7d7; color: #742a2a; }

.modal-bg {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
}
.modal-bg.active { display: flex; }
.modal {
  background: white;
  border-radius: 8px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  font-weight: 500;
  color: #475569;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}

.empty {
  text-align: center;
  padding: 40px;
  color: #94a3b8;
}
.qr-display { text-align: center; padding: 20px; }
.qr-display canvas, .qr-display img { margin: 0 auto; display: block; }
.alert-row { background: #fff5f5 !important; }
.warn-row { background: #fffaf0 !important; }
.cat-chart { display: flex; flex-direction: column; gap: 10px; }
.cat-bar-row { display: grid; grid-template-columns: 140px 1fr 80px; align-items: center; gap: 12px; }
.cat-bar { background: #e2e8f0; height: 22px; border-radius: 4px; overflow: hidden; }
.cat-bar-fill { background: linear-gradient(90deg, #4299e1, #2b6cb0); height: 100%; transition: width 0.4s; }
.cat-count { font-weight: 600; color: #2b6cb0; text-align: right; }

.hint { color: #64748b; margin-bottom: 14px; font-size: 14px; }
.hint.center { text-align: center; }
.hint-small { color: #64748b; font-size: 12px; }
.info-box { padding: 10px; background: #f8fafc; border-radius: 6px; font-size: 14px; }
.filetree { background: #f8fafc; padding: 14px; border-radius: 6px; font-size: 13px; line-height: 1.6; font-family: ui-monospace, monospace; color: #2c3e50; }

#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: white;
  padding: 12px 24px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 300;
}
#toast.show { opacity: 1; }

video { width: 100%; max-width: 400px; border-radius: 8px; background: #000; }
.scan-area { text-align: center; padding: 20px; }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  main { padding: 12px; }
  th, td { padding: 8px; font-size: 13px; }
  .cat-bar-row { grid-template-columns: 100px 1fr 50px; }
}

/* ===== 移行ウィザード ===== */
.modal-wide { max-width: 760px; }
.mig-steps { margin: 12px 0 0 20px; color: #475569; font-size: 14px; line-height: 1.9; }
.mapping-wrap { max-height: 400px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 6px; }
.mapping-table { font-size: 13px; }
.mapping-table th { position: sticky; top: 0; z-index: 1; }
.mapping-table td { vertical-align: middle; }
.mapping-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.sample-cell { color: #94a3b8; font-size: 12px; max-width: 200px; word-break: break-all; }
.summary-table { font-size: 14px; margin: 8px 0; }
.summary-table td { padding: 6px 12px; border-bottom: 1px solid #f1f5f9; }
.summary-table td:first-child { color: #64748b; }
.preview-wrap { overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 6px; }
.preview-table { font-size: 12px; }
.preview-table th, .preview-table td { padding: 6px 10px; white-space: nowrap; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

/* ===== 展開可能な商品行 ===== */
.expand-btn {
  background: none;
  border: 1px solid #cbd5e0;
  color: #475569;
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 24px;
}
.expand-btn:hover { background: #e2e8f0; color: #2c3e50; }
.detail-row td { background: #f8fafc !important; padding: 0 !important; }
.detail-row:hover { background: #f8fafc !important; }
.detail-wrap {
  padding: 12px 24px 16px 60px;
  border-left: 3px solid #2b6cb0;
  background: #f8fafc;
}
.detail-table {
  margin-top: 8px;
  background: white;
  font-size: 13px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}
.detail-table th {
  background: #edf2f7;
  font-size: 11px;
  padding: 6px 10px;
}
.detail-table td { padding: 8px 10px; }

/* ===== 場所別ビュー ===== */
.loc-summary {
  font-size: 13px;
  font-weight: 400;
  color: #64748b;
}

/* ===== 場所間移動 ===== */
.transfer-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.transfer-grid .form-group { margin-bottom: 0; }
.tf-swap-wrap {
  padding-bottom: 9px;
}
.tf-swap-wrap button {
  font-size: 16px;
  padding: 8px 10px;
}
.tf-preview {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  min-height: 42px;
}
.transfer-row td {
  background: #faf5ff !important;
}
.transfer-row:hover td {
  background: #f3e8ff !important;
}
.badge.transfer-in {
  background: #e9d8fd;
  color: #553c9a;
}
.badge.transfer-out {
  background: #d6bcfa;
  color: #44337a;
}

@media (max-width: 640px) {
  .transfer-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .tf-swap-wrap { padding-bottom: 0; text-align: center; }
}

/* ===== QR/バーコード管理 ===== */
.codes-list {
  min-height: 30px;
  padding: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.code-chip {
  display: inline-flex;
  align-items: center;
  background: #e0e7ff;
  color: #3730a3;
  padding: 4px 6px 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  gap: 4px;
}
.code-chip .code-val {
  font-family: ui-monospace, monospace;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.code-chip .code-del {
  background: rgba(0,0,0,0.1);
  color: #3730a3;
  border: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.code-chip .code-del:hover { background: rgba(0,0,0,0.2); }
.code-add-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.code-add-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.code-count {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  background: #e0e7ff;
  color: #3730a3;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 500;
}
.codes-display {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.code-pill {
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
}

/* ===== モーダル拡張 ===== */
.section-h {
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid #e2e8f0;
  font-size: 14px;
  color: #475569;
}
.section-h:first-of-type { margin-top: 0; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px 12px;
  margin-bottom: 12px;
  padding: 10px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
}
.detail-cell {
  display: flex;
  gap: 6px;
}
.detail-key {
  color: #94a3b8;
  font-size: 12px;
  min-width: 90px;
}
.detail-val {
  color: #2c3e50;
  font-weight: 500;
}

/* ===== 棚卸 ===== */
.st-summary {
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}
.st-progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}
.st-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4299e1, #2b6cb0);
  transition: width 0.3s;
}
.st-summary-text { font-size: 13px; color: #475569; }
.st-filter-btn.active {
  background: #2b6cb0;
  color: white;
}
.stocktake-table-wrap {
  margin-top: 14px;
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.stocktake-table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.st-input {
  width: 80px;
  padding: 6px 10px;
  border: 2px solid #2b6cb0;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.st-input:focus {
  outline: none;
  background: #ebf8ff;
}
.st-uncounted td {
  background: #fffaf0 !important;
}
.st-diff-row td {
  background: #fff5f5 !important;
}
.st-ok-row td {
  background: #f0fff4 !important;
}
.st-diff-plus { color: #38a169; font-weight: 600; }
.st-diff-minus { color: #e53e3e; font-weight: 600; }
.st-diff-zero { color: #94a3b8; }

/* ===== ソート可能なヘッダ ===== */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: background 0.15s;
}
th.sortable:hover { background: #edf2f7; }
th.sorted { background: #ebf8ff !important; color: #2b6cb0; }
.sort-mark {
  font-size: 10px;
  margin-left: 2px;
  color: #cbd5e0;
}
th.sorted .sort-mark { color: #2b6cb0; }

/* ===== インライン編集セル ===== */
.editable-cell {
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.editable-cell:hover {
  background: #fffaf0 !important;
  outline: 1px dashed #f6ad55;
  outline-offset: -1px;
}
.editable-cell:hover::after {
  content: '✏️';
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  opacity: 0.5;
}
.inline-edit-input {
  width: 100%;
  padding: 4px 6px;
  border: 2px solid #2b6cb0;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  font-family: inherit;
}
.inline-edit-input:focus {
  outline: none;
  background: #ebf8ff;
}

/* ===== 表示項目モーダル ===== */
.columns-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
}
.col-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.col-toggle:hover { background: #ebf8ff; }
.col-toggle input { cursor: pointer; }
.col-toggle input:disabled + span { color: #94a3b8; cursor: not-allowed; }

/* ===== グラフクリック ===== */
.cat-bar-clickable {
  cursor: pointer;
  padding: 4px 6px;
  margin: -4px -6px;
  border-radius: 4px;
  transition: background 0.15s;
}
.cat-bar-clickable:hover {
  background: #ebf8ff;
}
.cat-bar-clickable:hover .cat-bar-fill {
  background: linear-gradient(90deg, #63b3ed, #2c5282);
}

/* ===== アクション列を狭く ===== */
.actions-cell {
  white-space: nowrap;
  min-width: 220px;
}

@media (max-width: 640px) {
  .columns-list { grid-template-columns: 1fr; }
}

/* ===== マスタータブ ===== */
.masters-tab {
  background: transparent;
  color: #64748b;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 12px 18px;
  font-weight: 500;
}
.masters-tab:hover {
  background: #f8fafc;
  color: #2b6cb0;
}
.masters-tab.active {
  background: white;
  color: #2b6cb0;
  border-bottom-color: #2b6cb0;
}

/* ===== ヘッダのユーザー切替 ===== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.user-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  border: none;
  font-size: 13px;
  transition: background 0.15s;
}
.user-switcher:hover { background: rgba(255,255,255,0.25); }
.user-switcher-name { font-weight: 500; }

/* ===== ユーザーアバター ===== */
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: white;
  font-weight: 600;
  font-size: 14px;
}
.user-avatar.small { width: 22px; height: 22px; font-size: 11px; }
.user-avatar.tiny { width: 16px; height: 16px; font-size: 9px; }

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #475569;
}
.user-chip.deleted {
  color: #94a3b8;
  font-style: italic;
}

/* 役割バッジの色分け */
.badge.role-admin {
  background: #fed7d7;
  color: #742a2a;
}
.badge.role-staff {
  background: #c6f6d5;
  color: #22543d;
}
.badge.role-viewer {
  background: #e2e8f0;
  color: #475569;
}

/* ===== API仕様の表示 ===== */
.api-spec {
  background: #1a202c;
  color: #cbd5e0;
  padding: 16px;
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  line-height: 1.5;
  overflow-x: auto;
}

/* ===== 役割と権限の管理 ===== */
.role-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
}
.role-perms-list {
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  padding: 8px;
}
.perm-group {
  background: white;
  border-radius: 6px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
}
.perm-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 8px;
}
.perm-group-header label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}
.perm-count {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 400;
}
.perm-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px;
}
.perm-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  background: #f8fafc;
  transition: background 0.15s;
}
.perm-item:hover { background: #ebf8ff; }
.perm-item.on { background: #c6f6d5; }
.perm-item input { grid-row: 1 / 3; align-self: start; margin-top: 3px; }
.perm-label { font-size: 13px; font-weight: 500; color: #2c3e50; }
.perm-desc { font-size: 11px; color: #94a3b8; }
.perm-item.on .perm-label { color: #1a202c; }
.perm-item.on .perm-desc { color: #475569; }

@media (max-width: 640px) {
  .perm-items { grid-template-columns: 1fr; }
}

/* ===== 空状態(権限不足等) ===== */
.empty-state {
  background: white;
  border: 1px dashed #cbd5e0;
  border-radius: 8px;
  padding: 40px 20px;
  text-align: center;
  color: #94a3b8;
  margin-top: 16px;
}
.empty-state p { margin: 4px 0; }
.empty-state p:first-child { font-size: 15px; color: #475569; }
