:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --color-primary: #16a34a;
  --color-danger: #dc2626;
  --color-warn: #d97706;
  --color-border: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f1f5f9;
    --color-muted: #94a3b8;
    --color-border: #334155;
  }
}

* { box-sizing: border-box; }
/* [hidden]属性は常にdisplay:noneを優先させる（.banner等のdisplay:flex指定に負けないようにする） */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  padding-bottom: 76px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-primary);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.app-header h1 { font-size: 1.05rem; margin: 0; }
.month-switcher { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.month-switcher button {
  background: rgba(255,255,255,0.2); color: #fff; border: none; border-radius: 6px;
  width: 28px; height: 28px; font-size: 1rem; cursor: pointer;
}

.banner {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; font-size: 0.85rem;
}
.banner-info { background: #fef9c3; color: #713f12; }
.banner-error { background: #fee2e2; color: #7f1d1d; }
.banner button { background: none; border: none; font-size: 1rem; cursor: pointer; color: inherit; }

main { max-width: 480px; margin: 0 auto; padding: 12px 16px 24px; }
.screen { display: none; }
.screen.active { display: block; }

.summary-card {
  background: var(--color-surface); border-radius: 12px; padding: 16px;
  display: flex; justify-content: space-between; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.summary-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.summary-item .label { font-size: 0.75rem; color: var(--color-muted); }
.summary-item .value { font-size: 1.1rem; font-weight: bold; }
.value.income { color: var(--color-primary); }
.value.expense { color: var(--color-danger); }
.value.negative { color: var(--color-danger); }

.budget-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.badge { font-size: 0.75rem; padding: 4px 8px; border-radius: 999px; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-over { background: #fee2e2; color: #991b1b; }
.badge-ok { background: #dcfce7; color: #166534; }

.section-title { font-size: 0.95rem; margin: 18px 0 8px; color: var(--color-muted); }

.tx-list, .category-manage-list, .budget-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tx-item, .category-manage-item, .budget-row {
  background: var(--color-surface); border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.tx-icon { font-size: 1.2rem; }
.tx-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tx-cat { font-size: 0.9rem; }
.tx-memo { font-size: 0.75rem; color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-date { font-size: 0.7rem; color: var(--color-muted); }
.tx-amount { font-weight: bold; min-width: 80px; text-align: right; }
.tx-amount.income { color: var(--color-primary); }
.tx-amount.expense { color: var(--color-text); }
.tx-edit, .tx-delete { border: none; background: none; cursor: pointer; font-size: 1rem; }

.empty-state { color: var(--color-muted); text-align: center; padding: 24px 8px; font-size: 0.9rem; }

.filter-row { margin-bottom: 10px; }
select, input[type="text"], input[type="number"], input[type="date"], input[type="color"] {
  font-size: 1rem; padding: 8px; border-radius: 8px; border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text); width: 100%;
}

.chart-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.chart-tab {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text); cursor: pointer;
}
.chart-tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.chart-pane { display: none; text-align: center; }
.chart-pane.active { display: block; }
#pieCanvas, #barCanvas { max-width: 100%; height: auto; }
.chart-legend { list-style: none; padding: 0; margin: 12px 0 0; text-align: left; font-size: 0.85rem; }
.chart-legend li { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.budget-row { justify-content: space-between; }
.budget-input { max-width: 120px; }
.hint { color: var(--color-muted); font-size: 0.8rem; }

.category-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip {
  border: 2px solid var(--chip-color, var(--color-border)); border-radius: 999px;
  padding: 6px 12px; background: var(--color-surface); color: var(--color-text);
  cursor: pointer; font-size: 0.85rem;
}
.chip.active { background: var(--chip-color, var(--color-primary)); color: #fff; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; margin-bottom: 10px; color: var(--color-muted); }
.ocr-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ocr-row label.btn-secondary { display: inline-block; margin: 0; cursor: pointer; }

.btn-primary, .btn-secondary, .btn-danger {
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 0.9rem; cursor: pointer;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; }
.form-error { color: var(--color-danger); font-size: 0.85rem; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.type-btn { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); cursor: pointer; }
.type-btn.active { background: var(--color-text); color: var(--color-surface); }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-actions-vertical { flex-direction: column; }

dialog.dialog {
  border: none; border-radius: 14px; padding: 20px; width: min(420px, 92vw);
  background: var(--color-surface); color: var(--color-text);
}
dialog.dialog::backdrop { background: rgba(0,0,0,0.4); }

.fab {
  position: fixed; right: 20px; bottom: 84px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-primary); color: #fff; font-size: 1.6rem; border: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25); cursor: pointer; z-index: 20;
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--color-surface); border-top: 1px solid var(--color-border); z-index: 15;
}
.nav-btn {
  flex: 1; border: none; background: none; color: var(--color-muted); padding: 8px 0;
  display: flex; flex-direction: column; align-items: center; font-size: 0.7rem; gap: 2px; cursor: pointer;
}
.nav-btn .nav-icon { font-size: 1.2rem; }
.nav-btn.active { color: var(--color-primary); font-weight: bold; }
