* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --navy: #1a365d; --blue: #2b6cb0; --sky: #4299e1;
  --bg: #eef2f7; --card: #fff; --text: #1a202c; --muted: #718096; --line: #e2e8f0;
  --red: #e53e3e; --red-soft: #fff5f5; --amber: #d69e2e; --amber-soft: #fffbeb;
  --green: #38a169; --green-soft: #f0fff4;
  --radius: 16px; --shadow: 0 2px 10px rgba(26, 54, 93, .08);
}
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ===== ログイン ===== */
.login { position: fixed; inset: 0; background: linear-gradient(160deg, var(--navy), var(--blue)); display: flex; align-items: center; justify-content: center; z-index: 100; }
.login-box { background: var(--card); padding: 36px 28px; border-radius: 24px; width: min(88%, 340px); text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.login-icon { font-size: 3rem; }
.login-box h1 { font-size: 1.25rem; margin: 6px 0 20px; }
.login-box input { width: 100%; padding: 15px; font-size: 1.2rem; border: 1.5px solid var(--line); border-radius: 14px; margin-bottom: 12px; text-align: center; letter-spacing: .3em; }
.err { color: var(--red); font-size: .85rem; min-height: 1.2em; margin-top: 10px; }

/* ===== レイアウト ===== */
#view { padding: calc(8px + env(safe-area-inset-top)) 14px 110px; max-width: 640px; margin: 0 auto; }
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: flex-end; background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
#tabs button { flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 52px; cursor: pointer; color: var(--muted); justify-content: center; }
#tabs .ti { font-size: 1.35rem; }
#tabs .tl { font-size: .66rem; font-weight: 600; }
#tabs button.active { color: var(--blue); }
#fab {
  flex: 0 0 62px !important; height: 62px; margin: 0 4px 6px; border-radius: 50% !important;
  background: linear-gradient(150deg, var(--sky), var(--navy)) !important; color: #fff !important;
  box-shadow: 0 6px 16px rgba(43,108,176,.45); align-self: center;
}
#fab span { font-size: 2rem; font-weight: 300; line-height: 1; }
#fab:active { transform: scale(.93); }

/* ===== カード ===== */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { font-size: .82rem; color: var(--muted); margin-bottom: 10px; font-weight: 700; letter-spacing: .02em; }
.card h2 .link { float: right; color: var(--blue); font-weight: 600; font-size: .78rem; cursor: pointer; }

/* ヒーロー */
.hero {
  background: linear-gradient(150deg, #2c5282, var(--navy) 70%); color: #fff;
  border-radius: 20px; padding: 20px 18px 16px; margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(26,54,93,.35);
}
.hero .label { font-size: .8rem; opacity: .85; font-weight: 600; }
.hero .big { font-size: 2.4rem; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; }
.hero .big .yen { font-size: 1.3rem; font-weight: 600; opacity: .8; margin-right: 2px; }
.hero .big.minus { color: #feb2b2; }
.hero .sub { display: flex; gap: 16px; margin-top: 10px; font-size: .78rem; opacity: .9; }
.hero .sub b { font-size: .95rem; display: block; }
.hero-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-side { text-align: right; font-size: .72rem; opacity: .92; flex: 0 0 auto; }
.hero-side > div { margin: 3px 0; }
.hero-side span { display: block; opacity: .8; }
.hero-side b { font-size: .95rem; }
.hero details { margin-top: 10px; font-size: .82rem; }
.hero summary { opacity: .8; cursor: pointer; font-size: .75rem; }
.hero .drow { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.15); }

/* ===== 支払い行 ===== */
.pay-item { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); transition: opacity .3s, transform .3s; }
.pay-item:last-child { border-bottom: none; }
.pay-item.leaving { opacity: 0; transform: translateX(40px); }
.pay-item .due {
  flex: 0 0 52px; text-align: center; border-radius: 12px; padding: 5px 2px;
  background: #edf2f7; color: var(--muted); line-height: 1.15;
}
.pay-item .due .d1 { font-size: .95rem; font-weight: 800; display: block; }
.pay-item .due .d2 { font-size: .6rem; font-weight: 600; }
.pay-item .due.today { background: var(--red); color: #fff; }
.pay-item .due.soon { background: var(--amber-soft); color: var(--amber); }
.pay-item .due.overdue { background: var(--red-soft); color: var(--red); border: 1.5px solid var(--red); }
.pay-item .body { flex: 1; min-width: 0; cursor: pointer; }
.pay-item .name { font-size: .95rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-item .amount { font-size: 1.15rem; font-weight: 800; }
.pay-item .amount .yen { font-size: .8rem; font-weight: 600; color: var(--muted); }
.pay-item .tags { font-size: .68rem; color: var(--muted); }
.paid-btn {
  flex: 0 0 auto; border: none; border-radius: 999px; padding: 10px 14px; min-height: 44px;
  background: var(--green-soft); color: var(--green); font-weight: 800; font-size: .85rem; cursor: pointer;
  border: 1.5px solid #c6f6d5;
}
.paid-btn:active { transform: scale(.94); background: var(--green); color: #fff; }
.paid-btn.amt-btn { background: var(--amber-soft); color: var(--amber); border-color: #fbd38d; }

.group-head { font-size: .78rem; font-weight: 800; color: var(--muted); margin: 16px 4px 6px; }
.group-head.alert { color: var(--red); }

/* ===== 借金メーター ===== */
.meter { height: 10px; border-radius: 999px; background: #e2e8f0; overflow: hidden; margin: 6px 0 4px; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--sky), var(--green)); transition: width .6s ease; }
.debt-card .row1 { display: flex; align-items: center; justify-content: space-between; }
.debt-card .dname { font-weight: 800; font-size: 1rem; }
.debt-card .dbal { font-weight: 800; font-size: 1.15rem; }
.debt-card .dmeta { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: 2px; }
.badge-done { background: var(--green-soft); color: var(--green); font-weight: 800; border-radius: 999px; padding: 2px 10px; font-size: .75rem; }

/* ===== 汎用リスト行 ===== */
.li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.li:last-child { border-bottom: none; }
.li .ic { flex: 0 0 36px; height: 36px; border-radius: 10px; background: #edf2f7; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.li .bd { flex: 1; min-width: 0; }
.li .t1 { font-size: .92rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .t2 { font-size: .7rem; color: var(--muted); }
.li .amt { font-weight: 800; font-size: 1rem; white-space: nowrap; }
.li .amt.in { color: var(--green); }
.li .amt.ex { color: #a0aec0; font-weight: 600; }

.chip { display: inline-block; font-size: .66rem; padding: 1px 8px; border-radius: 999px; background: #edf2f7; color: var(--muted); font-weight: 600; }
.chip.warn { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.blue { background: #ebf4ff; color: var(--blue); }

/* ===== ボトムシート ===== */
.sheet-bg { position: fixed; inset: 0; background: rgba(15,25,40,.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
@keyframes fade { from { opacity: 0 } }
.sheet {
  background: var(--card); border-radius: 22px 22px 0 0; width: 100%; max-width: 640px;
  max-height: 92vh; overflow-y: auto; padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(40%); } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 1.05rem; font-weight: 800; margin-bottom: 12px; }

/* フォーム */
label { display: block; font-size: .74rem; color: var(--muted); margin: 12px 0 4px; font-weight: 700; }
input, select, textarea {
  width: 100%; padding: 13px; font-size: 1rem; border: 1.5px solid var(--line);
  border-radius: 12px; background: #fff; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--sky); }
.amount-input { font-size: 1.7rem !important; font-weight: 800; text-align: center; padding: 16px !important; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: .85rem; margin-top: 12px; }
.check-line input { width: 20px; height: 20px; }

.btn { display: block; width: 100%; padding: 15px; border: none; border-radius: 14px; font-size: 1.05rem; font-weight: 800; cursor: pointer; margin-top: 16px; min-height: 50px; font-family: inherit; }
.btn.primary { background: linear-gradient(150deg, var(--sky), var(--navy)); color: #fff; box-shadow: 0 4px 12px rgba(43,108,176,.35); }
.btn.primary:active { transform: scale(.98); }
.btn.small { padding: 9px 16px; font-size: .85rem; width: auto; display: inline-block; margin-top: 0; min-height: 42px; border-radius: 10px; }
.btn.ghost { background: #edf2f7; color: var(--text); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* 区分ボタン・チップ */
.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.type-grid button {
  padding: 9px 2px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  font-size: .72rem; font-weight: 700; cursor: pointer; min-height: 56px; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-family: inherit;
}
.type-grid button .em { font-size: 1.15rem; }
.type-grid button.sel { border-color: var(--blue); background: #ebf4ff; color: var(--navy); }
.suggest-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; -webkit-overflow-scrolling: touch; }
.suggest-row button {
  flex: 0 0 auto; border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: .8rem; font-weight: 700; cursor: pointer; font-family: inherit;
}
.suggest-row button:active { background: #ebf4ff; border-color: var(--blue); }
.hint { border-radius: 10px; padding: 8px 12px; font-size: .78rem; margin-top: 10px; }
.hint.pl { background: #ebf4ff; color: var(--navy); }
.hint.nopl { background: var(--amber-soft); color: #975a16; }

/* テーブル・グラフ */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .8rem; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 700; }
.chart { width: 100%; height: auto; }
.chart .bar-in { fill: #68d391; }
.chart .bar-out { fill: #fc8181; }
.chart text { font-size: 10px; fill: var(--muted); }

/* メニューリスト(その他) */
.menu { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 12px; }
.menu button {
  display: flex; width: 100%; align-items: center; gap: 12px; padding: 15px 16px;
  border: none; background: none; font-size: .95rem; font-weight: 700; cursor: pointer;
  border-bottom: 1px solid var(--line); color: var(--text); font-family: inherit; text-align: left;
}
.menu button:last-child { border-bottom: none; }
.menu button .mi { font-size: 1.2rem; }
.menu button .arrow { margin-left: auto; color: var(--muted); }

.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #1a202c; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: .88rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 92%; display: flex; gap: 12px; align-items: center;
}
.toast button { background: none; border: none; color: #63b3ed; font-weight: 800; font-size: .88rem; cursor: pointer; font-family: inherit; }

.seg { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.seg button {
  padding: 9px 15px; border: none; border-radius: 999px; background: var(--card);
  font-size: .8rem; font-weight: 700; white-space: nowrap; cursor: pointer; color: var(--text);
  box-shadow: var(--shadow); font-family: inherit;
}
.seg button.active { background: var(--navy); color: #fff; }
/* カレンダー */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: .68rem; font-weight: 700; color: var(--muted); padding: 2px 0; }
.cal-dow.sun { color: var(--red); }
.cal-dow.sat { color: var(--blue); }
.cal-cell {
  min-height: 54px; border-radius: 8px; background: #f8fafc; padding: 2px 3px;
  font-size: .68rem; cursor: pointer; overflow: hidden; border: 1.5px solid transparent;
}
.cal-cell.empty { background: none; cursor: default; }
.cal-cell.today { border-color: var(--blue); background: #ebf4ff; }
.cal-cell.selected { border-color: var(--navy); background: #e0ecf9; }
.cal-cell.overdue { background: var(--red-soft); }
.cal-cell .cd { font-weight: 700; color: var(--muted); font-size: .7rem; }
.cal-due { background: var(--red); color: #fff; border-radius: 6px; padding: 0 3px; font-weight: 800; font-size: .66rem; display: inline-block; max-width: 100%; overflow: hidden; }
.cal-paid { color: var(--green); font-weight: 800; font-size: .7rem; }
.cal-spend { color: var(--muted); font-size: .62rem; }

/* CSV取り込み */
.imp-row { display: flex; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .78rem; }
.imp-row .d { flex: 0 0 44px; color: var(--muted); }
.imp-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.imp-row .a { flex: 0 0 auto; font-weight: 800; }
.imp-row select { width: auto; padding: 5px 6px; font-size: .72rem; border-radius: 8px; }
input[type=file] { padding: 10px; background: #f8fafc; }

.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .75rem; }
.topline { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 12px; }
.topline h1 { font-size: 1.25rem; font-weight: 800; }
.topline select { width: auto; padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: .85rem; }
.notice-dot { background: var(--amber-soft); color: #975a16; border-radius: 12px; padding: 10px 14px; font-size: .8rem; font-weight: 700; margin-bottom: 12px; cursor: pointer; }
