* {
  box-sizing: border-box;
}

:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  color: #172033;
  background: #f4f6f9;
  line-height: 1.5;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px max(18px, env(safe-area-inset-right)) 20px max(18px, env(safe-area-inset-left));
  background: #1f4b99;
  color: white;
}

.app-header h1 {
  margin: 0;
  font-size: 1.65rem;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.78;
}

.container {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.card {
  margin-bottom: 18px;
  padding: 20px;
  border-radius: 16px;
  background: white;
  box-shadow: 0 5px 20px rgba(23, 32, 51, 0.08);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

.rule-card {
  border-left: 6px solid #1f4b99;
}

.rule-grid,
.summary-grid,
.form-grid {
  display: grid;
  gap: 12px;
}

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

.rule-grid div {
  padding: 12px;
  border-radius: 12px;
  background: #f4f7fc;
}

.rule-grid span,
.summary-box span {
  display: block;
  color: #647089;
  font-size: 0.82rem;
}

.rule-grid strong {
  display: block;
  margin-top: 3px;
}

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

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: #33415c;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #cbd3df;
  border-radius: 10px;
  background: white;
  color: #172033;
}

input:focus {
  outline: 3px solid rgba(31, 75, 153, 0.17);
  border-color: #1f4b99;
}

.button-row,
.table-actions,
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button-row {
  margin-top: 16px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
}

.month-picker {
  min-width: 170px;
}

.primary-button,
.secondary-button,
.danger-button,
.small-button {
  border: 0;
  border-radius: 10px;
  font-weight: 700;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  padding: 10px 16px;
}

.primary-button {
  background: #1f4b99;
  color: white;
}

.secondary-button {
  background: #e8eef8;
  color: #1f4b99;
}

.danger-button {
  background: #fff0f0;
  color: #a52a2a;
}

.small-button {
  padding: 6px 9px;
  white-space: nowrap;
}

.edit-button {
  background: #e8eef8;
  color: #1f4b99;
}

.delete-button {
  background: #fff0f0;
  color: #a52a2a;
}

.summary-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 14px;
}

.summary-box {
  padding: 14px;
  border-radius: 12px;
  background: #f4f7fc;
}

.summary-box strong {
  display: block;
  margin-top: 4px;
  font-size: 1.22rem;
}

.total-box {
  background: #eaf7ee;
}

.total-box strong {
  color: #146c36;
}

.table-actions {
  justify-content: flex-end;
  margin: 10px 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e1e5ec;
  border-radius: 12px;
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid #e8ebf0;
  text-align: right;
  white-space: nowrap;
}

th {
  background: #f7f9fc;
  color: #45526b;
  font-size: 0.82rem;
}

th:first-child,
td:first-child {
  text-align: left;
}

tr:last-child td {
  border-bottom: 0;
}

.action-cell {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.note {
  margin: 14px 0 0;
  color: #667085;
  font-size: 0.9rem;
}

.error-message {
  min-height: 24px;
  margin-top: 8px;
  color: #b42318;
  font-weight: 700;
}

.empty-state {
  padding: 26px 12px;
  text-align: center;
  color: #718096;
}

.formula-list {
  padding: 2px 0;
}

.formula-list p {
  margin: 8px 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .container {
    padding: 12px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

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

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

  .total-box {
    grid-column: 1 / -1;
  }

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

  .table-actions {
    justify-content: stretch;
  }

  .table-actions button {
    flex: 1;
  }
}

@media (max-width: 440px) {
  .app-header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }

  .app-header h1 {
    font-size: 1.35rem;
  }

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

  .button-row {
    display: grid;
  }

  .button-row button {
    width: 100%;
  }
}
