/* ================================================================
   CASH — エメラルド×ゴールド
   紙幣の深緑と金貨のゴールドを基調に、白背景へ淡いミントの光を
   にじませる。数字が主役の財務ツールなので、金額はRobotoの
   tabular-numsで桁を揃え、色は「収入=緑 / 手残り=金」だけに絞る。
   レイアウトと操作感はMaterial Design 3準拠（メモリアの設計を継承）。
   ================================================================ */
:root {
  --grad: linear-gradient(135deg, #047857 0%, #059669 45%, #0d9488 100%);
  --grad-gold: linear-gradient(135deg, #b45309 0%, #d97706 55%, #f59e0b 100%);
  --grad-soft: linear-gradient(135deg, rgba(5, 150, 105, 0.10), rgba(13, 148, 136, 0.10));
  --emerald: #047857;
  --emerald-bright: #059669;
  --teal: #0d9488;
  --gold: #b45309;
  --gold-bright: #d97706;
  --bg: #f6faf8;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-2: #eef5f1;
  --outline: rgba(16, 120, 90, 0.13);
  --outline-strong: rgba(16, 120, 90, 0.30);
  --text: #1c2622;
  --text-2: #46564e;
  --muted: #7d8d84;
  --red: #dc4a5e;
  --amber-soft: #fef3c7;
  --radius: 20px;
  --font: "Roboto", "Noto Sans JP", "Hiragino Sans", sans-serif;
  --font-display: "Google Sans", "Roboto", "Noto Sans JP", "Hiragino Sans", sans-serif;
  --shadow-1: 0 2px 10px rgba(28, 100, 74, 0.08);
  --shadow-2: 0 12px 40px -8px rgba(28, 100, 74, 0.25);
  --glow: 0 8px 24px -8px rgba(5, 150, 105, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* 背景: 淡いミントと金の光 */
.atmosphere {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(46% 34% at 10% 0%, rgba(110, 231, 183, 0.28), transparent 70%),
    radial-gradient(50% 36% at 92% 4%, rgba(153, 246, 228, 0.30), transparent 70%),
    radial-gradient(40% 28% at 82% 50%, rgba(252, 211, 77, 0.12), transparent 70%),
    radial-gradient(55% 40% at 4% 92%, rgba(52, 211, 153, 0.14), transparent 70%),
    var(--bg);
}

.app {
  max-width: 640px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom));
}

button { font-family: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface-solid);
  border: 1.5px solid var(--outline); border-radius: 14px;
  padding: 12px 14px; width: 100%; min-width: 0; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--emerald-bright); }

/* チェックボックスは全域で統一デザイン（角丸四角＋チェックマーク）。
   理由: 上のinput共通スタイルが効くと丸く歪んだ見た目になるため明示的に上書きする */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 21px; height: 21px; padding: 0; margin: 0;
  border: 2px solid var(--outline-strong); border-radius: 6px;
  background: var(--surface-solid);
  display: inline-block; position: relative;
  cursor: pointer; flex: none; transition: all 0.12s;
}
input[type="checkbox"]:checked {
  background: var(--emerald-bright); border-color: var(--emerald-bright);
}
input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 5.5px; top: 2px;
  width: 5px; height: 9.5px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

/* 金額は常に桁揃え */
.num, .amount { font-family: "Roboto", var(--font); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------------------------------------------------------------- トップバー */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 4px 2px 12px;
}
.brand { display: flex; align-items: center; gap: 7px; }
.brand-icon { width: 26px; height: 26px; border-radius: 7px; display: block; box-shadow: var(--shadow-1); }
.brand-name {
  font-family: var(--font-display); font-size: 1.02rem; font-weight: 700; letter-spacing: 0.05em;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-label {
  font-family: var(--font-display); font-weight: 500; font-size: 1.0rem;
  padding: 6px 10px; border-radius: 12px;
}
.month-label:active { background: var(--surface-2); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background 0.15s;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.app[data-view="loans"] .month-nav, .app[data-view="settings"] .month-nav { visibility: hidden; }

/* ---------------------------------------------------------------- ビュー */
.view { display: none; animation: fadein 0.18s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: var(--surface-solid);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 18px 16px;
  margin-bottom: 14px;
}
.card.grad-tint { background: linear-gradient(150deg, #ffffff 30%, #f0faf5 100%); }
.card-title {
  font-family: var(--font-display); font-size: 0.82rem; font-weight: 700;
  letter-spacing: 0.08em; color: var(--muted); margin-bottom: 12px;
}
.card-title .right { float: right; font-weight: 500; letter-spacing: 0; }

.kicker {
  font-family: var(--font-display); font-size: 0.66rem; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* ---------------------------------------------------------------- ウォーターフォール */
.wf-row { margin-bottom: 13px; }
.wf-row:last-child { margin-bottom: 0; }
.wf-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.wf-label { font-size: 0.82rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.wf-label .op { color: var(--muted); font-size: 0.78rem; }
.wf-value { font-size: 1.02rem; font-weight: 700; }
.wf-track { height: 12px; border-radius: 999px; background: var(--surface-2); position: relative; overflow: hidden; }
.wf-bar { position: absolute; top: 0; bottom: 0; border-radius: 999px; min-width: 3px; transition: all 0.4s cubic-bezier(0.2, 0, 0, 1); }
.wf-sales .wf-bar { background: var(--grad); }
.wf-expense .wf-bar { background: #cdd9d3; }
.wf-op .wf-bar { background: var(--teal); }
.wf-private .wf-bar { background: #f2c063; }
.wf-tenokori .wf-bar { background: var(--grad-gold); box-shadow: 0 2px 10px -2px rgba(217, 119, 6, 0.5); }
.wf-tenokori .wf-value { font-size: 1.35rem; background: var(--grad-gold); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.wf-divider { border: 0; border-top: 1.5px dashed var(--outline-strong); margin: 12px 0; }
.wf-note { font-size: 0.74rem; color: var(--muted); margin-top: 10px; line-height: 1.6; }

/* ---------------------------------------------------------------- ゲージ・ミニカード */
.gauge-row { display: flex; align-items: center; gap: 12px; }
.gauge-track { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 999px; background: var(--grad-gold); transition: width 0.4s; }
.gauge-pct { font-weight: 700; font-size: 1.05rem; min-width: 58px; text-align: right; }
.sub-note { font-size: 0.78rem; color: var(--text-2); margin-top: 10px; line-height: 1.7; }
.sub-note b { font-weight: 700; }

.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini-card {
  background: var(--surface-solid); border: 1px solid var(--outline);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: 14px; text-align: left; width: 100%;
}
.mini-card .t { font-size: 0.74rem; color: var(--muted); font-weight: 600; margin-bottom: 5px; display: flex; align-items: center; gap: 5px; }
.mini-card .v { font-size: 1.2rem; font-weight: 700; }
.mini-card .s { font-size: 0.72rem; color: var(--muted); margin-top: 3px; }
.mini-card.alert .v { color: var(--gold-bright); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 0.72rem; font-weight: 700;
}
.badge.zero { background: var(--emerald-bright); }

/* ---------------------------------------------------------------- チェックリスト */
.check-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 4px; border-bottom: 1px solid var(--outline); text-align: left;
}
.check-row:last-child { border-bottom: 0; }
.check-status {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--outline-strong); color: transparent;
}
.check-row.done .check-status { background: var(--emerald-bright); border-color: var(--emerald-bright); color: #fff; }
.check-row.na .check-status { background: var(--surface-2); border-color: var(--surface-2); color: var(--muted); }
.check-status svg { width: 15px; height: 15px; }
.check-main { flex: 1; min-width: 0; }
.check-label { font-size: 0.92rem; font-weight: 500; }
.check-sub { font-size: 0.74rem; color: var(--muted); margin-top: 1px; }
.check-amount { font-weight: 700; font-size: 0.95rem; }
.check-row.done .check-label { color: var(--text-2); }
.check-row.na .check-label { color: var(--muted); text-decoration: line-through; }
.check-amount.empty { color: var(--gold-bright); font-size: 0.8rem; font-weight: 600; }

/* ---------------------------------------------------------------- チップ・セグメント */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 500;
  background: var(--surface-solid); border: 1.5px solid var(--outline-strong);
  color: var(--text-2); white-space: nowrap; transition: all 0.15s; flex: none;
}
.chip.on { background: var(--emerald); border-color: var(--emerald); color: #fff; box-shadow: var(--glow); }
.chip .n { margin-left: 4px; font-size: 0.75rem; opacity: 0.85; }
.chip.small { padding: 5px 11px; font-size: 0.78rem; }
.chip-add { border-style: dashed; color: var(--muted); }

.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 11px; font-size: 0.88rem; font-weight: 500;
  color: var(--text-2); transition: all 0.15s;
}
.seg button.on { background: var(--surface-solid); color: var(--emerald); font-weight: 700; box-shadow: var(--shadow-1); }

/* ---------------------------------------------------------------- 取引リスト */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.searchbox { position: relative; }
.searchbox input { padding-left: 40px; border-radius: 999px; }
.searchbox svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }

.date-head {
  font-size: 0.76rem; font-weight: 700; color: var(--muted);
  margin: 16px 4px 6px; letter-spacing: 0.04em;
}
.tx-row {
  display: flex; align-items: center; gap: 11px; width: 100%;
  background: var(--surface-solid); border: 1px solid var(--outline);
  border-radius: 16px; padding: 11px 13px; margin-bottom: 7px;
  text-align: left; box-shadow: var(--shadow-1); position: relative;
}
.tx-row:active { transform: scale(0.99); }
.tx-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tx-dot.business { background: var(--emerald-bright); }
.tx-dot.private { background: #f0b429; }
.tx-dot.internal { background: #9aa8b5; }
.tx-dot.unclassified { background: #fff; border: 2.5px solid var(--red); }
.tx-main { flex: 1; min-width: 0; }
/* display:block必須。spanのままだとoverflow/ellipsisが効かず長い店名が金額に被る */
.tx-desc { display: block; font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 0.7rem; color: var(--muted); flex-wrap: wrap; }
.tx-tag { background: var(--surface-2); border-radius: 6px; padding: 1.5px 7px; font-weight: 500; }
.tx-tag.cat-business { background: #d9f2e7; color: var(--emerald); }
.tx-tag.cat-private { background: var(--amber-soft); color: var(--gold); }
.tx-tag.cat-internal { background: #e8edf2; color: #5a6b7a; }
.tx-tag.sub-tag { background: #ede9fe; color: #6d28d9; }
.tx-amount { font-size: 0.98rem; font-weight: 700; flex: none; }
.tx-amount.plus { color: var(--emerald-bright); }
.tx-amount .yen { font-size: 0.78rem; margin-right: 1px; }
.tx-badge {
  font-size: 0.68rem; font-weight: 700; border-radius: 6px; padding: 2px 7px; flex: none;
}
.tx-badge.processing { background: var(--amber-soft); color: var(--gold); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.tx-icon { width: 16px; height: 16px; color: var(--muted); flex: none; }

/* 選択モード */
.row-check {
  width: 21px; height: 21px; flex: none; position: relative;
  border: 2px solid var(--outline-strong); border-radius: 6px;
  background: var(--surface-solid); transition: all 0.12s;
}
.row-check.checked { background: var(--emerald-bright); border-color: var(--emerald-bright); }
.row-check.checked::after {
  content: ""; position: absolute; left: 4.5px; top: 1px;
  width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.selbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(88px + env(safe-area-inset-bottom));
  width: min(420px, calc(100% - 28px));
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-solid); border: 1px solid var(--outline-strong);
  border-radius: 16px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-2); z-index: 45;
}
.selbar #selCount { flex: 1; font-weight: 700; font-size: 0.9rem; }

.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); font-size: 0.9rem; line-height: 1.9; }
.empty-state .big { font-size: 2rem; margin-bottom: 6px; }

/* AI提案 */
.suggest-banner {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, #ecfdf5, #f0fdfa);
  border: 1.5px solid rgba(5, 150, 105, 0.3); border-radius: 14px;
  padding: 10px 13px; margin-bottom: 10px; font-size: 0.82rem; color: var(--emerald);
}
.suggest-chip { border: 1.5px dashed var(--emerald-bright); color: var(--emerald); border-radius: 999px; padding: 2px 9px; font-size: 0.72rem; font-weight: 600; }

/* ---------------------------------------------------------------- ボタン */
.btn-primary {
  width: 100%; padding: 14px; border-radius: 16px;
  background: var(--grad); color: #fff; font-size: 1rem; font-weight: 700;
  box-shadow: var(--glow); transition: transform 0.12s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; box-shadow: none; }
.btn-gold { background: var(--grad-gold); box-shadow: 0 8px 24px -8px rgba(217, 119, 6, 0.55); }
.btn-outline {
  width: 100%; padding: 13px; border-radius: 16px;
  border: 1.5px solid var(--outline-strong); color: var(--emerald); font-size: 0.95rem; font-weight: 700;
  background: var(--surface-solid);
}
.btn-text { color: var(--emerald); font-weight: 700; font-size: 0.88rem; padding: 8px 10px; border-radius: 10px; }
.btn-text.danger { color: var(--red); }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

/* ---------------------------------------------------------------- タブバー・FAB */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(420px, calc(100% - 24px));
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--outline); border-radius: 999px;
  box-shadow: var(--shadow-2); padding: 8px 6px; z-index: 40;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px; }
.tab-pill {
  width: 46px; height: 28px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: all 0.18s;
}
.tab-pill svg { width: 21px; height: 21px; }
.tab-label { font-size: 0.64rem; font-weight: 600; color: var(--muted); }
.tab.active .tab-pill { background: var(--grad-soft); color: var(--emerald); }
.tab.active .tab-label { color: var(--emerald); }
.tab-fab { margin-top: -26px; }
.fab {
  width: 56px; height: 56px; border-radius: 19px;
  background: var(--grad); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--glow); transition: transform 0.15s;
}
.fab svg { width: 26px; height: 26px; }
.tab-fab:active .fab { transform: scale(0.93) rotate(90deg); }

/* ---------------------------------------------------------------- シート */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 35, 28, 0.42);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; transform: translate(-50%, 105%);
  bottom: 0; width: min(640px, 100%);
  background: var(--bg); border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 50px rgba(20, 60, 44, 0.25);
  transition: transform 0.26s cubic-bezier(0.2, 0, 0, 1);
  z-index: 51; max-height: 88dvh; overflow-y: auto;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
}
.sheet.open { transform: translate(-50%, 0); }
.sheet::before {
  content: ""; display: block; width: 40px; height: 4.5px; border-radius: 999px;
  background: var(--outline-strong); margin: 4px auto 14px;
}
.sheet h2 { font-family: var(--font-display); font-size: 1.12rem; font-weight: 700; margin-bottom: 14px; }
.sheet { overflow-x: hidden; }
.sheet .field { margin-bottom: 13px; min-width: 0; }
.sheet .field label { display: block; font-size: 0.76rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.sheet .actions { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.field-row > .seg { min-width: 0; }

.amount-input { position: relative; min-width: 0; }
.amount-input input { font-size: 1.5rem; font-weight: 700; text-align: right; padding-right: 40px; font-variant-numeric: tabular-nums; }
.amount-input::after { content: "円"; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.9rem; }

.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 15px 12px; border-radius: 16px; text-align: left;
  font-size: 0.98rem; font-weight: 600; transition: background 0.15s;
}
.menu-item:active { background: var(--surface-2); }
.menu-item .mi-icon {
  width: 44px; height: 44px; border-radius: 14px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--grad-soft); color: var(--emerald);
}
.menu-item .mi-icon svg { width: 22px; height: 22px; }
.menu-item .mi-sub { display: block; font-size: 0.74rem; color: var(--muted); font-weight: 400; margin-top: 2px; }

.receipt-thumb { width: 100%; max-height: 220px; object-fit: contain; border-radius: 14px; background: var(--surface-2); margin-bottom: 12px; cursor: zoom-in; }

/* レシート画像の拡大表示（タップで開閉） */
.lightbox {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(10, 18, 14, 0.93);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
  cursor: zoom-out;
}
.lightbox.open { opacity: 1; visibility: visible; pointer-events: auto; }
.lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* プレビューテーブル */
.pv-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.pv-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1.5px solid var(--outline-strong); }
.pv-table td { padding: 7px 8px; border-bottom: 1px solid var(--outline); }
.pv-table .r { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.pv-stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.pv-stat { background: var(--surface-2); border-radius: 10px; padding: 6px 11px; font-size: 0.78rem; font-weight: 600; color: var(--text-2); }
.pv-stat b { color: var(--emerald); }

.spinner {
  width: 30px; height: 30px; border-radius: 50%; margin: 0 auto;
  border: 3.5px solid var(--surface-2); border-top-color: var(--emerald-bright);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ai-wait { text-align: center; padding: 26px 12px; color: var(--text-2); font-size: 0.86rem; line-height: 1.9; }

/* ---------------------------------------------------------------- 借入金 */
.loan-hero {
  background: linear-gradient(140deg, #063f2e 0%, #0a5c40 55%, #0d7a52 100%);
  color: #fff; border-radius: var(--radius); padding: 20px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-2); position: relative; overflow: hidden;
}
.loan-hero::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 140px; height: 140px;
  border-radius: 50%; background: radial-gradient(circle, rgba(245, 158, 11, 0.35), transparent 70%);
}
.loan-hero .t { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.1em; opacity: 0.75; }
.loan-hero .v { font-size: 2rem; font-weight: 700; margin: 6px 0 2px; }
.loan-hero .s { font-size: 0.76rem; opacity: 0.75; }
.loan-months { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }
.loan-month-chip { background: rgba(255, 255, 255, 0.14); border-radius: 999px; padding: 4px 11px; font-size: 0.74rem; font-weight: 600; }

.loan-progress { height: 4.5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 7px; }
.loan-progress span { display: block; height: 100%; background: var(--grad); border-radius: 999px; }
.status-chip { font-size: 0.68rem; font-weight: 700; padding: 2.5px 9px; border-radius: 999px; flex: none; }
.status-chip.unsettled { background: #fde8e8; color: var(--red); }
.status-chip.partial { background: var(--amber-soft); color: var(--gold); }
.status-chip.settled { background: #d9f2e7; color: var(--emerald); }

/* 借入金ビューの配置用（PCグリッドでgrid-areaを割り当てるためclass化） */
.l-btn { margin-bottom: 14px; }
.l-chips { margin-bottom: 12px; }
.l-hist { margin-top: 16px; }

/* 月別グループカード */
.mg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.mg-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; }
.mg-sub { font-size: 0.78rem; color: var(--text-2); margin-top: 3px; }
.mg-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }
.mg-out { font-size: 1.02rem; font-weight: 700; color: var(--gold-bright); }
.mg-items { margin-top: 12px; }
.mg-items .tx-row { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.mg-toggle { flex: 0 0 132px; font-size: 0.85rem; padding: 11px 8px; }

.settle-row { padding: 12px 4px; border-bottom: 1px solid var(--outline); }
.settle-row:last-child { border-bottom: 0; }
.settle-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.settle-allocs { font-size: 0.74rem; color: var(--muted); margin-top: 5px; line-height: 1.7; }
.select-loan {
  display: flex; align-items: center; gap: 10px; padding: 10px 6px;
  border-bottom: 1px solid var(--outline); width: 100%; text-align: left;
  cursor: pointer;
}

/* ---------------------------------------------------------------- 分析 */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 150px; height: 150px; flex: none; }
.donut .center-v { font-family: "Roboto", var(--font); font-size: 15px; font-weight: 700; fill: var(--text); }
.donut .center-t { font-size: 8.5px; fill: var(--muted); font-weight: 600; }
.legend { flex: 1; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 4.5px 0; font-size: 0.8rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 4px; flex: none; }
.legend-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.legend-val { font-weight: 700; }
.legend-pct { color: var(--muted); font-size: 0.72rem; min-width: 38px; text-align: right; }

.trend { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 8px; }
.trend-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.trend-stack { width: 100%; max-width: 44px; display: flex; flex-direction: column-reverse; border-radius: 8px 8px 4px 4px; overflow: hidden; }
.trend-seg { width: 100%; }
.trend-label { font-size: 0.68rem; color: var(--muted); font-weight: 600; }
.trend-total { font-size: 0.66rem; color: var(--text-2); font-weight: 700; }

.legend-row.clickable, .bar-list-row.clickable { cursor: pointer; border-radius: 8px; }
.legend-row.clickable:hover, .bar-list-row.clickable:hover { background: var(--surface-2); }

.bar-list-row { margin-bottom: 10px; }
.bar-list-head { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 4px; }
.bar-list-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-list-fill { height: 100%; border-radius: 999px; background: var(--grad); }

/* ---------------------------------------------------------------- 設定 */
.setting-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--outline); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .name { flex: 1; font-size: 0.9rem; font-weight: 500; }
.setting-row .sub { font-size: 0.72rem; color: var(--muted); }
.setting-row input.inline { width: 130px; padding: 8px 11px; text-align: right; font-variant-numeric: tabular-nums; }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input, .add-row select { flex: 1; padding: 9px 12px; }
.add-row button { flex: none; }
.arch-btn { font-size: 0.72rem; color: var(--muted); font-weight: 600; padding: 6px 9px; border-radius: 9px; background: var(--surface-2); flex: none; }
.arch-btn:active { background: var(--outline); }

/* カテゴリ並び替え */
.cat-row { gap: 6px; }
.drag-handle {
  cursor: grab; color: var(--muted); font-size: 0.95rem;
  padding: 0 2px; flex: none; user-select: none; -webkit-user-select: none;
}
.cat-row.dragging { opacity: 0.45; }
.arch-btn.mv { padding: 6px 9px; font-size: 0.8rem; line-height: 1; }
/* タッチ端末はHTML5ドラッグが効かないためハンドルを隠し、↑↓のみにする */
@media (hover: none) { .drag-handle { display: none; } }

/* ---------------------------------------------------------------- 年間ダッシュボード */
.mode-seg { max-width: 280px; margin: 0 auto 14px; }

.kpi-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 12px; }
.kpi .k { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 700; margin-bottom: 3px; }
.kpi .v { font-size: 1.28rem; font-weight: 700; }
.kpi.gold { grid-column: 1 / -1; border-top: 1.5px dashed var(--outline-strong); padding-top: 10px; }
.kpi.gold .v {
  font-size: 1.85rem;
  background: var(--grad-gold);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.kpi-sub { font-size: 0.75rem; color: var(--text-2); line-height: 1.9; }
.kpi-sub b { font-weight: 700; }

.ychart { width: 100%; height: auto; display: block; }
.yc-grid { stroke: var(--outline); stroke-width: 1; }
.yc-zero { stroke: var(--outline-strong); stroke-width: 1.2; }
.yc-ylab, .yc-xlab { font-size: 10.5px; fill: var(--muted); font-family: "Roboto", sans-serif; }
.yc-ylab { text-anchor: end; }
.yc-xlab { text-anchor: middle; }
.yc-bar { fill: var(--emerald-bright); opacity: 0.72; }
.yc-line { fill: none; stroke: var(--gold-bright); stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.yc-dot { fill: #fff; stroke: var(--gold-bright); stroke-width: 2; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 10px; vertical-align: -1px; }
.lg-sales { background: var(--emerald-bright); opacity: 0.8; }
.lg-ten { background: var(--gold-bright); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ytable { width: 100%; border-collapse: collapse; font-size: 0.78rem; min-width: 460px; }
.ytable th {
  text-align: right; padding: 6px 6px; color: var(--muted); font-weight: 600;
  border-bottom: 1.5px solid var(--outline-strong); white-space: nowrap;
}
.ytable th:first-child { text-align: left; }
.ytable td { padding: 7.5px 6px; border-bottom: 1px solid var(--outline); white-space: nowrap; }
.ytable td.r { text-align: right; font-variant-numeric: tabular-nums; }
.ytable td.c { text-align: center; font-size: 0.72rem; color: var(--muted); }
.ytable td.ten { font-weight: 700; }
.ytable tr[data-month] { cursor: pointer; }
.ytable tr.now td { background: #eefaf4; }
.ytable tr.total td { border-top: 2px solid var(--outline-strong); border-bottom: 0; font-weight: 700; }

.fc-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 8px 0; font-size: 0.84rem; color: var(--text-2);
  border-bottom: 1px solid var(--outline);
}
.fc-row b { font-weight: 700; color: var(--text); }
.fc-row.big b {
  font-size: 1.3rem;
  background: var(--grad-gold);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------------------------------------------------------------- スナックバー */
.snackbar {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(92px + env(safe-area-inset-bottom));
  background: #1f2b26; color: #fff; border-radius: 14px;
  padding: 12px 18px; font-size: 0.86rem; font-weight: 500;
  box-shadow: var(--shadow-2); opacity: 0; pointer-events: none;
  transition: all 0.25s; z-index: 60; max-width: min(560px, calc(100% - 32px));
  display: flex; align-items: center; gap: 14px;
}
.snackbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.snackbar button { color: #fcd34d; font-weight: 700; flex: none; }

/* ---------------------------------------------------------------- ログイン */
.login-wrap {
  max-width: 380px; margin: 0 auto; padding: 15dvh 24px 40px; text-align: center;
}
.login-icon { width: 74px; height: 74px; border-radius: 20px; box-shadow: var(--shadow-2); margin-bottom: 20px; }
.login-kicker {
  font-family: var(--font-display); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.22em;
  background: var(--grad-gold);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.login-logo {
  font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; letter-spacing: 0.06em;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  margin: 2px 0 6px;
}
.login-sub { color: var(--text-2); font-size: 0.86rem; margin-bottom: 30px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--red); font-size: 0.85rem; margin-bottom: 14px; font-weight: 600; }

@media (min-width: 700px) {
  .app { padding-top: 24px; }
  .tx-row:hover { border-color: var(--outline-strong); }
  .menu-item:hover, .icon-btn:hover { background: var(--surface-2); }
}

/* ================================================================
   PCレイアウト（1024px〜）
   ボトムバー→左ナビゲーションレール、ボトムシート→中央ダイアログ、
   各ビューをマルチカラムグリッドに展開する。
   理由: モバイルの縦積みをそのまま広げると余白だけが増えて一覧性が
   上がらないため、PCでは画面幅を情報の並列表示に使う。
   ================================================================ */
@media (min-width: 1024px) {
  body { padding-left: 96px; }
  .app { max-width: 1160px; padding-bottom: 48px; }

  /* 左ナビゲーションレール（MD3 navigation rail） */
  .tabbar {
    top: 0; bottom: 0; left: 0; transform: none;
    width: 96px; height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 12px;
    padding: 22px 12px;
    border-radius: 0; border: 0; border-right: 1px solid var(--outline);
  }
  .tab { min-width: 0; width: 100%; }
  .tab-fab { order: -1; margin: 0 0 16px; }
  .tab-pill { width: 52px; }
  .tab:hover .tab-pill { background: var(--surface-2); }
  .tab.active:hover .tab-pill { background: var(--grad-soft); }

  /* シートは中央ダイアログに（モバイルのボトムシートはPCでは遠すぎるため） */
  .sheet {
    left: calc(50% + 48px); top: 50%; bottom: auto;
    width: min(620px, calc(100vw - 220px));
    max-height: 86dvh; border-radius: 28px;
    padding: 22px 28px 28px;
    transform: translate(-50%, -47%) scale(0.97);
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), opacity 0.16s, visibility 0.16s;
  }
  .sheet.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1; visibility: visible; pointer-events: auto;
  }
  .sheet::before { display: none; }
  .snackbar { left: calc(50% + 48px); bottom: 36px; }
  .selbar { left: calc(50% + 48px); bottom: 28px; }

  /* ホーム: 手残りウォーターフォールとチェックリストを並列の主役に */
  #view-home.active {
    display: grid; gap: 16px; align-items: start;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas:
      "seg  seg"
      "wf   gauge"
      "wf   mini"
      "wf   checks"
      "cov  checks"
      "top  checks";
  }
  #view-home.active > * { margin-bottom: 0; }
  .mode-seg { grid-area: seg; width: 280px; margin: 0 auto; }

  /* ホーム年間モード: KPI全幅、左にチャート・予測、右に月次テーブル */
  #view-home.active.year {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas:
      "seg      seg"
      "kpi      kpi"
      "chart    table"
      "forecast table"
      "top      table";
  }
  .y-kpi { grid-area: kpi; }
  .y-chart { grid-area: chart; }
  .y-forecast { grid-area: forecast; }
  .y-table { grid-area: table; }
  .y-top { grid-area: top; }
  .kpi-row { grid-template-columns: 1fr 1fr 1.3fr; }
  .kpi.gold {
    grid-column: auto; border-top: 0; padding-top: 0;
    border-left: 1.5px dashed var(--outline-strong); padding-left: 18px;
  }
  .ytable tr[data-month]:hover td { background: var(--surface-2); }
  .c-wf { grid-area: wf; padding: 24px; }
  .c-gauge { grid-area: gauge; }
  .c-mini { grid-area: mini; }
  .c-checks { grid-area: checks; }
  .c-cov { grid-area: cov; }
  .c-top { grid-area: top; }
  .c-wf .wf-row { margin-bottom: 17px; }
  .c-wf .wf-track { height: 14px; }
  .c-wf .wf-tenokori .wf-value { font-size: 1.7rem; }

  /* 取引: 行の可読幅を保って中央寄せ、ツールバーは横並び */
  #view-tx.active { max-width: 920px; margin: 0 auto; }
  #view-tx .toolbar { flex-direction: row; align-items: center; }
  #view-tx .searchbox { flex: 1; }

  /* 借入金: 立替台帳と精算履歴を並列 */
  #view-loans.active {
    display: grid; gap: 16px; align-items: start;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas:
      "hero  hist"
      "pend  hist"
      "list  hist";
  }
  #view-loans.active > * { margin-bottom: 0; }
  .l-hero { grid-area: hero; }
  .l-pend { grid-area: pend; }
  .l-list { grid-area: list; }
  .l-hist { grid-area: hist; margin-top: 0; }

  /* 分析: 当月内訳と推移を横並び、事業経費は全幅 */
  #view-analysis.active {
    display: grid; gap: 16px; align-items: start;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "donut trend" "subs biz";
  }
  #view-analysis.active > * { margin-bottom: 0; }
  .a-donut { grid-area: donut; }
  .a-trend { grid-area: trend; }
  .a-subs { grid-area: subs; }
  .a-biz { grid-area: biz; }
  .a-donut .donut { width: 180px; height: 180px; }

  /* 設定: カードを2列に */
  #view-settings.active {
    display: grid; gap: 16px; align-items: start;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  #view-settings.active > .card { margin-bottom: 0; }
}

/* 入力状況（どこまで取り込んだか） */
.cov-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--outline); font-size: 0.84rem; }
.cov-row:last-of-type { border-bottom: 0; }
.cov-name { flex: 0 0 38%; font-weight: 600; color: var(--text); line-height: 1.4; }
.cov-line { flex: 1; color: var(--text-2); line-height: 1.6; }
.cov-line b { color: var(--text); font-weight: 700; }
.cov-src { color: var(--muted); font-size: 0.76rem; }
.cov-none { color: var(--muted); }
.cov-flag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 8px; font-size: 0.7rem; font-weight: 700; }
.cov-flag.warn { background: var(--amber-soft); color: var(--gold); }
.cov-flag.alert { background: rgba(220, 74, 94, 0.12); color: var(--red); }
.cov-inline { margin-top: 8px; font-size: 0.84rem; color: var(--text-2); line-height: 1.6; }
.cov-inline b { color: var(--text); }
