/* ============================================================
   M-BOX QR保管管理システム  共通スタイル
   ============================================================ */

:root {
  --color-primary: #2c5282;
  --color-primary-dark: #1f3a5f;
  --color-accent: #d69e2e;
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #d6dde6;
  --color-text: #1a202c;
  --color-text-soft: #5a6577;
  --color-success: #2f855a;
  --color-success-bg: #e6fffa;
  --color-danger: #c53030;
  --color-danger-bg: #fff5f5;
  --color-warn-bg: #fffbeb;
  --color-warn: #b7791f;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
}

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

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
               "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "Yu Gothic", Meiryo, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ヘッダー */
.site-header {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.site-header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
}
.site-logo {
  color: #fff; display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px;
}
.site-logo:hover { text-decoration: none; opacity: 0.9; }
.logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--color-accent); color: #fff;
  border-radius: var(--radius); font-weight: 800;
}
.logo-text small { display: block; font-size: 11px; font-weight: 400; opacity: 0.85; }

.site-nav { display: flex; gap: 18px; align-items: center; }
.site-nav a { color: #fff; opacity: 0.92; }
.site-nav a:hover { opacity: 1; }
.user-badge {
  font-size: 12px; padding: 4px 10px;
  background: rgba(255,255,255,0.15); border-radius: 999px;
}

/* レイアウト */
.container {
  max-width: 1200px; margin: 28px auto;
  padding: 0 20px;
}

.site-footer {
  text-align: center; color: var(--color-text-soft);
  padding: 24px; margin-top: 60px;
}

/* ページタイトル */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
  padding-bottom: 12px; border-bottom: 2px solid var(--color-border);
}
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .meta { color: var(--color-text-soft); font-size: 13px; }

/* カード */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 14px;
  font-size: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  background: #fff; color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn:hover { background: #f0f4f8; text-decoration: none; }
.btn-primary {
  background: var(--color-primary); color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); color: #fff; }
.btn-danger {
  background: var(--color-danger); color: #fff; border-color: var(--color-danger);
}
.btn-danger:hover { background: #9b2c2c; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* フォーム */
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block; margin-bottom: 6px;
  font-weight: 600; font-size: 13px;
}
.form-row .required { color: var(--color-danger); margin-left: 4px; }
.form-row .hint { font-size: 12px; color: var(--color-text-soft); margin-top: 4px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.form-control:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(44,82,130,0.15);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.form-actions {
  display: flex; gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  margin-top: 20px;
}

/* 検索フィルタバー */
.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
@media (max-width: 900px) {
  .filter-bar { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 540px) {
  .filter-bar { grid-template-columns: 1fr; }
}

/* 属性バッジ */
.badge-owner {
  background: #fed7aa;
  color: #9a3412;
  font-weight: 600;
}

/* テーブル */
.table-wrapper { overflow-x: auto; }
table.data-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.data-table th, table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}
table.data-table th {
  background: #edf2f7;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
table.data-table tbody tr:hover { background: #f7fafc; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table .col-actions { width: 1%; white-space: nowrap; }

.box-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 13px; font-weight: 700;
  padding: 2px 8px; background: #edf2f7; border-radius: 4px;
}

/* バッジ */
.badge {
  display: inline-block;
  padding: 2px 8px; font-size: 12px;
  background: #e2e8f0; color: var(--color-text);
  border-radius: 999px;
}

/* フラッシュメッセージ */
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 1px solid;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.flash-error   { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger); }
.flash-warn    { background: var(--color-warn-bg); color: var(--color-warn); border-color: var(--color-warn); }

/* アイテムリスト（編集画面の動的追加） */
.items-list { display: flex; flex-direction: column; gap: 12px; }
.item-row {
  display: grid;
  grid-template-columns: 2fr 80px 2fr auto;
  gap: 8px; align-items: center;
}
@media (max-width: 600px) {
  .item-row { grid-template-columns: 1fr 1fr; }
}

/* アイテムカード（画像付き） */
.item-card {
  background: #fafbfc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
}
.item-fields {
  display: grid;
  grid-template-columns: 2fr 80px 2fr auto;
  gap: 8px; align-items: center;
}
@media (max-width: 600px) {
  .item-fields { grid-template-columns: 1fr 1fr; }
}
.item-photo {
  margin-top: 8px;
  display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap;
}
.item-photo-current {
  display: flex; gap: 8px; align-items: center;
}
.item-photo-current img {
  width: 60px; height: 60px; object-fit: cover;
  border-radius: 4px; border: 1px solid var(--color-border);
}
.item-photo-delete {
  font-size: 12px; color: var(--color-danger);
  display: inline-flex; align-items: center; gap: 4px;
}
.item-photo-upload {
  flex: 1;
  display: flex; flex-direction: column; gap: 4px;
}
.item-photo-upload input[type=file] { font-size: 13px; }

/* テーブル内のアイテムサムネ */
.item-thumb {
  width: 50px; height: 50px; object-fit: cover;
  border-radius: 4px; border: 1px solid var(--color-border);
  display: block;
}

/* ============================================================
   中身グリッド（詳細画面）
   ============================================================ */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
@media (max-width: 600px) {
  .item-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
  }
}
.item-card-link {
  display: block;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  padding: 0;
  transition: all 0.15s;
  width: 100%;
}
.item-card-link:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.item-card-image {
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #edf2f7 0%, #e2e8f0 100%);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.item-card-image img {
  width: 100%; height: 100%; object-fit: cover;
}
.item-card-placeholder {
  font-size: 36px; opacity: 0.5;
}
.item-card-body {
  padding: 8px 10px;
}
.item-card-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-card-meta {
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-qty {
  display: inline-block;
  background: var(--color-primary); color: #fff;
  padding: 1px 6px; border-radius: 999px;
  font-weight: 600; font-size: 11px;
}

/* ============================================================
   モーダル（アイテム詳細）
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modal-fade 0.15s ease-out;
}
.modal-overlay.open { display: flex; }
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-content {
  position: relative;
  background: #fff;
  border-radius: 8px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-image {
  background: #1a202c;
  display: flex; align-items: center; justify-content: center;
  min-height: 200px;
  max-height: 60vh;
  overflow: hidden;
}
.modal-image img {
  max-width: 100%; max-height: 60vh; object-fit: contain;
  display: block;
}
.modal-image-placeholder {
  font-size: 80px; opacity: 0.3; color: #fff;
}
.modal-body {
  padding: 18px 20px 22px;
}
.modal-title {
  margin: 0 0 8px; font-size: 18px;
}
.modal-qty {
  display: inline-block;
  background: var(--color-primary); color: #fff;
  padding: 3px 10px; border-radius: 999px;
  font-weight: 600; font-size: 13px;
  margin-bottom: 10px;
}
.modal-notes {
  font-size: 14px; color: var(--color-text); line-height: 1.5;
  white-space: pre-wrap;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: rgba(0,0,0,0.5); color: #fff;
  border: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 22px; line-height: 1;
  cursor: pointer; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.modal-close:hover { background: rgba(0,0,0,0.75); }

/* ============================================================
   QRボタンバー（詳細画面）
   ============================================================ */
.qr-button-bar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
}
.qr-button-info {
  display: flex; flex-direction: column; gap: 2px;
}

/* 写真ギャラリー */
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-thumb {
  position: relative; background: #edf2f7;
  border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 4/3;
}
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.photo-thumb .photo-delete {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: #fff;
  border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* QRコード表示 */
.qr-card {
  display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start;
}
.qr-image {
  background: #fff; padding: 16px;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  display: inline-block;
}
.qr-meta { flex: 1; min-width: 200px; }
.qr-url {
  font-family: ui-monospace, monospace;
  background: #f7fafc; padding: 8px 12px;
  border-radius: var(--radius);
  word-break: break-all; font-size: 13px;
}

/* 詳細表示 */
dl.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px; margin: 0;
}
dl.detail-list dt { font-weight: 600; color: var(--color-text-soft); font-size: 13px; }
dl.detail-list dd { margin: 0; }

/* 印刷ラベル用 */
.print-label {
  width: 60mm; padding: 4mm; border: 1px dashed #aaa;
  text-align: center;
}
.print-label .label-code { font-size: 14px; font-weight: 700; margin-top: 4mm; }
.print-label .label-name { font-size: 11px; color: #444; }

@media print {
  .site-header, .site-footer, .no-print, .form-actions, .btn { display: none !important; }
  body, .container { background: #fff; margin: 0; padding: 0; }
  .container { max-width: none; padding: 0; }
  .card { border: none; box-shadow: none; padding: 0; margin: 0; }
}

/* ユーザートップ（公開ページ仮置き） */
.public-hero {
  text-align: center; padding: 80px 20px;
  background: linear-gradient(135deg, #2c5282 0%, #1f3a5f 100%);
  color: #fff; border-radius: var(--radius);
}
.public-hero h1 { font-size: 28px; margin-top: 0; }
.public-hero p { opacity: 0.9; }

/* 空状態 */
.empty-state {
  padding: 60px 20px; text-align: center; color: var(--color-text-soft);
}
.empty-state h2 { font-size: 18px; margin: 0 0 8px; color: var(--color-text); }

/* ユーティリティ */
.text-soft { color: var(--color-text-soft); }
.text-success { color: var(--color-success); font-weight: 600; }
.text-danger  { color: var(--color-danger); font-weight: 600; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 16px; }
.gap-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   フェーズ2 追加スタイル
   ============================================================ */

/* ログイン画面 */
.auth-body {
  background: linear-gradient(135deg, #2c5282 0%, #1f3a5f 100%);
  min-height: 100vh;
}
.auth-shell {
  max-width: 380px;
  margin: 0 auto;
  padding: 60px 20px 40px;
}
.auth-brand {
  text-align: center;
  color: #fff;
  margin-bottom: 24px;
}
.auth-brand h1 { margin: 16px 0 4px; font-size: 28px; }
.auth-brand p  { margin: 0; opacity: 0.85; font-size: 14px; }
.auth-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  background: var(--color-accent); color: #fff;
  border-radius: 16px; font-weight: 800; font-size: 32px;
  box-shadow: var(--shadow-lg);
}

/* ダッシュボード */
.dashboard-hero {
  background: linear-gradient(135deg, #2c5282 0%, #1f3a5f 100%);
  color: #fff;
  padding: 32px 24px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  text-align: center;
}
.dashboard-hero h1 { margin: 0 0 8px; font-size: 22px; }
.dashboard-hero p  { margin: 0 0 20px; opacity: 0.9; }
.dashboard-actions {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
}
.dashboard-actions .btn { background: rgba(255,255,255,0.95); color: var(--color-primary); border: none; }
.dashboard-actions .btn:hover { background: #fff; }
.dashboard-actions .btn-primary { background: var(--color-accent); color: #fff; }
.dashboard-actions .btn-primary:hover { background: #b97a18; color: #fff; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.btn-lg .icon { font-size: 18px; margin-right: 4px; }

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

/* 最近の箱・検索結果カードリスト（モバイル向き） */
.recent-list { display: flex; flex-direction: column; gap: 10px; }
.recent-item {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none; color: var(--color-text);
  transition: all 0.15s;
}
.recent-item:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.recent-code {
  font-family: ui-monospace, monospace;
  font-size: 12px; color: var(--color-text-soft);
  font-weight: 700;
}
.recent-name {
  font-size: 16px; font-weight: 600; margin-top: 2px;
}
.recent-meta {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 6px; font-size: 13px;
}

/* インラインフォーム（属性管理など） */
.form-inline {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: end;
}
.form-inline .form-row { margin-bottom: 0; }

/* 属性リスト */
.owner-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.owner-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: #fafbfc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: all 0.15s;
}
.owner-row .drag-handle {
  cursor: default;
  color: transparent;
  font-size: 18px; line-height: 1;
  user-select: none;
  padding: 4px;
  width: 24px; text-align: center;
}
.owner-list.reorder-mode .owner-row {
  background: #fffbeb;
  border-color: var(--color-warn);
}
.owner-list.reorder-mode .drag-handle {
  cursor: grab;
  color: var(--color-text-soft);
}
.owner-list.reorder-mode .drag-handle:active { cursor: grabbing; }
.owner-list.reorder-mode .owner-actions { display: none; }
.owner-name { flex: 1; }
.owner-actions { display: flex; gap: 6px; }
.owner-row.editing .drag-handle { visibility: hidden; }
.sortable-ghost {
  opacity: 0.4;
  background: #fef3c7 !important;
}

/* QRスキャナー */
.qr-reader {
  max-width: 480px;
  margin: 0 auto 14px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 1/1;
}
.qr-reader video { width: 100%; height: 100%; object-fit: cover; }
.scan-status {
  text-align: center; padding: 10px; font-size: 14px;
}

/* スマホ向けナビ調整 */
@media (max-width: 600px) {
  .site-header-inner { padding: 10px 14px; }
  .site-nav { gap: 12px; font-size: 13px; }
  .site-nav .user-badge { display: none; }
  .container { padding: 0 12px; margin: 16px auto; }
  .page-header h1 { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .qr-card { gap: 14px; }
  .qr-image { padding: 10px; }
  .dashboard-hero { padding: 22px 16px; }
  .dashboard-hero h1 { font-size: 18px; }
  .btn-lg { padding: 10px 14px; font-size: 14px; }
}
