:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #1f2733;
  --muted: #6b7686;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0fe;
  --success: #16a34a;
  --success-soft: #e8f6ec;
  --warn: #d97706;
  --warn-soft: #fdf2e2;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --info: #0ea5e9;
  --info-soft: #e6f6fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.04);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: #1e2435;
  color: #c8cfdd;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.brand .title { font-size: 14px; font-weight: 700; color: #fff; line-height: 1.3; }
.brand .subtitle { font-size: 11px; color: #8b94a8; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 10.5px; font-weight: 700; letter-spacing: 1px; color: #6b7488; padding: 16px 12px 6px; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px;
  color: #c8cfdd; background: none; border: none;
  font-size: 13.5px; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
.nav-item .badge-count {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
}
.nav-item.active .badge-count { background: rgba(255,255,255,0.25); }

.sidebar-footer { margin-top: auto; padding: 12px 8px 0; font-size: 11px; color: #6b7488; border-top: 1px solid rgba(255,255,255,0.08); }

.main { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { font-size: 15px; margin: 0; }

/* ---------- KPI grid ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 8px; letter-spacing: -0.5px; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--muted); }
.kpi.accent-warn .value { color: var(--warn); }
.kpi.accent-info .value { color: var(--info); }
.kpi.accent-success .value { color: var(--success); }
.kpi-click { cursor: pointer; transition: box-shadow .15s, transform .15s, border-color .15s; }
.kpi-click:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(79,70,229,0.12); transform: translateY(-2px); }
.kpi-click .label::after { content: " ›"; color: var(--muted); font-weight: 700; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.btn:hover { background: #f7f8fc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-warn:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 11px 14px; color: var(--muted); font-weight: 600;
  font-size: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: #fafbfd;
}
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: #fcfcff; }
.t-num { text-align: right; font-variant-numeric: tabular-nums; }
tr.tbl-total td { background: #fafbfd; border-top: 2px solid var(--border); }
tr.clickable-row { cursor: pointer; }
tr.clickable-row:hover td { background: var(--primary-soft); }
tr.detail-row td { background: #f7f8fc; padding: 0; }
.detail-box { padding: 12px 16px 14px; }
.detail-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
table.tbl.mini { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table.tbl.mini th, table.tbl.mini td { padding: 8px 12px; }
.t-strong { font-weight: 600; }
.t-sub { color: var(--muted); font-size: 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-gray { background: #eef1f6; color: #5b6573; }
.badge-blue { background: var(--info-soft); color: #0369a1; }
.badge-amber { background: var(--warn-soft); color: #b45309; }
.badge-violet { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: var(--success-soft); color: #15803d; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.col-2 { grid-column: span 2; }
.field label { font-size: 12.5px; font-weight: 600; color: #3d4757; }
.field label .req { color: var(--danger); margin-left: 3px; }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); outline: none; transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint { font-size: 11px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17, 24, 39, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25); animation: pop .16s ease-out;
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x-btn { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; padding: 2px 6px; border-radius: 6px; }
.x-btn:hover { background: #f0f1f5; color: var(--text); }

/* ---------- Misc ---------- */
.list-row { display: flex; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: #fcfcff; }
.list-row .lr-main { width: 180px; flex-shrink: 0; }
.list-row .lr-mid { flex: 1; min-width: 0; }
.list-row .lr-mid > div:first-child { font-size: 13px; }
.list-row .lr-mid .money { color: var(--text); font-size: 13px; margin-top: 2px; }
.list-row > .btn { flex-shrink: 0; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 38px; margin-bottom: 8px; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.pill-tabs { display: inline-flex; background: #eceef4; border-radius: 10px; padding: 3px; gap: 2px; }
.pill-tabs button { border: none; background: none; padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pill-tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumb button { background: none; border: none; color: var(--primary); font-size: 13px; padding: 0; }
.crumb button:hover { text-decoration: underline; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.fee-log-flag { font-size: 10.5px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 5px; padding: 1px 5px; display: inline-block; margin-top: 3px; }
.cell-date { padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px; color: var(--text); background: #fff; outline: none; }
.cell-date:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.link-btn { background: none; border: none; padding: 0; color: var(--primary); font-weight: 600; font-size: 13px; text-align: left; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.status-select { padding: 5px 9px; border-radius: 7px; border: 1px solid var(--border); font-size: 12.5px; font-weight: 700; outline: none; cursor: pointer; }
.status-select:focus { box-shadow: 0 0 0 3px var(--primary-soft); }
.status-select.ps-active  { color: #0369a1; background: var(--info-soft);    border-color: #bae0f3; }
.status-select.ps-delayed { color: #b91c1c; background: var(--danger-soft);  border-color: #f3c6c6; }
.status-select.ps-action  { color: #b45309; background: var(--warn-soft);    border-color: #f0d9ad; }
.status-select.ps-done    { color: #15803d; background: var(--success-soft); border-color: #bfe3c8; }
.inline-note { background: var(--info-soft); border: 1px solid #bce4f5; color: #075985; padding: 10px 14px; border-radius: 9px; font-size: 12.5px; display: flex; gap: 8px; }

/* ---------- Notice doc (支払い通知書) ---------- */
.notice-doc { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 30px 34px; font-size: 13px; color: #222; }
.notice-doc h2 { text-align: center; font-size: 18px; letter-spacing: 4px; margin: 0 0 24px; }
.notice-doc .nd-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.notice-doc .nd-to { font-size: 15px; font-weight: 700; margin: 14px 0 18px; }
.notice-doc .nd-total { background: var(--primary-soft); border-radius: 8px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }
.notice-doc .nd-total .amt { font-size: 24px; font-weight: 800; color: var(--primary-dark); }
.notice-doc table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12.5px; }
.notice-doc table th, .notice-doc table td { border: 1px solid #d6dbe5; padding: 7px 10px; }
.notice-doc table th { background: #f6f7fb; text-align: left; }
.notice-doc .nd-bank { background: #fafbfd; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-top: 14px; font-size: 12.5px; }
.notice-doc .nd-foot { margin-top: 22px; text-align: right; color: var(--muted); font-size: 12px; }

.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: #1e2435; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px; display: flex; align-items: center; gap: 9px; animation: pop .16s; max-width: 360px; }
.toast.ok { background: #14532d; }
.toast.info { background: #075985; }
.toast-undo { background: rgba(255,255,255,0.16); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 7px; padding: 4px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.toast-undo:hover { background: rgba(255,255,255,0.28); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
