:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f6f2;
  color: #172a23;
  --ink: #172a23;
  --muted: #52625a;
  --green: #1c533e;
  --green-dark: #123b2e;
  --line: #d9e2da;
  --error: #963425;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
h1, h2, p, dl, dd { margin: 0; }
:focus-visible { outline: 2px solid #327556; outline-offset: 3px; }

.app {
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  min-height: 100vh;
  min-height: 100svh;
  margin-inline: auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.topbar, .summary-heading, .products-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar { margin-bottom: 16px; }
h1 { font-size: clamp(1.125rem, 5vw, 1.5rem); font-weight: 750; }
.button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 650;
}

.settings-button {
  min-height: 44px;
  padding: 0 12px;
  border-color: var(--line);
  background: #fff;
  color: var(--green);
  font-size: 0.875rem;
  white-space: nowrap;
}

.summary {
  padding: 19px 20px 17px;
  border-radius: 20px;
  background: var(--green-dark);
  color: #fff;
}

.summary h2 { font-size: 0.9375rem; font-weight: 600; color: #dfede4; }
.rate {
  padding: 6px 10px;
  border-radius: 20px;
  background: #d9f0dd;
  color: var(--green-dark);
  font-size: 0.875rem;
  font-weight: 700;
  white-space: nowrap;
}

.payable {
  margin: 8px 0 16px;
  font-size: clamp(2.625rem, 11vw, 3.5rem);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.payable, dd, .price-input, .discounted-price, .product-number { font-variant-numeric: tabular-nums; }
.totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 13px;
  border-top: 1px solid #507163;
}

.totals > div + div { padding-left: 14px; border-left: 1px solid #507163; }
.totals dt { color: #dfede4; font-size: 0.875rem; }
.totals dd { margin-top: 4px; font-size: 1.125rem; font-weight: 700; overflow-wrap: anywhere; }

.products {
  margin-top: 16px;
  padding: 15px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

.products-heading { padding: 0 3px; margin-bottom: 15px; }
.products h2, dialog h2 { font-size: 1.125rem; font-weight: 750; }
#product-count { color: var(--muted); font-size: 0.875rem; }
.column-headings, .product-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) minmax(57px, 0.75fr) 44px;
  align-items: center;
  gap: 8px;
}

.column-headings { padding-bottom: 7px; color: var(--muted); font-size: 0.875rem; white-space: nowrap; }
.column-headings :nth-child(3) { text-align: right; }
.product-list { list-style: none; margin: 0; padding: 0; }
.product + .product { margin-top: 8px; }
.product-number { color: var(--muted); text-align: center; font-size: 0.875rem; }
.price-input, .discount-fields input, #quote-text {
  min-width: 0;
  min-height: 48px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #bdcec0;
  border-radius: 10px;
  background: #f7f9f6;
  font-size: 1.125rem;
}

.price-input::placeholder { color: #65766b; }
.price-input:focus, .discount-fields input:focus, #quote-text:focus {
  outline: 2px solid var(--green);
  outline-offset: -1px;
  background: #fff;
}

input[aria-invalid="true"] { border-color: var(--error); background: #fff6f2; }
.discounted-price {
  text-align: right;
  color: var(--green-dark);
  font-size: 1rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.remove-button {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #56685e;
}

.remove-button:disabled { opacity: 0.4; }
.add-button {
  width: 100%;
  min-height: 51px;
  margin-top: 12px;
  border-color: #c5d9cc;
  background: #edf5ee;
  color: var(--green);
}

.add-button span { font-size: 1.2em; }
.actions { margin-top: auto; padding-top: 16px; }
.action-row, .dialog-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.action-row .button { min-height: 53px; }
.primary-button { background: var(--green); color: #fff; }
.primary-button:disabled { background: #dce6de; color: #596960; }
.clear-button { border-color: #cbd8ce; background: #fff; color: var(--green); }
.clear-button:disabled { background: #f5f6f2; color: #637168; }
.status, .offline-status { color: var(--muted); font-size: 0.875rem; text-align: center; }
.status:not(:empty), .offline-status { margin-top: 8px; }
.field-error { color: var(--error); margin-top: 6px; font-size: 0.875rem; }
.price-error { padding-left: 38px; }

dialog {
  width: min(calc(100% - 32px), 430px);
  max-height: calc(100% - 32px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
}

dialog::backdrop { background: rgb(18 35 27 / 46%); }
dialog h2:focus { outline: none; }
.dialog-note { margin: 8px 0 16px; color: var(--muted); font-size: 0.875rem; line-height: 1.5; }
.discount-fields { display: grid; gap: 8px; }
.discount-fields label { display: grid; align-items: center; grid-template-columns: 1fr 88px auto; gap: 10px; }
.discount-fields input { text-align: right; }
.dialog-actions { margin-top: 16px; grid-template-columns: 1fr 1fr; }
#quote-text { font-size: 1rem; resize: vertical; }
.close-quote { width: 100%; margin-top: 12px; }

@media (hover: hover) {
  .settings-button:hover, .clear-button:enabled:hover { background: #edf5ee; }
  .add-button:hover, .remove-button:enabled:hover { background: #e0eee3; }
  .primary-button:enabled:hover { background: var(--green-dark); }
}
