:root {
  color-scheme: light;
  --ink: #17232f;
  --muted: #5d6975;
  --line: #cfd8e0;
  --soft: #eef4f7;
  --panel: #ffffff;
  --blue: #123d5a;
  --blue-2: #1f5f85;
  --yellow: #ffd228;
  --green: #16715f;
  --red: #9b2f2f;
  --shadow: 0 12px 32px rgba(18, 61, 90, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #dfe8ed;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--blue);
  color: #fff;
  padding: 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 84px;
  height: 54px;
  background: var(--yellow);
  color: #15466b;
  font-weight: 800;
  font-size: 28px;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.05;
}

.topbar p {
  margin-top: 6px;
  color: #d8e7ef;
  line-height: 1.35;
}

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

.summary-strip div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.summary-strip strong,
.summary-strip span {
  display: block;
}

.summary-strip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.calculator {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.panel-heading h2 {
  font-size: 19px;
  line-height: 1.15;
}

.panel-heading span {
  color: var(--muted);
  font-size: 14px;
}

.ghost-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafc;
  color: var(--ink);
  font-weight: 700;
  padding: 8px 12px;
}

.primary-button {
  min-height: 40px;
  border: 1px solid var(--green);
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-weight: 800;
  padding: 8px 12px;
}

.danger-button {
  color: var(--red);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.install-button {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 6px;
  background: #ffffff;
  color: var(--blue);
  font: inherit;
  font-weight: 800;
  padding: 8px 14px;
}

.grid {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #b6c4cf;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  padding: 9px 10px;
  touch-action: manipulation;
}

input:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(31, 95, 133, 0.24);
  outline-offset: 2px;
}

.section-label {
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--blue);
  font-weight: 800;
}

.result-card {
  border: 2px solid var(--blue);
  border-radius: 8px;
  overflow: hidden;
}

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

.result-grid div {
  padding: 14px;
  background: var(--soft);
  border-right: 1px solid var(--line);
}

.result-grid div:last-child {
  border-right: 0;
}

.result-grid span,
.detail-list dt {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.result-grid strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: clamp(24px, 5vw, 34px);
  line-height: 1;
}

.result-grid .primary-result {
  background: #e7f4f0;
}

.result-grid .primary-result strong {
  color: var(--green);
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--line);
}

.detail-list div {
  padding: 11px 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.detail-list div:nth-child(2n) {
  border-right: 0;
}

.detail-list dd {
  margin: 5px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.formula-box {
  display: grid;
  gap: 6px;
  padding: 13px 14px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
  color: #33414d;
  font-size: 13px;
  line-height: 1.35;
}

.status-message {
  min-height: 42px;
  padding: 12px 14px;
  color: var(--muted);
  line-height: 1.35;
}

.status-message.warning {
  color: var(--red);
  font-weight: 700;
}

.table-panel {
  margin-top: 14px;
}

.saved-panel {
  margin-top: 14px;
}

.save-status {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.save-status.warning {
  color: var(--red);
  font-weight: 700;
}

.save-status.success {
  color: var(--green);
  font-weight: 700;
}

.saved-records {
  display: grid;
  gap: 8px;
}

.empty-records {
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: 12px;
}

.record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfd;
}

.record-card strong,
.record-card span {
  display: block;
}

.record-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.record-card button {
  min-height: 36px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  text-align: center;
}

th {
  background: var(--blue);
  color: #fff;
}

tbody th {
  background: #e6eef3;
  color: var(--ink);
}

td.active-cell {
  background: #e7f4f0;
  color: var(--green);
  font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--green);
}

@media (max-width: 900px) {
  .calculator,
  .grid.two,
  .grid.three,
  .result-grid,
  .detail-list,
  .record-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .install-button {
    width: 100%;
  }

  .button-row {
    width: 100%;
    justify-content: stretch;
  }

  .button-row button {
    flex: 1 1 auto;
  }

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

  .result-grid div,
  .detail-list div {
    border-right: 0;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    padding: 0;
  }

  .ghost-button,
  .inputs-panel,
  .table-panel,
  .saved-panel {
    display: none;
  }

  .calculator {
    display: block;
  }

  .panel {
    box-shadow: none;
  }
}
