:root {
  color-scheme: light;
  --ink: #18201f;
  --muted: #5c6664;
  --paper: #f7f8fa;
  --panel: #ffffff;
  --line: #dce3e1;
  --line-strong: #c5cfcc;
  --primary: #0f7b6c;
  --primary-dark: #0a4f46;
  --gold: #b98119;
  --gold-soft: #fff3d8;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --success-soft: #e8f7f1;
  --shadow: 0 12px 32px rgba(31, 38, 36, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 14px;
}

.app-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgba(15, 123, 108, 0.2);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--primary-dark);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 7vw, 2.35rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.04rem;
  line-height: 1.2;
}

.app-main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.panel {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 1px 1px rgba(24, 32, 31, 0.03);
}

.input-panel,
.actual-panel,
.explain-panel,
.table-panel {
  padding: 16px;
}

.summary-panel {
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 5;
  padding: 15px;
  border-color: rgba(15, 123, 108, 0.28);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.table-heading,
.summary-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section-heading {
  display: grid;
  gap: 2px;
}

.table-heading {
  margin-bottom: 12px;
}

.input-stack {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 750;
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.money-input {
  display: flex;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  color: var(--muted);
  overflow: hidden;
}

.money-input span {
  display: grid;
  width: 46px;
  height: 100%;
  min-height: 58px;
  place-items: center;
  border-right: 1px solid var(--line);
  color: var(--primary-dark);
  font-size: 1.12rem;
  font-weight: 850;
}

.money-input input {
  width: 100%;
  min-width: 0;
  min-height: 58px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.26rem;
  font-weight: 760;
  padding: 0 14px;
}

.money-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 123, 108, 0.12);
}

.input-message {
  min-height: 22px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.input-message.warning {
  color: var(--danger);
  font-weight: 700;
}

.standard-badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.standard-badge {
  background: var(--gold-soft);
  color: #7a4c08;
}

.status-pill {
  background: #eef2f1;
  color: var(--muted);
}

.status-pill.above {
  background: var(--success-soft);
  color: var(--primary-dark);
}

.status-pill.below {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.equal {
  background: var(--gold-soft);
  color: #7a4c08;
}

.hero-metric {
  display: grid;
  gap: 5px;
  padding: 16px 0 13px;
}

.hero-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.hero-metric strong {
  color: var(--primary-dark);
  font-size: clamp(2rem, 12vw, 3.4rem);
  line-height: 0.98;
  overflow-wrap: anywhere;
}

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

.metric-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfd;
}

.metric-grid dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  line-height: 1.2;
}

.metric-grid dd {
  margin-top: 6px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric-grid dd.positive {
  color: var(--primary-dark);
}

.metric-grid dd.negative {
  color: var(--danger);
}

.formula-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.formula-list p {
  border-left: 3px solid var(--primary);
  padding: 9px 10px;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: #f4f8f7;
  color: var(--muted);
  font-size: 0.92rem;
}

.formula-list strong {
  color: var(--ink);
}

.table-note {
  max-width: 140px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: right;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

.price-table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
  background: #ffffff;
  font-size: 0.88rem;
}

.price-table th,
.price-table td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: right;
  white-space: nowrap;
}

.price-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3f2;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.price-table th:first-child,
.price-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
}

.price-table th:first-child {
  z-index: 3;
  background: #e6edeb;
}

.price-table td:first-child {
  background: #ffffff;
  font-weight: 850;
}

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

.price-table tr.standard-row td {
  background: var(--gold-soft);
  color: #4b3206;
  font-weight: 850;
}

.price-table tr.standard-row td:first-child {
  background: #ffe9b4;
}

.price-table td.positive {
  color: var(--primary-dark);
}

.price-table td.negative {
  color: var(--danger);
}

.empty-row {
  height: 74px;
  color: var(--muted);
  text-align: center !important;
}

@media (min-width: 760px) {
  .app-shell {
    padding: 28px 24px 40px;
  }

  .app-main {
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
  }

  .summary-panel {
    top: 18px;
  }

  .table-panel,
  .explain-panel {
    grid-column: 1 / -1;
  }

  .actual-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}
