:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --green: #059669;
  --red: #dc2626;
  --orange: #ea580c;
  --purple: #7c3aed;
  --shadow: 0 8px 30px rgba(17, 24, 39, 0.06);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); }
body { margin: 0; background: var(--bg); min-height: 100vh; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(229,231,235,.8);
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.app-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 12px; background: #111827; color: white; font-weight: 800;
}
.brand { font-size: 16px; font-weight: 800; letter-spacing: .01em; }
.subtitle { margin-top: 1px; font-size: 11px; color: var(--muted); }
.icon-button {
  width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 20px; box-shadow: 0 3px 14px rgba(0,0,0,.04);
}
.main { max-width: 1040px; margin: 0 auto; padding: 12px 14px 28px; }

.source-card, .filter-card, .panel, .privacy-note {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.source-card { display: flex; justify-content: space-between; align-items: center; padding: 13px 14px; gap: 12px; }
.source-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.source-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(5,150,105,.10); }
.source-dot.loading { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245,158,11,.12); }
.source-dot.error { background: var(--red); box-shadow: 0 0 0 4px rgba(220,38,38,.10); }
.source-name { font-size: 13px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.source-meta { margin-top: 2px; font-size: 10px; color: var(--muted); }
.text-button { border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 700; padding: 8px; }

.filter-card { margin-top: 10px; padding: 13px; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filter-grid label { display: grid; gap: 5px; }
.filter-grid span { font-size: 10px; color: var(--muted); font-weight: 700; }
.filter-grid input, .search-wrap input {
  width: 100%; border: 1px solid var(--line); background: #fafafa; color: var(--text);
  border-radius: 12px; padding: 10px 11px; outline: none;
}
.filter-grid input:focus, .search-wrap input:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px #dbeafe; background: white; }
.filter-actions { display: flex; gap: 8px; margin-top: 10px; }
.primary-button, .secondary-button, .more-button {
  border-radius: 12px; border: 1px solid var(--line); padding: 10px 14px; font-size: 12px; font-weight: 750;
}
.primary-button { background: #111827; color: white; border-color: #111827; flex: 1; }
.secondary-button { background: white; color: var(--text); }

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 22px 4px 12px; }
.eyebrow { font-size: 10px; font-weight: 900; letter-spacing: .15em; color: var(--accent); }
.page-heading h1 { margin: 2px 0 0; font-size: 27px; line-height: 1.15; }
.page-heading p { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.period-badge { flex: 0 0 auto; border-radius: 999px; background: #e5e7eb; color: #374151; padding: 7px 10px; font-size: 10px; font-weight: 700; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.kpi-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-label { font-size: 10px; color: var(--muted); font-weight: 700; }
.kpi-value { margin-top: 7px; font-size: 22px; font-weight: 850; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-note { margin-top: 4px; font-size: 9px; color: var(--muted); }
.kpi-card.positive .kpi-value { color: var(--green); }
.kpi-card.negative .kpi-value { color: var(--red); }

.subnav { display: flex; gap: 6px; margin: 12px 0 0; overflow-x: auto; padding-bottom: 2px; }
.subnav button { border: 1px solid var(--line); background: white; color: #4b5563; border-radius: 999px; padding: 8px 14px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.subnav button.active { background: #111827; color: white; border-color: #111827; }
.hidden { display: none !important; }

.panel { margin-top: 12px; padding: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head p { margin: 3px 0 0; font-size: 10px; color: var(--muted); }
.chart-wrap { position: relative; width: 100%; min-height: 245px; }
.chart-wrap canvas { width: 100% !important; height: 245px !important; }
.breakdown-list { display: grid; gap: 9px; }
.breakdown-row { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; align-items: center; gap: 9px; }
.breakdown-name { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breakdown-bar { height: 8px; border-radius: 999px; background: #eef2f7; overflow: hidden; }
.breakdown-bar > span { display: block; height: 100%; border-radius: inherit; background: #60a5fa; }
.breakdown-value { font-size: 10px; font-weight: 700; color: #4b5563; }

.list-head { align-items: end; }
.search-wrap { width: min(180px, 42vw); }
.search-wrap input { padding: 8px 10px; font-size: 11px; }
.data-list { display: grid; gap: 0; border-top: 1px solid #f0f1f3; }
.data-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f0f1f3; }
.data-main { min-width: 0; }
.data-title { font-size: 12px; font-weight: 750; line-height: 1.45; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.data-meta { margin-top: 4px; font-size: 9px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; }
.data-values { text-align: right; min-width: 84px; }
.data-amount { font-size: 13px; font-weight: 800; }
.data-profit { margin-top: 3px; font-size: 10px; color: var(--green); font-weight: 700; }
.data-profit.negative { color: var(--red); }
.tag { display: inline-block; border-radius: 999px; padding: 2px 6px; background: #f3f4f6; color: #4b5563; }
.empty-state { padding: 36px 10px; text-align: center; color: var(--muted); font-size: 12px; }
.more-button { width: 100%; margin-top: 12px; background: #f9fafb; color: #374151; }

.privacy-note { margin-top: 12px; padding: 13px 14px; display: grid; gap: 3px; }
.privacy-note strong { font-size: 11px; }
.privacy-note span { color: var(--muted); font-size: 9px; line-height: 1.5; }

.bottom-nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5,1fr);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.96); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.nav-item { display: grid; place-items: center; gap: 3px; border: 0; background: transparent; color: #9ca3af; padding: 5px 2px; }
.nav-item span { font-size: 18px; line-height: 1; }
.nav-item em { font-style: normal; font-size: 9px; font-weight: 750; }
.nav-item.active { color: #111827; }

.loading-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(244,246,248,.72); backdrop-filter: blur(8px); }
.loader-card { background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 20px 24px; display: flex; align-items: center; gap: 12px; font-size: 12px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #e5e7eb; border-top-color: #111827; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 90; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .22s ease; background: #111827; color: white; border-radius: 999px; padding: 10px 14px; font-size: 11px; font-weight: 700; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (min-width: 720px) {
  .main { padding: 18px 24px 40px; }
  .topbar { padding-left: 28px; padding-right: 28px; }
  .filter-card { display: flex; align-items: end; justify-content: space-between; gap: 14px; }
  .filter-grid { width: 420px; }
  .filter-actions { margin: 0; }
  .primary-button { min-width: 120px; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .chart-wrap, .chart-wrap canvas { height: 320px !important; min-height: 320px; }
  .source-name { max-width: 520px; }
  .bottom-nav { left: 50%; transform: translateX(-50%); max-width: 520px; bottom: 18px; border: 1px solid var(--line); border-radius: 20px; padding: 8px 10px; box-shadow: 0 12px 35px rgba(17,24,39,.14); }
  .app-shell { padding-bottom: 110px; }
}
