/* ===== テーマ変数 ===== */
:root {
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --text: #111114;
  --text-2: #8a8a8e;
  --text-3: #b3b3b8;
  --line: #ececef;
  --card-bg: #1b1b1d;
  --card-text: #ffffff;
  --accent: #2f6bff;
  --accent-soft: #e7eeff;
  --danger: #e0454e;
  --chip-bg: #f1f1f3;
  --chip-active: #1b1b1d;
  --chip-active-text: #ffffff;
  --shadow: 0 6px 24px rgba(0,0,0,.06);
  --radius: 18px;
}
[data-theme="dark"] {
  --bg: #0c0c0e;
  --bg-2: #161618;
  --surface: #161618;
  --surface-2: #1e1e21;
  --text: #f4f4f6;
  --text-2: #9a9aa0;
  --text-3: #6a6a70;
  --line: #2a2a2e;
  --card-bg: #1f1f23;
  --card-text: #ffffff;
  --accent: #5b8bff;
  --accent-soft: #1d2a4d;
  --chip-bg: #232327;
  --chip-active: #f4f4f6;
  --chip-active-text: #111114;
  --shadow: 0 6px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg-2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--bg);
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.screen { padding: 14px 18px 0; min-height: 100vh; }
.is-hidden { display: none !important; }
.list-pad { height: 120px; }

.muted-s { color: var(--text-2); font-size: 12px; }
.strong { font-weight: 700; font-size: 16px; }
.right { text-align: right; }

/* ===== ヘッダ ===== */
.page-head { padding: 8px 0 14px; }
.page-eyebrow { color: var(--text-2); font-size: 13px; font-weight: 600; }
.big-title { font-size: 30px; font-weight: 800; padding: 18px 0 6px; }

/* ===== 合計カード ===== */
.total-card {
  background: var(--card-bg);
  color: var(--card-text);
  border-radius: 22px;
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.total-card::after {
  content: "";
  position: absolute; right: -30px; top: -20px;
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #3a3a3e, #161618);
}
.total-card__label { font-size: 13px; color: #c9c9cf; }
.total-card__label .hint {
  display: inline-flex; width: 16px; height: 16px; border-radius: 50%;
  background: #3a3a3e; color:#cfcfd4; font-size: 11px; align-items:center; justify-content:center; vertical-align:1px;
}
.total-card__amount { font-size: 36px; font-weight: 800; margin: 6px 0 18px; letter-spacing: -.5px; }
.total-card__sub { display: flex; justify-content: space-between; border-top: 1px solid #313135; padding-top: 14px; }
.total-card__sub .muted-s { color: #9a9aa0; }
.total-card__sub .strong { color: #fff; }
.total-card__foot { color: #7d7d83; font-size: 11px; text-align: center; margin-top: 14px; }

/* ===== セグメント ===== */
.seg {
  display: flex; gap: 6px; background: var(--surface-2);
  border-radius: 14px; padding: 4px; margin: 16px 0 14px;
}
.seg__btn {
  flex: 1; border: none; background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 600; padding: 9px 4px; border-radius: 10px; cursor: pointer;
  font-family: inherit;
}
.seg__btn.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.seg__btn em { font-style: normal; color: var(--text-3); margin-left: 2px; }
.seg--mini { margin: 0; width: auto; flex: 0 0 auto; }
.seg--mini .seg__btn { flex: 0 0 auto; padding: 8px 14px; }
.seg--mini .seg__btn.is-active { background: var(--chip-active); color: var(--chip-active-text); }

/* ===== チップ ===== */
.chips { display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips--wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); font-size: 13px; font-weight: 600; padding: 8px 14px;
  border-radius: 999px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.chip.is-active { background: var(--chip-active); color: var(--chip-active-text); border-color: var(--chip-active); }

.section-label { color: var(--text-2); font-size: 13px; font-weight: 600; margin: 18px 0 10px; }

/* ===== サブスク一覧 ===== */
.sub-list { list-style: none; }
.sub-item {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  padding: 14px 2px 16px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative;
}
.sub-icon {
  width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: var(--surface-2);
}
.sub-name { font-size: 15px; font-weight: 600; }
.sub-meta { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.sub-price { text-align: right; font-weight: 700; font-size: 14px; }
.sub-period { color: var(--text-3); font-weight: 500; font-size: 12px; }
.sub-left { color: var(--text-3); font-size: 12px; text-align: right; margin-top: 2px; }
.sub-progress {
  grid-column: 1 / -1; height: 3px; background: var(--line); border-radius: 3px; margin-top: 10px; overflow: hidden;
}
.sub-progress > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.empty { text-align: center; color: var(--text-3); padding: 50px 0; font-size: 14px; }

/* ===== カレンダー ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px 16px; }
.cal-head h2 { font-size: 18px; font-weight: 700; }
.cal-nav { border: none; background: transparent; color: var(--text); font-size: 26px; cursor: pointer; width: 40px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
#calWeekdays { margin-bottom: 6px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--text-2); padding: 4px 0; }
.cal-wd.sun { color: #e0454e; }
.cal-wd.sat { color: #2f6bff; }
.cal-cell { aspect-ratio: 1 / 1.15; border: .5px solid var(--line); padding: 4px; position: relative; font-size: 12px; color: var(--text); overflow: hidden; }
.cal-cell.is-out { color: var(--text-3); background: var(--surface-2); }
.cal-cell.is-today .cal-num { background: var(--chip-active); color: var(--chip-active-text); border-radius: 50%; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; }
.cal-num { display: inline-block; }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.cal-dot { font-size: 13px; line-height: 1; }
.pay-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.pay-total { display: flex; justify-content: space-between; padding: 16px; font-weight: 800; border-bottom: 1px solid var(--line); }
.pay-row { display: grid; grid-template-columns: 36px 32px 1fr auto; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.pay-row:last-child { border-bottom: none; }
.pay-date { color: var(--text-2); font-size: 12px; }
.pay-ic { width: 30px; height: 30px; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.pay-name { font-size: 14px; font-weight: 600; }
.pay-amt { font-weight: 700; font-size: 14px; }

/* ===== 分析 ===== */
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card__amount { font-size: 30px; font-weight: 800; margin: 4px 0; }
.stat-card__diff { font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.stat-card__diff.up { color: var(--danger); }
.stat-card__diff.down { color: #2ca85f; }
.stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.rank-card, .cat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px; }
.rank-row { display: grid; grid-template-columns: 22px 34px 1fr auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: none; }
.rank-no { color: var(--text-3); font-weight: 700; font-size: 13px; text-align: center; }
.rank-ic { width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.rank-name { font-size: 14px; font-weight: 600; }
.rank-sub { font-size: 11px; color: var(--text-3); }
.rank-amt { font-weight: 700; text-align: right; }
.cat-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: none; }
.cat-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.cat-bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.cat-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* ===== 診断 ===== */
.checkup-hero { background: var(--card-bg); color: var(--card-text); border-radius: 22px; padding: 22px; box-shadow: var(--shadow); }
.checkup-hero .score { font-size: 40px; font-weight: 800; }
.checkup-hero .msg { color: #c9c9cf; font-size: 13px; margin-top: 8px; line-height: 1.6; }
.advice-list { display: flex; flex-direction: column; gap: 10px; }
.advice {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start;
}
.advice .ai { font-size: 20px; }
.advice .at { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.advice .ad { font-size: 13px; color: var(--text-2); line-height: 1.6; }

/* ===== 設定 ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); gap: 12px; }
.row:last-child { border-bottom: none; }
.row.col { flex-direction: column; align-items: stretch; }
.as-btn { width: 100%; background: none; border: none; border-bottom: 1px solid var(--line); font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.as-btn:last-child { border-bottom: none; }
.as-btn.danger div > div:first-child { color: var(--danger); }
.chev { color: var(--text-3); font-size: 20px; }
.rate-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.rate-input { width: 110px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; text-align: right; background: var(--surface-2); color: var(--text); }
.app-foot { text-align: center; padding: 30px 0 10px; color: var(--text-2); }
.app-foot .strong { color: var(--text); }

/* スイッチ */
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--chip-active); }
.switch input:checked + span::before { transform: translateX(20px); }

/* ===== FAB ===== */
.fab {
  position: fixed; right: max(18px, calc(50% - 240px + 18px)); bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--chip-active); color: var(--chip-active-text);
  font-size: 28px; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 30; line-height: 1;
}

/* ===== ボトムナビ ===== */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 480px;
  display: grid; grid-template-columns: repeat(5,1fr); background: var(--surface);
  border-top: 1px solid var(--line); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); z-index: 25;
}
.tab { border: none; background: none; color: var(--text-3); font-size: 10px; font-weight: 600; cursor: pointer; font-family: inherit; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.tab .ti { font-size: 19px; filter: grayscale(1) opacity(.6); }
.tab.is-active { color: var(--text); }
.tab.is-active .ti { filter: none; }

/* ===== シート ===== */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 480px;
  height: 92vh; background: var(--bg); border-radius: 20px 20px 0 0; z-index: 50;
  display: flex; flex-direction: column; animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sheet__title { font-weight: 700; }
.sheet__cancel, .sheet__save { border: none; background: none; font: inherit; cursor: pointer; color: var(--text-2); }
.sheet__save { color: var(--accent); font-weight: 700; }
.sheet__body { flex: 1; overflow-y: auto; padding: 18px; padding-bottom: 60px; }

.search { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 13px 14px; font: inherit; color: var(--text); margin-bottom: 12px; }
.manual-btn { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px; font: inherit; font-weight: 600; cursor: pointer; margin-bottom: 16px; color: var(--text); }
.chips--scroll { margin-bottom: 16px; }
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.preset {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 8px; text-align: center; cursor: pointer;
}
.preset .pic { font-size: 30px; }
.preset .pn { font-size: 12px; font-weight: 600; margin-top: 8px; }
.preset .pc { font-size: 10px; color: var(--text-3); margin-top: 2px; }

.icon-pick { width: 80px; height: 80px; border-radius: 20px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 38px; margin: 0 auto 8px; cursor: pointer; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin: 16px 0 7px; }
.field-label em { color: var(--danger); font-style: normal; }
.input { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 13px 14px; font: inherit; color: var(--text); }
textarea.input { resize: vertical; }
.del-link { display: block; width: 100%; margin: 28px 0 0; border: none; background: none; color: var(--danger); font: inherit; font-weight: 600; cursor: pointer; padding: 12px; }
