:root {
  --viewport-width: 100vw;
  --visual-viewport-height: 100vh;
  --keyboard-inset: 0px;
  --chart-max-width: 760px;
  --bg: #f7f2e8;
  --bg-deep: #e6dac2;
  --surface: rgba(255, 251, 244, 0.86);
  --surface-strong: #fffdfa;
  --ink: #1e2627;
  --muted: #667275;
  --line: rgba(30, 38, 39, 0.12);
  --primary: #0f766e;
  --primary-deep: #0a4f4a;
  --accent: #c26d00;
  --danger: #b13c59;
  --success: #1f8f63;
  --shadow: 0 22px 60px rgba(41, 49, 53, 0.08);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-display: "Yu Mincho", "Hiragino Mincho ProN", serif;
  --font-body: "Yu Gothic UI", "Hiragino Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  overflow-x: clip;
  scroll-padding-bottom: calc(var(--keyboard-inset) + 96px);
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 28%),
    radial-gradient(circle at right 10% top 15%, rgba(15, 118, 110, 0.08), transparent 20%),
    linear-gradient(140deg, var(--bg) 0%, #faf5eb 48%, var(--bg-deep) 100%);
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(1200px, calc(var(--viewport-width) - 32px));
  max-width: 100%;
  margin: 0 auto;
  padding: 28px 0 calc(48px + var(--keyboard-inset));
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
  gap: 18px;
}

.hero-copy,
.hero-status,
.panel {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  align-items: center;
  padding: 28px 32px;
  border-radius: var(--radius-lg);
}

.hero-status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px;
  border-radius: var(--radius-lg);
}

.section-kicker {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--primary);
}

.hero-copy h1,
.panel-header h2,
.chart-header h3,
.entry-form h3,
.total-card h3 {
  margin: 0;
  font-family: var(--font-display);
}

.hero-copy h1 {
  font-size: clamp(1.8rem, 2.6vw, 2.6rem);
  line-height: 1.1;
}

.panel-meta,
.form-head p,
.chart-header p,
.helper-text,
.status-label {
  color: var(--muted);
}

.status-dot {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--success), #33b97e);
  box-shadow: 0 0 0 8px rgba(31, 143, 99, 0.18);
  flex: 0 0 auto;
}

.status-label,
.status-value {
  margin: 0;
}

.status-value {
  margin-top: 4px;
  font-size: 1.08rem;
  font-weight: 700;
}

.layout {
  display: grid;
  gap: 20px;
  margin-top: 22px;
}

.panel {
  border-radius: var(--radius-lg);
  padding: 24px;
}

.panel-header,
.form-head,
.form-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.panel-header {
  align-items: end;
  margin-bottom: 18px;
}

.panel-action-button {
  margin-left: auto;
}

.quarter-nav {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.quarter-select-wrap {
  display: grid;
  gap: 6px;
  min-width: min(280px, 100%);
}

.quarter-select-wrap label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.quarter-select-wrap select {
  width: 100%;
  min-height: 44px;
  padding: 10px 38px 10px 14px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.quarter-nav-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--primary-deep);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}

.quarter-nav-button:disabled {
  background: rgba(30, 38, 39, 0.06);
  border-color: rgba(30, 38, 39, 0.08);
  color: rgba(102, 114, 117, 0.7);
  cursor: default;
}

.panel-meta,
.form-head p,
.chart-header p,
.helper-text {
  margin: 6px 0 0;
  line-height: 1.6;
}

.is-disabled-panel {
  opacity: 0.58;
}

.is-disabled-panel::after {
  content: "総収支ビューでは収支・立替の登録編集はできません。四半期を選ぶと操作できます。";
  display: block;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(15, 118, 110, 0.08);
  color: var(--primary-deep);
  font-size: 0.9rem;
  line-height: 1.5;
}

.totals-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.total-card,
.event-form,
.entry-form,
.history-block {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
}

.event-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.7fr) minmax(110px, 0.45fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 16px;
}

.event-form.is-hidden {
  display: none;
}

.event-form h3 {
  margin: 0;
  font-family: var(--font-display);
}

.total-card {
  padding: 16px;
}

.entry-form,
.history-block {
  padding: 20px;
}

.history-block-compact {
  padding: 12px 14px;
}

.total-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(15, 118, 110, 0.12);
  color: var(--primary-deep);
}

.pill.is-negative {
  background: rgba(177, 60, 89, 0.12);
  color: var(--danger);
}

.total-main {
  margin: 12px 0 0;
  font-size: 1.7rem;
  font-weight: 800;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-row p {
  margin: 0;
}

.chart-panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.chart-header {
  margin-bottom: 12px;
}

.chart-stage {
  min-height: 320px;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(247, 242, 232, 0.8));
}

.chart-canvas {
  width: min(100%, var(--chart-max-width));
  margin: 0 auto;
}

.chart-svg {
  width: 100%;
  height: 280px;
  display: block;
  overflow: visible;
}

.chart-grid {
  stroke: rgba(30, 38, 39, 0.08);
  stroke-width: 1;
}

.chart-axis,
.chart-zero {
  stroke: rgba(30, 38, 39, 0.2);
  stroke-width: 1.2;
}

.chart-zero {
  stroke: rgba(15, 118, 110, 0.25);
}

.chart-axis-label {
  font-size: 11px;
  fill: var(--muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 8px;
  justify-content: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.field,
.field-grid {
  display: grid;
  gap: 8px;
}

.field {
  margin-bottom: 14px;
}

.compact-field {
  margin-bottom: 0;
}

.field-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field span,
.score-field label {
  font-size: 0.9rem;
  font-weight: 700;
}

.score-field label {
  display: block;
  margin-bottom: 6px;
}

.field input,
.field select,
.score-field input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 13px 14px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(30, 38, 39, 0.18);
  background: rgba(255, 255, 255, 0.92);
  scroll-margin-block: 92px;
}

#advanceMonth {
  inline-size: 100%;
  text-align: left;
}

.form-head {
  align-items: start;
  margin-bottom: 18px;
}

.form-head-actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-footer {
  align-items: center;
  margin-top: 18px;
}

.edit-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(15, 118, 110, 0.1);
  color: var(--primary-deep);
  font-size: 0.9rem;
  font-weight: 700;
}

.tab-strip {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
}

.tab-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tab-button.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.18);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.is-hidden {
  display: none !important;
}

.validation-dialog {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + var(--keyboard-inset));
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  width: min(460px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid rgba(177, 60, 89, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 250, 248, 0.96);
  box-shadow: 0 18px 48px rgba(41, 49, 53, 0.18);
  color: var(--ink);
}

.validation-dialog.is-error {
  border-color: rgba(177, 60, 89, 0.18);
  background: rgba(255, 250, 248, 0.96);
}

.validation-dialog.is-success {
  border-color: rgba(31, 143, 99, 0.2);
  background: rgba(247, 255, 250, 0.96);
}

.validation-dialog-kicker,
.validation-dialog-title,
.validation-dialog-message {
  margin: 0;
}

.validation-dialog-kicker {
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.validation-dialog.is-error .validation-dialog-kicker,
.validation-dialog.is-error .validation-dialog-close {
  color: var(--danger);
}

.validation-dialog.is-success .validation-dialog-kicker,
.validation-dialog.is-success .validation-dialog-close {
  color: var(--success);
}

.validation-dialog-title {
  margin-top: 4px;
  font-weight: 800;
}

.validation-dialog-message {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.55;
}

.validation-dialog-close {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.primary-button,
.ghost-button,
.table-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.2);
}

.ghost-button {
  border-color: rgba(15, 118, 110, 0.18);
  background: rgba(255, 255, 255, 0.78);
  color: var(--primary-deep);
}

.table-button {
  min-height: 34px;
  padding: 0 12px;
  border-color: rgba(15, 118, 110, 0.18);
  background: rgba(255, 255, 255, 0.82);
  color: var(--primary-deep);
}

.table-button.danger {
  border-color: rgba(177, 60, 89, 0.18);
  color: var(--danger);
}

.primary-button:hover,
.ghost-button:hover,
.table-button:hover {
  transform: translateY(-1px);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(30, 38, 39, 0.08);
  text-align: left;
  white-space: nowrap;
}

thead th {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  padding: 16px 0;
}

.is-negative {
  color: var(--danger);
}

.is-positive {
  color: var(--primary);
}

@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .totals-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-header,
  .form-head,
  .form-footer {
    flex-direction: column;
    align-items: start;
  }

  .panel-action-button {
    margin-left: 0;
  }

  .quarter-nav {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(calc(var(--viewport-width) - 16px), 100%);
    padding-top: max(14px, env(safe-area-inset-top));
    padding-bottom: calc(max(28px, env(safe-area-inset-bottom)) + var(--keyboard-inset));
  }

  .hero-copy,
  .hero-status,
  .panel {
    padding: 16px;
  }

  .hero-copy h1 {
    font-size: 1.5rem;
    line-height: 1.14;
  }

  .hero-status {
    align-items: flex-start;
  }

  .panel {
    padding: 18px 16px;
  }

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

  .total-card {
    padding: 14px;
  }

  .total-main {
    font-size: 1.4rem;
  }

  .metric-row {
    font-size: 0.82rem;
  }

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

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

  .field input,
  .field select,
  .score-field input {
    min-height: 48px;
    font-size: 16px;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .tab-strip {
    display: grid;
    width: 100%;
  }

  .form-head-actions,
  .form-footer {
    width: 100%;
  }

  .form-footer {
    align-items: stretch;
  }

  .chart-panel {
    padding: 14px 10px 12px;
  }

  .chart-stage {
    min-height: 236px;
  }

  .chart-canvas {
    width: min(100%, var(--chart-max-width));
  }

  .chart-svg {
    height: 220px;
  }

  .history-block,
  .history-block-compact {
    padding: 10px 0 0;
    border: 0;
    background: transparent;
  }

  table {
    min-width: 100%;
    font-size: 0.84rem;
  }

  th,
  td {
    padding: 9px 8px;
    white-space: nowrap;
  }

  .row-actions {
    flex-wrap: nowrap;
  }

  .row-actions .table-button {
    min-height: 30px;
    padding: 0 10px;
  }

  .validation-dialog {
    left: 16px;
    right: 16px;
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + var(--keyboard-inset));
    width: auto;
    grid-template-columns: 1fr;
  }

  .validation-dialog-close {
    justify-self: stretch;
  }
}
