/* ===== デザイン変数（ポイ帳方針ベース・家計簿用ブランド色） ===== */
:root {
  /* ブランド: 落ち着いたティール（ポイ帳の緑 #5ac26a とは別色） */
  --brand: #2a9d8f;
  --brand-pressed: #238b7e;
  --brand-soft: #e6f5f3;

  /* 支出: コーラル寄り */
  --expense: #e76f51;
  --expense-pressed: #d96145;
  --expense-soft: #fde8e1;
  --expense-text: #c2513a;

  /* 収入はブランド色側で区別 */
  --income: var(--brand);
  --income-pressed: var(--brand-pressed);
  --income-soft: var(--brand-soft);
  --income-text: #1f7a6e;

  /* ベース */
  --bg: #ffffff;
  --bg-muted: #f5f6f5;
  --border: #e6e9e7;
  --text: #111111;
  --text-muted: #6b7280;

  /* 角丸・余白・幅 */
  --radius-card: 1.25rem;
  --radius-control: 0.75rem;
  --radius-pill: 999px;
  --space: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --app-max: 28rem;
  --tap-min: 48px;

  /* フォント */
  --font-display: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  --font-body: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
}

.app {
  max-width: var(--app-max);
  margin: 0 auto;
  padding: calc(var(--space) + env(safe-area-inset-top, 0px))
    calc(var(--space) + 4px) calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
}

/* ヘッダー：ブランド級タイトル＋設定 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  position: relative;
  margin: 0.25rem 0 var(--space-lg);
}

.app-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
}

.settings-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  min-height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
}

.settings-toggle[aria-expanded="true"] {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--income-text);
}

/* ===== 設定パネル ===== */
.settings-panel[hidden] {
  display: none;
}

.settings-lead {
  margin: -0.25rem 0 var(--space);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.settings-block {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space);
  border-bottom: 1px solid var(--border);
}

.settings-block:last-of-type {
  border-bottom: none;
  margin-bottom: var(--space);
  padding-bottom: 0;
}

.settings-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.settings-subtitle {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
}

.settings-note {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.settings-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.settings-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.65rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row.is-hidden-item {
  opacity: 0.55;
}

.settings-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.settings-row-main {
  min-width: 0;
}

.settings-row-name {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  word-break: break-word;
}

.settings-row-meta {
  margin: 0.1rem 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.settings-row-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.settings-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 0.75rem;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
}

.settings-tab {
  min-height: 2.5rem;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
}

.settings-tab.is-active {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.settings-tab[data-cat-type="expense"].is-active {
  color: var(--expense-text);
  border-color: transparent;
  background: var(--expense-soft);
}

.settings-tab[data-cat-type="income"].is-active {
  color: var(--income-text);
  border-color: transparent;
  background: var(--income-soft);
}

.settings-close {
  width: 100%;
  margin-top: 0.25rem;
}

/* ボタン類 */
.ghost-button,
.secondary-button,
.primary-button,
.danger-button {
  min-height: 2.5rem;
  padding: 0 0.85rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}

.ghost-button {
  border: none;
  background: transparent;
  color: var(--text-muted);
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.primary-button {
  border: none;
  background: var(--brand);
  color: #fff;
}

.primary-button:active {
  background: var(--brand-pressed);
}

.danger-button {
  border: none;
  background: var(--expense-soft);
  color: var(--expense-text);
}

/* ===== 今月のサマリー（薄い面＋大きな数字） ===== */
.summary {
  margin-bottom: var(--space-lg);
  padding: var(--space-lg) var(--space);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg-muted);
  text-align: center;
}

.summary-balance-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.summary-balance-amount {
  margin: 0.25rem 0 var(--space);
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space);
  padding-top: var(--space);
  border-top: 1px solid var(--border);
}

.summary-item {
  padding: 0;
  background: transparent;
}

.summary-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.summary-amount {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.summary-unit {
  margin-left: 0.1rem;
  font-size: 0.85em;
  font-weight: 700;
}

.summary-expense .summary-amount {
  color: var(--expense-text);
}

.summary-income .summary-amount {
  color: var(--income-text);
}

/* ===== カード（薄い枠・影なし） ===== */
.card {
  margin-bottom: var(--space-lg);
  padding: var(--space-lg) var(--space);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg);
  box-shadow: none;
}

.section-title {
  margin: 0 0 var(--space);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
}

/* ===== 支出 / 収入タブ ===== */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 0.5rem;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
}

.mode-tab {
  min-height: var(--tap-min);
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.mode-tab.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}

.entry-card[data-mode="expense"] .mode-tab[data-mode="expense"].is-active {
  color: var(--expense-text);
  border-color: transparent;
  background: var(--expense-soft);
}

.entry-card[data-mode="income"] .mode-tab[data-mode="income"].is-active {
  color: var(--income-text);
  border-color: transparent;
  background: var(--income-soft);
}

.swipe-hint {
  margin: 0 0 var(--space);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}

/* スワイプ領域 */
.entry-card {
  touch-action: pan-y;
}

.swipe-area {
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.swipe-area.is-dragging {
  cursor: grabbing;
}

.swipe-track {
  will-change: transform;
  transition: transform 0.25s ease;
}

.swipe-area.is-dragging .swipe-track {
  transition: none;
}

.swipe-panel {
  width: 100%;
}

@media (prefers-reduced-motion: reduce) {
  .swipe-track {
    transition: none;
  }
}

/* ===== 入力フォーム ===== */
.field {
  margin: 0 0 var(--space);
  padding: 0;
  border: none;
}

.field label,
.field legend {
  display: block;
  margin-bottom: 0.4rem;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 700;
}

.field input[type="date"],
.field input[type="number"],
.field input[type="text"] {
  width: 100%;
  height: var(--tap-min);
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
}

.field input:focus {
  outline: 2px solid var(--brand);
  border-color: var(--brand);
}

.entry-card[data-mode="expense"] .field input:focus {
  outline-color: var(--expense);
  border-color: var(--expense);
}

.entry-card[data-mode="income"] .field input:focus {
  outline-color: var(--income);
  border-color: var(--income);
}

/* 誰の？チップ */
.member-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.member-chip {
  position: relative;
  margin: 0;
}

.member-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.member-chip span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}

.member-chip .chip-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--chip-color, var(--text-muted));
}

.member-chip input:checked + span {
  border-color: transparent;
  background: var(--brand-soft);
  color: var(--income-text);
}

.entry-card[data-mode="expense"] .member-chip input:checked + span {
  background: var(--expense-soft);
  color: var(--expense-text);
}

.member-chip input:focus-visible + span {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}

/* カテゴリボタン（3列・ピル寄り） */
.category-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.category {
  position: relative;
  margin: 0;
}

.category input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.category span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 0.25rem;
  border: 1.5px solid var(--color);
  border-radius: var(--radius-pill);
  color: var(--color);
  background: var(--bg);
  font-size: 0.8125rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.category input:checked + span {
  background: var(--color);
  color: #fff;
}

.category input:focus-visible + span {
  outline: 3px solid var(--text);
  outline-offset: 2px;
}

/* ===== 追加ボタン（太いCTA・ピル・影なし） ===== */
.submit-button {
  width: 100%;
  min-height: 3.5rem;
  border: none;
  border-radius: var(--radius-pill);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
  cursor: pointer;
  background: var(--expense);
  box-shadow: none;
}

.entry-card[data-mode="income"] .submit-button {
  background: var(--income);
}

.submit-button:active {
  background: var(--expense-pressed);
}

.entry-card[data-mode="income"] .submit-button:active {
  background: var(--income-pressed);
}

/* ===== 一覧（区切り線のみ・カード重ねない） ===== */
.entry-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  align-items: center;
  padding: var(--space) 0;
  border-bottom: 1px solid var(--border);
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-main {
  min-width: 0;
}

.entry-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.15rem;
}

.entry-type {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
}

.entry-type-expense {
  background: var(--expense-soft);
  color: var(--expense-text);
}

.entry-type-income {
  background: var(--income-soft);
  color: var(--income-text);
}

.entry-category {
  font-size: 0.9375rem;
  font-weight: 700;
}

.entry-member {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.entry-member-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--member-color, var(--text-muted));
}

.entry-meta {
  color: var(--text-muted);
  font-size: 0.8125rem;
  word-break: break-word;
}

.entry-amount {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
  white-space: nowrap;
}

.entry-amount-expense {
  color: var(--expense-text);
}

.entry-amount-income {
  color: var(--income-text);
}

.entry-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.delete-button {
  min-height: 2.5rem;
  padding: 0 0.85rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--expense-soft);
  color: var(--expense-text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}

.delete-button:active {
  filter: brightness(0.96);
}

.empty-message {
  margin: 0;
  padding: var(--space-xl) 0;
  color: var(--text-muted);
  text-align: center;
}

.entry-list:not(:empty) + .empty-message {
  display: none;
}

/* ===== ダイアログ ===== */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space);
  background: rgba(17, 17, 17, 0.35);
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog {
  width: 100%;
  max-width: var(--app-max);
  padding: var(--space-lg) var(--space);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg);
}

.dialog-title {
  margin: 0 0 var(--space);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 800;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: var(--space);
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.color-option {
  position: relative;
  margin: 0;
}

.color-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.color-option span {
  display: block;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--swatch);
  border: 2px solid transparent;
  cursor: pointer;
}

.color-option input:checked + span {
  border-color: var(--text);
  outline: 2px solid var(--bg);
  outline-offset: -4px;
}

.color-option input:focus-visible + span {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

@media (min-width: 480px) {
  .dialog-backdrop {
    align-items: center;
  }
}
