:root {
  --primary: #2d7a5f;
  --primary-dark: #1f5d47;
  --primary-light: #e7f4ee;
  --background: #f5f7f6;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e2e8e5;
  --danger: #c73e3e;
  --danger-light: #fff0f0;
  --shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--background);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Kaku Gothic ProN",
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 認証画面 */
.auth-screen {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background:
    radial-gradient(circle at top left, #dff3e9 0, transparent 36%),
    var(--background);
}

.auth-card {
  width: min(100%, 440px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-icon,
.logo-mark {
  display: grid;
  color: #ffffff;
  font-weight: 800;
  background: var(--primary);
  place-items: center;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 24px;
  padding: 4px;
  background: #f0f3f1;
  border-radius: 10px;
}

.auth-tab {
  padding: 10px;
  color: var(--muted);
  font-weight: 700;
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.auth-tab.active {
  color: var(--primary-dark);
  background: #ffffff;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.08);
}

#auth-form {
  display: grid;
  gap: 16px;
}

#auth-form h2 {
  margin: 0;
  font-size: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: #374151;
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid #cfd8d3;
  border-radius: 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 122, 95, 0.15);
}

.form-help,
.message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.message.success {
  color: var(--primary-dark);
}

.message.error {
  color: var(--danger);
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.delete-button {
  border: 0;
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.delete-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.primary-button {
  min-height: 46px;
  padding: 11px 18px;
  color: #ffffff;
  font-weight: 700;
  background: var(--primary);
  border-radius: 10px;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.full-width {
  width: 100%;
}

.secondary-button {
  padding: 9px 13px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
  background: var(--primary-light);
  border-radius: 9px;
}

.text-button {
  padding: 8px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
  background: transparent;
}

/* アプリ全体 */
.app-screen {
  min-height: 100vh;
  padding-bottom: 78px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.header-inner {
  display: flex;
  width: min(100% - 32px, 960px);
  min-height: 64px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: inline-flex;
  gap: 8px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  align-items: center;
}

.logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 16px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-email {
  max-width: 160px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  width: min(100% - 32px, 960px);
  margin: 0 auto;
  padding: 28px 0;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-heading {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  align-items: flex-end;
  justify-content: space-between;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 32px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.subtext {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.summary-card {
  margin-bottom: 18px;
  padding: 24px;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent),
    var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.compact-summary {
  margin-bottom: 18px;
}

.summary-label {
  margin: 0;
  font-size: 14px;
  opacity: 0.9;
}

.summary-amount {
  margin: 7px 0;
  font-size: clamp(32px, 7vw, 44px);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.summary-note {
  margin: 0;
  font-size: 13px;
  opacity: 0.85;
}

.content-card {
  margin-bottom: 18px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(31, 41, 51, 0.04);
}

.section-heading {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
  align-items: center;
  justify-content: space-between;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* カテゴリグラフ */
.category-chart {
  display: grid;
  gap: 16px;
}

.chart-row {
  display: grid;
  gap: 7px;
}

.chart-label-row {
  display: flex;
  gap: 12px;
  font-size: 14px;
  justify-content: space-between;
}

.chart-category {
  color: #374151;
  font-weight: 700;
}

.chart-value {
  color: var(--muted);
  font-size: 13px;
}

.chart-bar-track {
  width: 100%;
  height: 11px;
  overflow: hidden;
  background: #eaf0ed;
  border-radius: 999px;
}

.chart-bar {
  height: 100%;
  min-width: 4px;
  background: linear-gradient(90deg, #52a982, var(--primary));
  border-radius: inherit;
}

/* 支出一覧 */
.expense-list {
  display: grid;
  gap: 10px;
}

.expense-item {
  display: flex;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.expense-item:last-child {
  border-bottom: 0;
}

.category-badge {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  background: var(--primary-light);
  border-radius: 50%;
  place-items: center;
}

.expense-info {
  min-width: 0;
  flex: 1;
}

.expense-note {
  overflow: hidden;
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expense-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.expense-right {
  display: flex;
  gap: 8px;
  text-align: right;
  align-items: center;
}

.expense-amount {
  margin: 0;
  color: #202c25;
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}

.delete-button {
  padding: 7px 9px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  background: var(--danger-light);
  border-radius: 8px;
}

.empty-text {
  margin: 6px 0;
  padding: 20px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* 支出入力フォーム */
.expense-form {
  display: grid;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 42px;
}

.input-with-unit span {
  position: absolute;
  top: 50%;
  right: 13px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  transform: translateY(-50%);
  pointer-events: none;
}

.form-actions {
  display: flex;
  gap: 14px;
  align-items: center;
}

/* 月選択 */
.month-selector {
  display: flex;
  gap: 8px;
  align-items: center;
}

.month-input-label input {
  min-height: 40px;
  padding: 8px;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  color: var(--primary-dark);
  font-size: 27px;
  line-height: 1;
  background: var(--primary-light);
  border-radius: 10px;
  place-items: center;
}

/* 下部ナビゲーション */
.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.nav-button {
  display: grid;
  gap: 3px;
  min-height: 62px;
  padding: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  background: transparent;
  border: 0;
  place-items: center;
}

.nav-button.active {
  color: var(--primary);
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
}

@media (min-width: 769px) {
  .app-screen {
    padding-bottom: 0;
  }

  .bottom-nav {
    position: static;
    width: min(100% - 32px, 960px);
    margin: 0 auto 28px;
    background: transparent;
    border-top: 0;
  }

  .nav-button {
    min-height: 46px;
    border-radius: 10px;
  }

  .nav-button.active {
    background: var(--primary-light);
  }
}

@media (max-width: 600px) {
  .auth-card {
    padding: 24px;
  }

  .header-inner,
  .main-content {
    width: min(100% - 24px, 960px);
  }

  .main-content {
    padding-top: 20px;
  }

  .user-email {
    display: none;
  }

  .content-card {
    padding: 17px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading .secondary-button {
    flex: 0 0 auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    display: grid;
  }

  .monthly-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .expense-item {
    align-items: flex-start;
  }

  .expense-right {
    flex-direction: column;
    align-items: flex-end;
  }
}