/* 共通レイアウトと部品。色は tokens.css の変数のみ使う */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: var(--font-size-md);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
/* ガラス越しに見える背景: 上が空色で、下へ向かって --bg に溶ける */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 30%, var(--bg) 62%);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

/* ガラス面の共通指定 */
.card, .list, .dialog, .capture-big, .titlebar-back,
.btn:not(.btn-primary):not(.btn-danger):not(.btn-ghost) {
  background: var(--surface);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-shadow);
}

.icon { display: inline-flex; line-height: 0; flex: none; }
.icon svg { display: block; }

/* ---- レイアウト ---- */
#app { display: flex; flex-direction: column; height: 100%; max-width: 100vw; }
.titlebar {
  flex: none;
  display: flex; align-items: center; gap: var(--space-2);
  min-height: calc(var(--titlebar-height) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space-3) + var(--safe-right)) 0 calc(var(--space-3) + var(--safe-left));
  background: transparent;
}
.titlebar-title { flex: 1; min-width: 0; font-size: var(--font-size-lg); font-weight: 700; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* タブ直下の画面（戻るボタンなし）は左寄せの大きな見出し */
.titlebar:not(:has(.titlebar-back:not([hidden]))) .titlebar-title {
  text-align: left; font-size: 32px; font-weight: 800; letter-spacing: -0.01em; padding-left: var(--space-1);
}
.titlebar:not(:has(.titlebar-back:not([hidden]))) .titlebar-spacer { display: none; }
.titlebar-back {
  width: var(--tap); height: var(--tap); flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); padding: 0; cursor: pointer;
}
.titlebar-spacer { width: var(--tap); flex: none; }
.banner {
  flex: none; display: block; width: calc(100% - 2 * var(--space-4)); margin: var(--space-2) auto 0; border: 0; text-align: left; cursor: pointer;
  min-height: var(--tap); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  background: var(--warning); color: var(--bg); font-size: var(--font-size-md); font-weight: 600;
}
.screen {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* 下端は浮いたタブバーに隠れないよう空ける */
  padding: var(--space-3) calc(var(--space-4) + var(--safe-right)) calc(var(--tabbar-height) + var(--tabbar-bottom) + var(--space-5)) calc(var(--space-4) + var(--safe-left));
  display: flex; flex-direction: column; gap: var(--space-4);
}

/* ---- 浮いたタブバー：ガラスのカプセル＋記録ボタン ---- */
.tabbar {
  position: fixed; z-index: 50;
  left: calc(var(--space-4) + var(--safe-left)); right: calc(var(--space-4) + var(--safe-right));
  bottom: var(--tabbar-bottom);
  display: flex; align-items: center; gap: var(--space-3);
  max-width: 520px; margin: 0 auto;
}
.tabbar-tabs, .tab-fab {
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--float-shadow);
}
.tabbar-tabs {
  flex: 1; min-width: 0; display: flex; height: var(--tabbar-height); padding: 5px;
  border-radius: 999px; background: var(--surface-strong);
}
.tab {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: 999px; color: var(--text); text-decoration: none; font-size: 11px; font-weight: 500;
}
.tab[aria-current="page"] { color: var(--accent-ink); font-weight: 700; background: var(--surface-2); }
.tab-fab {
  flex: none; width: var(--tabbar-height); height: var(--tabbar-height); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-fill); color: var(--accent-contrast); text-decoration: none;
  border-color: rgba(255, 255, 255, 0.35);
}
.tab-fab[aria-current="page"] { box-shadow: var(--float-shadow), 0 0 0 4px var(--accent-soft); }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-5);
  border: 1px solid transparent; border-radius: 999px;
  color: var(--text);
  font-size: var(--font-size-md); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  background: var(--accent-fill); color: var(--accent-contrast);
  box-shadow: 0 6px 18px var(--accent-soft), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn-danger { background: var(--danger); color: var(--bg); }
.btn-ghost { background: transparent; color: var(--accent-ink); }
.btn-block { display: flex; width: 100%; }

/* ---- カード・リスト ---- */
.card { border-radius: var(--radius-lg); padding: var(--space-4) calc(var(--space-4) + 2px); }
.card-title { font-size: var(--font-size-lg); font-weight: 700; color: var(--text); margin-bottom: var(--space-2); }
.section-title { font-size: var(--font-size-md); color: var(--text); font-weight: 700; padding: 0 var(--space-1); }
.list { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: var(--tap); padding: var(--space-3) var(--space-4);
  background: none; border: 0; text-align: left;
}
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
button.list-item { cursor: pointer; }
.list-main { flex: 1; min-width: 0; }
.list-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-subtitle { font-size: var(--font-size-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 金額・バッジ ---- */
.amount { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; white-space: nowrap; text-align: right; font-weight: 600; }
.amount-negative { color: var(--success); }
.amount-danger { color: var(--danger); }
.badge {
  display: inline-block; padding: 1px var(--space-2); border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-danger { background: var(--danger); color: var(--bg); }
.badge-warning { background: var(--warning); color: var(--bg); }
.badge-success { background: var(--success); color: var(--bg); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }

/* ---- フォーム ---- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field-label { font-size: var(--font-size-sm); color: var(--text-muted); padding-left: var(--space-1); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: var(--space-2) var(--space-3);
  font-size: 16px; /* iOS の自動ズーム回避のため 16px 以上 */
  background: var(--surface); color: var(--text);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge); border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px var(--border);
  appearance: none; -webkit-appearance: none;
}
.textarea { min-height: 96px; resize: vertical; }
.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.input-amount { text-align: right; font-variant-numeric: tabular-nums; }

.segmented { display: flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented button {
  flex: 1; min-height: 38px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text); font-size: var(--font-size-md); cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface-strong); font-weight: 700; box-shadow: var(--glass-shadow); }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--bar, linear-gradient(90deg, var(--accent-2), var(--accent))); border-radius: 999px; }
.progress-warn .progress-bar { background: var(--warning); }
.progress-danger .progress-bar { background: var(--danger); }

.empty { text-align: center; color: var(--text-muted); padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }

/* ---- シート・ダイアログ・トースト ---- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  padding: var(--space-2) calc(var(--space-2) + var(--safe-right)) max(var(--space-2), calc(var(--safe-bottom) - 12px)) calc(var(--space-2) + var(--safe-left));
}
.overlay-center { align-items: center; padding: var(--space-4); }
/* 下から出るシートも画面端から少し離して浮かせる */
.sheet {
  width: 100%; max-width: 560px; max-height: 90%; display: flex; flex-direction: column;
  background: var(--surface-strong);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge); border-radius: 34px; box-shadow: var(--float-shadow);
  overflow: hidden;
}
.sheet-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-3) var(--space-1) var(--space-5); }
.sheet-title { flex: 1; font-weight: 800; font-size: var(--font-size-lg); }
.sheet-body { overflow-y: auto; padding: var(--space-3) var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.dialog {
  width: 100%; max-width: 340px; background: var(--surface-strong); border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-4);
  box-shadow: var(--float-shadow);
}
.dialog-actions { display: flex; gap: var(--space-2); }
.dialog-actions .btn { flex: 1; }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-height) + var(--tabbar-bottom) + var(--space-3)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); pointer-events: none; padding: 0 var(--space-4); }
.toast {
  background: var(--toast-bg); color: var(--toast-text); padding: var(--space-3) var(--space-5); border-radius: 999px; max-width: 100%;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); box-shadow: var(--float-shadow); font-weight: 600;
}
.toast-error { background: var(--danger); color: var(--bg); }
.toast-success { background: var(--success); color: var(--bg); }
