:root {
  --color-bg: #f5f6f4;
  --color-surface: #ffffff;
  --color-border: #e2e4df;
  --color-text: #22282a;
  --color-text-muted: #6b7370;
  --color-accent: #2f6f5e;
  --color-accent-soft: #e7f1ed;
  --color-ta: #2f6f5e;
  --color-chi: #b3612c;
  --color-common: #556;
  --color-positive: #2f6f5e;
  --color-negative: #b3402c;
  --radius: 12px;
  --gap: 12px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  line-height: 1.5;
  padding-bottom: 32px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
}

/* ---------- ヘッダー / タブ ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-accent);
  color: #fff;
  padding: 14px 16px 0;
}

.app-header h1 {
  font-size: 1.25rem;
  margin-bottom: 10px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 4px;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.tab-btn.is-active {
  color: #fff;
  border-bottom-color: #fff;
}

/* ---------- レイアウト共通 ---------- */

main#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.view-title {
  font-size: 1.05rem;
  margin: 4px 0 12px;
  color: var(--color-text);
}

/* ---------- 月次ビュー ---------- */

.month-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 14px;
}

.switch-btn {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  color: var(--color-accent);
  cursor: pointer;
}

.switch-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.month-label {
  font-size: 1.15rem;
  font-weight: 700;
  min-width: 8em;
  text-align: center;
}

.edit-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.edit-toggle-btn {
  appearance: none;
  border: 1px solid var(--color-accent);
  background: var(--color-surface);
  color: var(--color-accent);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 16px;
  cursor: pointer;
}

.edit-toggle-btn.is-active {
  background: var(--color-accent);
  color: #fff;
}

.edit-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.edit-badge {
  display: inline-block;
  background: #fff2d9;
  color: #8a5a00;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.reset-btn,
.copy-btn {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius);
  font-size: 0.78rem;
  padding: 6px 10px;
  cursor: pointer;
}

.reset-btn:disabled,
.copy-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.copy-btn {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

#copy-output-area:not(:empty) {
  margin: -4px 0 14px;
}

.copy-success {
  margin: 0;
  padding: 8px 12px;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  border-radius: var(--radius);
  font-size: 0.82rem;
}

.copy-hint {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

textarea.copy-fallback {
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  resize: vertical;
}

.item-list.edit-list li {
  align-items: center;
  gap: 10px;
}

.item-list.edit-list .item-name {
  flex: 1;
  min-width: 0;
}

.edit-input {
  appearance: none;
  width: 112px;
  flex: 0 0 auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.9rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.edit-input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.empty-state {
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  color: var(--color-text-muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  margin-bottom: 20px;
}

.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
}

.summary-card .label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.summary-card .value {
  font-size: 1.15rem;
  font-weight: 700;
  word-break: break-all;
}

.summary-card.is-wide {
  grid-column: 1 / -1;
}

.summary-card.accent-ta .value { color: var(--color-ta); }
.summary-card.accent-chi .value { color: var(--color-chi); }
.value.is-negative { color: var(--color-negative); }

.section-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.section-block h3 {
  font-size: 0.95rem;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-accent-soft);
}

.owner-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
  color: #fff;
}

.owner-tag.ta { background: var(--color-ta); }
.owner-tag.chi { background: var(--color-chi); }
.owner-tag.common { background: var(--color-common); }

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

.item-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}

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

.item-list .item-name {
  color: var(--color-text);
}

.item-list .item-note {
  display: block;
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

.item-list .item-amount {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

details.zero-items {
  border-top: 1px solid var(--color-border);
}

details.zero-items summary {
  padding: 8px 14px;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

/* ---------- テーブル（年間・余剰金） ---------- */

.table-scroll {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
  white-space: nowrap;
}

table.data-table th,
table.data-table td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
}

table.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 2;
  border-bottom: 2px solid var(--color-border);
}

table.data-table th:first-child,
table.data-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  text-align: left;
  z-index: 1;
  box-shadow: 1px 0 0 var(--color-border);
}

table.data-table thead th:first-child {
  z-index: 3;
}

table.data-table tr.row-summary td,
table.data-table tr.row-summary th {
  background: var(--color-accent-soft);
  font-weight: 700;
}

table.data-table tr.row-summary td:first-child,
table.data-table tr.row-summary th:first-child {
  background: var(--color-accent-soft);
}

table.data-table tr.row-highlight td {
  background: #fff7e8;
}

table.data-table tr.row-highlight td:first-child {
  background: #fff7e8;
}

table.data-table td.col-empty {
  color: var(--color-text-muted);
}

.load-error {
  margin: 16px;
  padding: 12px;
  background: #fdecec;
  color: #a3241a;
  border-radius: var(--radius);
}

@media (min-width: 480px) {
  .summary-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------- ロック画面 ---------- */

.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-bg);
}

.lock-box {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
}

.lock-box h2 {
  font-size: 1.2rem;
  color: var(--color-accent);
  margin-bottom: 8px;
}

.lock-desc {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0 0 18px;
}

#lock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#passphrase-input {
  appearance: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 1rem;
  width: 100%;
}

#passphrase-input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.lock-error {
  margin: 0;
  color: var(--color-negative);
  font-size: 0.82rem;
  text-align: left;
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--color-text);
  text-align: left;
}

.unlock-btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  background: var(--color-accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px;
  cursor: pointer;
}

.unlock-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.forget-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.72rem;
  text-decoration: underline;
  padding: 6px 0 10px;
  cursor: pointer;
}
