* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, sans-serif;
  background: #f5f7fa;
  color: #2d3748;
  line-height: 1.6;
  padding: 1rem;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 0.9rem;
  opacity: 0.9;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e2e8f0;
  color: #1a202c;
}

.info-box {
  background: #f7fafc;
  border-left: 4px solid #4f46e5;
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 4px;
  font-size: 0.9rem;
}

.info-box ul, .info-box ol {
  padding-left: 1.5rem;
  margin-top: 0.25rem;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: #4f46e5;
  color: white;
}

.btn-primary:hover {
  background: #4338ca;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #e2e8f0;
  color: #2d3748;
}

.btn-secondary:hover {
  background: #cbd5e0;
}

.result-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.meta-item {
  background: #edf2f7;
  padding: 0.75rem;
  border-radius: 6px;
  text-align: center;
}

.meta-label {
  font-size: 0.75rem;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2d3748;
  margin-top: 0.25rem;
}

.meta-value.match { color: #38a169; }
.meta-value.mismatch { color: #e53e3e; }

.result-content {
  background: #1a202c;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 6px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre;
  max-height: 500px;
  overflow-y: auto;
}

.code-block {
  background: #2d3748;
  color: #e2e8f0;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  margin: 0.5rem 0;
  overflow-x: auto;
}

.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.api-table th, .api-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

.api-table th {
  background: #f7fafc;
  font-weight: 600;
  color: #4a5568;
}

.api-table code {
  background: #edf2f7;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: #2d3748;
}

.hidden { display: none; }

.success { color: #38a169; }
.error { color: #e53e3e; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fed7d7;
  color: #c53030;
  border-left: 4px solid #e53e3e;
}

/* ============================================
   Phase 2: Master management UI
   ============================================ */

/* ナビゲーションバー */
.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  background: white;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.main-nav a {
  text-decoration: none;
  color: #4a5568;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}

.main-nav a:hover {
  background: #edf2f7;
  color: #4f46e5;
}

.main-nav a.active {
  background: #4f46e5;
  color: white;
}

/* DB状態カード */
.db-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.db-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0.75rem;
  background: linear-gradient(135deg, #edf2f7 0%, #e2e8f0 100%);
  border-radius: 8px;
}

.db-label {
  font-size: 0.75rem;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.db-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #4f46e5;
  margin-top: 0.25rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.db-info {
  font-size: 0.85rem;
  color: #718096;
  text-align: right;
}

/* マスタ管理 カードヘッダ */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-header h2 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.filters {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.filters input[type="search"],
.filters select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
}

.filters label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #4a5568;
}

/* データテーブル */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th, .data-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.data-table th {
  background: #f7fafc;
  font-weight: 600;
  color: #4a5568;
  position: sticky;
  top: 0;
}

.data-table tbody tr:hover {
  background: #f7fafc;
}

.data-table code {
  background: #edf2f7;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: #2d3748;
}

.data-table.compact {
  font-size: 0.8rem;
}
.data-table.compact th,
.data-table.compact td {
  padding: 0.4rem 0.5rem;
}

.kana-cell {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-meta {
  font-size: 0.85rem;
  color: #718096;
  margin-bottom: 0.5rem;
}

/* バッジ */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-admin {
  background: #fed7d7;
  color: #c53030;
}

.badge-staff {
  background: #c6f6d5;
  color: #2f855a;
}

.badge-fb {
  background: #bee3f8;
  color: #2c5282;
}

/* 小ボタン */
.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  margin-right: 0.2rem;
  background: #e2e8f0;
  color: #2d3748;
  border-radius: 4px;
}
.btn-small:hover {
  background: #cbd5e0;
}
.btn-danger {
  background: #fed7d7;
  color: #c53030;
}
.btn-danger:hover {
  background: #feb2b2;
}
.btn-warn {
  background: #fefcbf;
  color: #744210;
}
.btn-warn:hover {
  background: #faf089;
}

/* 担当者プルダウン (組合画面: 即保存) */
.manager-select {
  padding: 0.3rem 0.5rem;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  background: white;
  font-size: 0.9rem;
  min-width: 120px;
  transition: background 0.6s ease-out, border-color 0.2s;
}
.manager-select:hover {
  border-color: #4f46e5;
}
.manager-select:disabled {
  opacity: 0.6;
  cursor: wait;
}
.manager-select.saved-flash {
  background: #c6f6d5;
  border-color: #38a169;
}

/* ローダー */
.loader {
  color: #718096;
  font-style: italic;
  padding: 1rem;
}

/* モーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: #2d3748;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #718096;
  padding: 0 0.5rem;
}

.modal-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.modal-body {
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.field {
  display: block;
  margin-bottom: 0.75rem;
}

.field span {
  display: block;
  font-size: 0.8rem;
  color: #4a5568;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.field-checkbox span {
  margin-bottom: 0;
}
.field-checkbox input {
  width: auto;
}

/* トースト通知 */
.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: #2d3748;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 2000;
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s;
}
.toast.show {
  opacity: 1;
  transform: translateX(0);
}
.toast-error {
  background: #c53030;
}
.toast-info {
  background: #2c5282;
}

/* ============================================================
 * Phase 3 #1: 振込明細入力 UI (/transfer)
 * ============================================================ */

/* 振込元設定フォーム */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.form-row label {
  font-size: 0.8rem;
  color: #4a5568;
  font-weight: 600;
}
.form-row select,
.form-row input[type="number"],
.form-row input[type="text"] {
  padding: 0.5rem 0.6rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.form-row select:focus,
.form-row input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

/* 明細表 */
.transfer-rows {
  margin: 0.5rem 0 1rem;
}
.rows-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.rows-table th,
.rows-table td {
  border: 1px solid #e2e8f0;
  padding: 0.5rem;
  vertical-align: top;
}
.rows-table th {
  background: #edf2f7;
  font-weight: 600;
  text-align: left;
}
.rows-table input[type="number"],
.rows-table input[type="text"] {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
}
.acc-detail {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: #4a5568;
}
.acc-line1 {
  font-weight: 600;
  color: #2d3748;
}
.acc-line2 {
  font-size: 0.75rem;
  color: #718096;
  margin-top: 0.1rem;
}

/* 小ボタン (admin.js の .btn-small と統一しつつ別名も用意) */
.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 4px;
}

/* バッジ */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 999px;
  background: #c6f6d5;
  color: #22543d;
  margin-left: 0.4rem;
}
.badge-warn {
  background: #fefcbf;
  color: #744210;
}
.badge-ok {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  background: #38a169;
  color: #fff;
  margin-left: 0.4rem;
}

/* 一括振込テーブル: 未設定行 */
.row-disabled {
  background: #f7fafc;
  color: #a0aec0;
}
.row-disabled .row-amount {
  background: #edf2f7;
}
.row-amount {
  width: 9rem;
  text-align: right;
  padding: 0.3rem 0.5rem;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
}

/* テキスト補助 */
.text-muted {
  color: #718096;
  font-style: italic;
}
.text-error {
  color: #c53030;
}

/* 受取人ピッカー (ワイドモーダル) */
.modal-wide {
  max-width: 1100px !important;
  width: 95vw !important;
}
.rp-result {
  max-height: 50vh;
  overflow-y: auto;
  margin-top: 0.5rem;
  border-top: 1px solid #e2e8f0;
  padding-top: 0.5rem;
}
.rp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.rp-table th,
.rp-table td {
  border-bottom: 1px solid #edf2f7;
  padding: 0.4rem 0.5rem;
  vertical-align: top;
}
.rp-table th {
  background: #f7fafc;
  position: sticky;
  top: 0;
  text-align: left;
}
.rp-table tr:hover {
  background: #f7fafc;
}

/* プレビュー領域は等幅 + 横スクロール */
.result-content {
  background: #1a202c;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre;
  max-height: 60vh;
  overflow-y: auto;
}

/* Phase 3 #2: 履歴照会 UI */
.pager {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  padding: 0.5rem;
}
.pager .text-muted {
  font-style: normal;
  font-size: 0.85rem;
}
.filters input[type="date"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
}

/* ==================================================
 * Phase 3 #3: 認証 UI
 * ================================================== */

/* ヘッダ: タイトル + 右上ユーザバッジ */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-header > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  flex: 0 0 auto;
}
.user-badge .user-name {
  color: #1a202c;
  font-weight: 600;
}
.user-badge .user-role {
  color: #718096;
  font-weight: 400;
  font-size: 0.78rem;
}
.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

/* ログインページ */
.login-container {
  max-width: 480px;
  margin: 4rem auto;
}
.login-card {
  padding: 2rem;
}
.login-card .form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-card .form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.login-card .form-row label {
  font-weight: 600;
  color: #2d3748;
  font-size: 0.9rem;
}
.login-card .form-row input {
  padding: 0.55rem 0.7rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
}
.login-card .form-row input:focus {
  outline: none;
  border-color: #4299e1;
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.15);
}
.login-card .form-row button {
  margin-top: 0.5rem;
}

.error-box {
  padding: 0.7rem 0.9rem;
  background: #fff5f5;
  border: 1px solid #fc8181;
  color: #c53030;
  border-radius: 6px;
  font-size: 0.85rem;
}
.error-box.hidden {
  display: none;
}

/* ====================================================
 * 振込明細入力 (/transfer): 操作カードを画面上部に sticky
 * ボタンへのアクセスを「最下部までスクロール」から「常時表示」に改善
 * ==================================================== */
.card-sticky-action {
  position: sticky;
  top: 0.5rem;
  z-index: 50;
  /* sticky 中であることを視覚的に示すため、影を少し強めて立体感 */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  /* 半透明背景でスクロール中の下の要素が透ける感じを抑える */
  background: #ffffff;
  /* 上の余白を少し減らしてコンパクトに */
  padding: 1rem 1.5rem;
}
.card-sticky-action h2 {
  margin-bottom: 0.5rem;
}
.card-sticky-action .result-meta {
  margin-top: 0.5rem;
}
/* ヘッダー右側にボタンを並べる */
.action-buttons-inline {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
/* sticky カードの主要ボタンは少し目立たせる */
.card-sticky-action .btn-primary {
  font-weight: 600;
  padding: 0.6rem 1.2rem;
}
