/* 共通スタイル */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2456a5;
  --primary-dark: #1a4180;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #26303c;
  --muted: #6b7684;
  --border: #d8dee8;
  --danger: #c0392b;
}

body {
  font-family: "Meiryo", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ===== ログイン ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
}
.login-card h1 {
  font-size: 19px;
  text-align: center;
  margin-bottom: 4px;
}
.login-card .subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 24px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}
.btn {
  display: inline-block;
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { background: #9db3d6; cursor: default; }
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 1.2em;
  text-align: center;
}
.version-note {
  text-align: center;
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 20px;
}

/* ログイン画面: パスワードとパスキーの区切り */
.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--muted);
  font-size: 12px;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid #dfe4ec;
}
.login-hint {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
  margin: 8px 0 0;
  text-align: center;
}

/* ===== ヘッダー（共通） ===== */
.app-header {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
}
.app-header h1 { font-size: 16px; flex: 1; }
.user-badge {
  font-size: 13px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 4px 12px;
}
.btn-logout {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn-logout:hover { background: rgba(255, 255, 255, 0.12); }

/* ===== メニュー ===== */
.menu-container {
  max-width: 1080px;
  margin: 26px auto;
  padding: 0 16px;
}
.menu-group { margin-bottom: 26px; }
.menu-group h2 {
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 12px;
}
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}
.menu-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.15s;
}
.menu-item:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.09);
  transform: translateY(-1px);
}
.menu-item .title { font-size: 15px; font-weight: bold; }
.menu-item .desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.5;
}
.menu-item.disabled { opacity: 0.55; cursor: default; }
.menu-item.disabled:hover { box-shadow: none; transform: none; }
.tag-todo {
  display: inline-block;
  font-size: 10.5px;
  color: #8a6d1a;
  background: #fdf3d5;
  border-radius: 4px;
  padding: 1px 6px;
  margin-top: 6px;
}
.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 30px 0 20px;
}

/* ===== 業務画面共通 ===== */
.header-back {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  padding: 5px 10px;
  white-space: nowrap;
}
.header-back:hover { background: rgba(255, 255, 255, 0.12); }

.page-container {
  max-width: 1180px;
  margin: 20px auto;
  padding: 0 16px;
}
/* 列数の多い帳票用。画面幅いっぱいまで使う */
.page-container.page-wide {
  max-width: 1800px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
}
.panel h2 {
  font-size: 15px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 14px;
}
.toolbar .field { margin-bottom: 0; }
.toolbar .field input, .toolbar .field select {
  width: auto;
  min-width: 160px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.toolbar .spacer { flex: 1; }

.btn-inline {
  width: auto;
  padding: 9px 18px;
  font-size: 14px;
}
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: #eef3fb; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #96271b; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; width: auto; }

/* テーブル */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--card);
}
table.data th, table.data td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
}
table.data th {
  background: #e9eef6;
  font-weight: bold;
  position: sticky;
  top: 0;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: #f0f5fd; }
table.data tbody tr.selected { background: #dce8fa; }
table.data td.num, table.data th.num { text-align: right; }
.table-note { color: var(--muted); font-size: 12.5px; margin: 8px 0; }

/* 列数の多い表用。見出しを折り返して列幅を詰め、全列を画面内に収める */
table.data.compact th, table.data.compact td {
  padding: 5px 7px;
  font-size: 12.5px;
}
table.data.compact thead th {
  white-space: normal;
  line-height: 1.25;
}
/* 入力欄を含む表（裁断実績登録など）は入力欄も併せて詰める */
table.data.compact input,
table.data.compact select {
  padding: 4px 6px;
  font-size: 12.5px;
}
table.bom-editor.compact input { width: 68px; }
table.bom-editor.compact input.code-input,
table.bom-editor.compact select.code-input { width: 104px; }

/* フォームグリッド */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 16px;
  margin-bottom: 14px;
}
.form-grid .field { margin-bottom: 0; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.form-grid input:focus, .form-grid select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}
.form-grid input[readonly], .form-grid input:disabled, .form-grid select:disabled {
  background: #eef0f4;
  color: var(--muted);
}
.field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.check-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  padding-top: 22px;
}

/* バッジ */
.badge {
  display: inline-block;
  font-size: 12px;
  border-radius: 10px;
  padding: 2px 10px;
  color: #fff;
}
.badge-gray { background: #8b95a3; }
.badge-blue { background: #3b7bd4; }
.badge-teal { background: #17948d; }
.badge-green { background: #2e9e4f; }
.badge-dark { background: #45506b; }
.badge-yellow { background: #d99b18; }
.badge-red { background: var(--danger); }

/* BOMエディタ */
table.bom-editor input {
  width: 90px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}
table.bom-editor input.code-input { width: 110px; }
table.bom-editor .row-note { font-size: 12px; color: var(--muted); white-space: normal; }

/* トースト */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333f4f;
  color: #fff;
  border-radius: 8px;
  padding: 11px 22px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 1000;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }

/* ページャ */
.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  font-size: 13.5px;
}

/* 同じ資材でまとめた列は上下の罫線を消して1つのセルに見せる
   （border-collapse では隣接セルの罫線が競合するため、両側を透明にする必要がある） */
table.data tbody td.cell-merged { border-top-color: transparent; }
table.data tbody td.cell-merged-above { border-bottom-color: transparent; }

/* 資材が変わる境界の横罫線だけ濃くする。
   罫線は隣接セル同士で競合するため、境界の上下（group-end の下・group-start の上）に指定する */
table.data tbody tr.group-end td { border-bottom-color: var(--muted); }
table.data tbody tr.group-start td { border-top-color: var(--muted); }

/* 入力エラーの強調（ロットと資材の不一致など） */
input.input-error,
table.data input.input-error {
  border: 2px solid var(--danger);
  background: #fdf0ee;
}

/* 集計から除外した行（原反所要量など） */
table.data tbody tr.row-excluded td {
  color: var(--muted);
  text-decoration: line-through;
  background: #f4f5f7;
}
table.data tbody tr.row-excluded td:first-child {
  text-decoration: none;
}

/* 情報ボックス（オーダー情報表示等） */
.info-box {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 18px;
  background: #f6f8fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.info-box .label { color: var(--muted); font-size: 12px; }
.info-box .value { font-weight: bold; }

/* 印刷用（帳票画面）。現行ExcelがすべてA4横のため用紙もそれに合わせる */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body { background: #fff; font-size: 11px; }
  .app-header, .toolbar, .no-print, .form-actions, .btn, .pager { display: none !important; }
  .page-container, .page-container.page-wide { max-width: none; margin: 0; padding: 0; }
  .panel { border: none; padding: 0; margin: 0; }

  /* 画面用の横スクロール枠は、印刷時に枠外を切り落としてしまうため解除する */
  .table-wrap { overflow: visible !important; }

  table.data { width: 100%; table-layout: auto; }
  table.data th, table.data td { padding: 3px 5px; font-size: 10px; }
  table.data.compact th, table.data.compact td { padding: 2px 4px; font-size: 9px; }
  table.data th { position: static; white-space: normal; }
  /* 見出しはページごとに繰り返し、行は途中で切らない */
  table.data thead { display: table-header-group; }
  table.data tr { page-break-inside: avoid; }

  .print-title { display: block !important; font-size: 14px; margin-bottom: 6px; }
}
.print-title { display: none; }
