/* styles.css — 固定費・サブスク管理。モバイル優先・ライト/ダーク対応。 */
:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f0f2f7; --text: #1c2230; --muted: #6b7280;
  --line: #e4e7ee; --primary: #4f7cff; --primary-ink: #ffffff; --danger: #e0524d; --warn: #e08a00;
  --ok: #1aa06d; --track: #e6e8ee; --shadow: 0 2px 10px rgba(20,30,60,.06); --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"], html[data-theme="dark"] {
  --bg: #0f1320; --surface: #171c2b; --surface-2: #1e2435; --text: #e8ebf2; --muted: #9aa3b5;
  --line: #2a3146; --primary: #5b86ff; --track: #2a3146; --shadow: 0 2px 14px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1320; --surface: #171c2b; --surface-2: #1e2435; --text: #e8ebf2; --muted: #9aa3b5;
    --line: #2a3146; --primary: #5b86ff; --track: #2a3146; --shadow: 0 2px 14px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; line-height: 1.5;
}
.hidden { display: none !important; }

/* ===== レイアウト ===== */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.appbar-title { font-size: 17px; font-weight: 700; margin: 0; }
.appbar-note { font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 3px 8px; border-radius: 999px; }
.view { flex: 1; padding: 14px 14px calc(96px + var(--safe-b)); max-width: 720px; width: 100%; margin: 0 auto; }

/* タブバー */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5,1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tab { appearance: none; border: 0; background: none; color: var(--muted); padding: 8px 2px 9px; font-size: 10.5px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.tab .tab-ico { font-size: 19px; line-height: 1; filter: grayscale(.3); }
.tab[aria-selected="true"] { color: var(--primary); font-weight: 700; }
.tab[aria-selected="true"] .tab-ico { filter: none; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(74px + var(--safe-b)); z-index: 7; width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--primary); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(79,124,255,.45);
  cursor: pointer;
}
.fab:active { transform: scale(.96); }

/* ===== 共通パーツ ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.center { text-align: center; }
.card-title { font-size: 14px; margin: 0 0 10px; font-weight: 700; }
.card-note { font-size: 12px; color: var(--muted); margin: -4px 0 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.warn { background: var(--warn); color: #fff; border-color: transparent; }
.btn.tiny { padding: 6px 10px; font-size: 12.5px; border-radius: 9px; }
.btn-row { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.icon-btn { appearance: none; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.link-btn { appearance: none; border: 0; background: none; color: var(--primary); font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 4px 6px; text-decoration: none; }
.spacer { flex: 1; }

/* ===== ホーム：ヒーロー ===== */
.hero { background: linear-gradient(135deg, var(--primary), #6a5cff); color: #fff; border-radius: var(--radius); padding: 20px; margin-bottom: 14px; box-shadow: 0 8px 22px rgba(79,124,255,.3); }
.hero-label { font-size: 12px; opacity: .9; }
.hero-amount { font-size: 38px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0; }
.hero-sub { font-size: 13px; opacity: .95; }
.hero-sub strong { font-weight: 800; }

/* お知らせリスト */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.alert-item .alert-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-when { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.alert-when.soon { background: #ffece8; color: var(--danger); font-weight: 700; }
html[data-theme="dark"] .alert-when.soon, :root:not([data-theme="light"]) .alert-when.soon { background: #3a221f; }
.alert-amt { font-weight: 700; font-size: 13px; white-space: nowrap; }
.muted-row { color: var(--muted); font-size: 13px; }

/* リスト操作 */
.list-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.list-controls select { flex: 1; }
select, input[type="number"], input[type="text"], input[type="url"], input[type="date"], input[type="color"], textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%;
}
input[type="color"] { padding: 4px; height: 40px; }

/* サブスク一覧 */
.sub-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sub-row { display: flex; align-items: center; gap: 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 12px; cursor: pointer; box-shadow: var(--shadow); }
.sub-row:active { background: var(--surface-2); }
.sub-row.dim { opacity: .6; }
.row-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.row-amt { text-align: right; font-weight: 800; font-size: 15px; white-space: nowrap; }
.row-amt small { display: block; font-weight: 500; font-size: 10.5px; color: var(--muted); }
.badge { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: #e3f6ee; color: var(--ok); }
.badge.trial { background: #e8effe; color: var(--primary); }
.badge.warn { background: #fdf0dc; color: var(--warn); }
html[data-theme="dark"] .badge, :root:not([data-theme="light"]) .badge { background: #232a3d; }
.trend { font-size: 10.5px; font-weight: 700; }
.trend.up { color: var(--danger); }
.trend.down { color: var(--ok); }

/* 空状態 */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-emoji { font-size: 44px; }
.empty-title { font-size: 16px; font-weight: 700; color: var(--text); margin: 12px 0 6px; }
.empty-sub { font-size: 13px; margin-bottom: 18px; }

/* ===== 集計 ===== */
.totals-2 { display: flex; justify-content: space-around; margin-bottom: 8px; }
.t-label { font-size: 12px; color: var(--muted); }
.t-val { font-size: 22px; font-weight: 800; }
.donut-wrap { display: flex; justify-content: center; padding: 8px 0; }
.donut .donut-top { font-size: 20px; font-weight: 800; fill: var(--text); }
.donut .donut-bottom { font-size: 11px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.legend li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; font-size: 13px; }
.legend .lg-name { font-weight: 600; }
.legend .lg-bar { grid-column: 1 / -1; height: 6px; background: var(--track); border-radius: 999px; overflow: hidden; order: 3; }
.legend .lg-bar > span { display: block; height: 100%; border-radius: 999px; }
.legend .lg-val { text-align: right; font-weight: 700; white-space: nowrap; }
.legend .lg-val small { color: var(--muted); font-weight: 500; }

/* ===== カレンダー ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head .card-title { margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-wk { text-align: center; font-size: 10.5px; color: var(--muted); padding: 2px 0; }
.cal-cell { min-height: 46px; border-radius: 8px; background: var(--surface-2); padding: 3px; position: relative; display: flex; flex-direction: column; }
.cal-cell.empty { background: transparent; }
.cal-cell.has { outline: 1px solid var(--line); }
.cal-cell.today { background: #e8effe; }
html[data-theme="dark"] .cal-cell.today, :root:not([data-theme="light"]) .cal-cell.today { background: #1d2740; }
.cal-d { font-size: 11px; color: var(--muted); }
.cal-cell.today .cal-d { color: var(--primary); font-weight: 800; }
.cal-dots { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 1px; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; }
.cal-sum { margin-top: auto; font-size: 9.5px; font-weight: 700; color: var(--text); text-align: right; }

/* ===== 解約候補 ===== */
.cand-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.cand { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.cand-top { display: flex; align-items: center; gap: 9px; }
.cand-name { flex: 1; font-weight: 700; }
.cand-amt { font-weight: 800; }
.cand-amt small { font-weight: 500; font-size: 10.5px; color: var(--muted); }
.cand-reasons { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.reason { font-size: 11px; font-weight: 700; color: var(--warn); background: #fdf0dc; padding: 2px 8px; border-radius: 999px; }
html[data-theme="dark"] .reason, :root:not([data-theme="light"]) .reason { background: #3a2e1a; }
.cand-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cand-q { font-size: 12.5px; color: var(--muted); flex: 1; min-width: 120px; }

/* ===== 設定 ===== */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.setting-row span { font-size: 14px; }
.setting-row select, .setting-row input { width: auto; min-width: 130px; }
.privacy-list { margin: 4px 0 10px; padding-left: 18px; font-size: 13px; color: var(--muted); }
.privacy-list li { margin: 4px 0; }
.privacy-list strong { color: var(--text); }
.ver { font-size: 11px; color: var(--muted); }
.install-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ===== ダイアログ ===== */
.dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(10,14,25,.5); backdrop-filter: blur(2px); }
.dialog.small { padding: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.dialog-head h2 { font-size: 16px; margin: 0; }
.dialog-body { padding: 4px 18px 8px; max-height: 70vh; overflow: auto; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); margin-top: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field > span em { color: var(--danger); font-style: normal; font-size: 10.5px; margin-left: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field.small { flex: 0 0 110px; }
.hint { font-size: 11px; color: var(--muted); }
.more { margin: 4px 0 8px; }
.more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--primary); padding: 6px 0; }
.form-error { color: var(--danger); font-size: 13px; min-height: 1px; }

/* ===== ロック ===== */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.lock-box { text-align: center; padding: 24px; width: min(340px, 90vw); }
.lock-emoji { font-size: 40px; }
.lock-box h1 { font-size: 18px; margin: 10px 0 16px; }
.pin-input { text-align: center; letter-spacing: 8px; font-size: 22px; }
.lock-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ===== トースト ===== */
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 90vw; }

@media (min-width: 560px) {
  .hero-amount { font-size: 42px; }
}
