:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e6ec;
  --text: #1a2230;
  --muted: #6b7686;
  --primary: #1f6feb;
  --primary-dark: #175bc4;
  --receive: #128a5b;
  --pay: #c2410c;
  --sched: #7c3aed;
  --danger: #d23b3b;
  --warn-bg: #fff4e5;
  --warn-line: #ffcf8f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 4px 16px rgba(20, 30, 50, 0.06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; cursor: pointer; border: none; }
a { text-decoration: none; color: inherit; }

/* 上部バー */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ボタン */
.btn-primary { background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; font-weight: 600; white-space: nowrap; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); padding: 10px 16px; border-radius: 10px; font-size: 15px; }
.btn-ghost:hover { background: #eef1f5; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); padding: 10px 16px; border-radius: 10px; font-size: 15px; }
.btn-danger:hover { background: #fff0f0; }
.icon-btn { background: transparent; color: var(--muted); font-size: 15px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.icon-btn:hover { background: #eef1f5; }
.link-btn { background: transparent; color: var(--primary); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: #eef4ff; }

.view { max-width: 900px; margin: 0 auto; padding: 8px 16px 48px; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* 集計カード（一覧トップ） */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 8px 0 4px; }
.sum-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.sum-label { font-size: 12px; color: var(--muted); }
.sum-value { font-size: 20px; font-weight: 700; }
.sum-receive .sum-value { color: var(--receive); }
.sum-pay .sum-value { color: var(--pay); }

/* 取引先カード一覧 */
.list { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card:hover { border-color: #cdd6e3; }
.partner-card.archived { opacity: 0.55; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-title { font-size: 16px; font-weight: 700; flex: 1; }
.count-pill { background: var(--pay); color: #fff; font-size: 12px; font-weight: 700; min-width: 22px; height: 22px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.card-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* バッジ */
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px; border: 1px solid transparent; }
.badge.ok { background: #e8f6ef; color: var(--receive); }
.badge.pending { background: var(--warn-bg); color: #b45309; border-color: var(--warn-line); }
.badge.pay { background: #fdece3; color: var(--pay); border-color: #f6c9ad; }
.badge.sched { background: #f2ecfd; color: var(--sched); border-color: #ddccf7; }
.badge.none { background: #f0f2f5; color: #9aa4b2; }

/* 取引先ページ: 上部サマリ帯 */
.pstrip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 4px; }
.pstrip-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.pstrip .pl { font-size: 12px; color: var(--muted); }
.pstrip .pv { font-size: 18px; }
.pstrip .pv.receive { color: var(--receive); }
.pstrip .pv.pay { color: var(--pay); }
.partner-note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

.timeline-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 2px 8px; }
.timeline-head h3 { font-size: 14px; margin: 0; color: var(--muted); }

/* 台帳の各行 */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.entry { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; }
.entry:hover { border-color: #cdd6e3; }
.entry.pending { border-left: 4px solid var(--warn-line); }
.entry.is-done { opacity: 0.6; }
.entry-icon { font-size: 20px; flex: 0 0 auto; }
.entry-body { flex: 1; min-width: 0; }
.entry-main { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-main .flow { font-weight: 500; color: var(--muted); font-size: 13px; }
.entry-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.done-btn { flex: 0 0 auto; background: #e8f6ef; color: var(--receive); border: 1px solid #b7e3cc; font-size: 13px; font-weight: 700; padding: 8px 12px; border-radius: 8px; }
.done-btn:hover { background: #d7efe2; }
.qbtns { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.qbtns .mini-btn { padding: 6px 12px; }

/* タップで済にする「未」チップ（バッジと同じ見た目のボタン） */
.st-btn {
  background: var(--warn-bg); color: #b45309; border: 1px solid var(--warn-line);
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.st-btn:hover { background: #ffe9cc; }

/* モーダル */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 22, 34, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; z-index: 20; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 520px; box-shadow: 0 12px 48px rgba(10, 18, 30, 0.28); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); border-radius: 16px 16px 0 0; }
.modal-head h2 { margin: 0; font-size: 17px; }
.form { padding: 16px 18px 18px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field[hidden] { display: none; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field em { color: var(--danger); font-style: normal; font-size: 11px; margin-left: 4px; }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 15px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); width: 100%;
  min-height: 44px; /* 高さを揃える（日付欄の飛び出し防止） */
}
.field input[type="date"] {
  min-width: 0; max-width: 100%;
  -webkit-appearance: none; appearance: none; /* ブラウザ標準の見た目差をなくす */
}
.field select {
  -webkit-appearance: none; appearance: none; /* プルダウンの高さも統一 */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7686' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.15);
}
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 4px 0 10px; cursor: pointer; }
.check[hidden] { display: none; }
.check input { width: 18px; height: 18px; }

/* 種類の切り替えボタン */
.type-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.type-btn { background: #f0f2f5; color: var(--muted); font-size: 14px; font-weight: 600; padding: 10px 4px; border-radius: 10px; border: 1px solid transparent; }
.type-btn.active { background: #e8f0ff; color: var(--primary); border-color: var(--primary); }

.modal-foot { display: flex; align-items: center; gap: 10px; padding-top: 4px; }
.modal-foot .spacer { flex: 1; }

/* ホーム画面 */
.home { min-height: calc(100vh - 40px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 16px; }
.home-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: var(--shadow); padding: 40px 28px; max-width: 380px; width: 100%;
}
.home-mascot { position: relative; font-size: 56px; line-height: 1; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.home-spark { position: absolute; right: -10px; bottom: -4px; font-size: 26px; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.home-title { font-size: 26px; margin: 18px 0 6px; letter-spacing: 0.5px; }
.home-tag { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.home-sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; white-space: nowrap; }
.home-start { font-size: 16px; padding: 14px 28px; border-radius: 999px; }
.home-foot { margin-top: 22px; font-size: 12px; color: #9aa4b2; letter-spacing: 1px; }

/* 共有まわり */
.badge.hide { background: #eef0f3; color: #64748b; border-color: #d6dbe2; }
.badge.confirm { background: #e6f0ff; color: var(--primary); border-color: #bcd4ff; }

.share-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0 4px; box-shadow: var(--shadow); }
.share-box h3 { margin: 0 0 8px; font-size: 14px; }
.share-off { color: var(--muted); font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.share-url { display: flex; gap: 8px; margin: 8px 0; }
.share-url input { flex: 1; font-size: 13px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #f7f9fc; color: var(--muted); }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.mini-btn { background: #f0f2f5; color: var(--text); font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 8px; }
.mini-btn:hover { background: #e6e9ee; }
.mini-btn.warn { color: var(--pay); }
.mini-btn.stop { color: var(--danger); }
.share-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* 合言葉ゲート（相手側） */
.gate { display: flex; justify-content: center; padding: 40px 8px; }
.gate-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 24px; max-width: 360px; width: 100%; text-align: center; }
.gate-card h2 { font-size: 18px; margin: 0 0 8px; }
.gate-note { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.gate-card input { width: 100%; font-size: 18px; text-align: center; letter-spacing: 2px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; }
.gate-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,111,235,0.15); }
.gate-card .btn-primary { width: 100%; }
.gate-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 12px 0 0; }

/* スマホ */
@media (max-width: 560px) {
  .summary { grid-template-columns: 1fr; }
  .sum-card { flex-direction: row; align-items: center; justify-content: space-between; }
  .pstrip { grid-template-columns: 1fr; }
  .pstrip-item { flex-direction: row; align-items: center; justify-content: space-between; }
  .type-picker { grid-template-columns: repeat(2, 1fr); }
}
