:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1b2721;
  background: #f4f5ef;
  font-synthesis: none;
  line-height: 1.45;
  --ink: #1b2721;
  --forest: #204b3b;
  --deep: #15382d;
  --line: #d6dfd6;
  --muted: #4d6257;
  --paper: #fff;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; min-width: 0; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid #347f60; outline-offset: 3px; }

.shell { width: min(100% - 3rem, 1120px); margin-inline: auto; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--deep); font-weight: 750; }
.brand-mark {
  display: inline-grid; place-items: center; width: 33px; height: 33px;
  border-radius: 9px; background: var(--forest); color: #fff; font-weight: 750;
}
.nav { display: flex; gap: .25rem; }
.nav a { text-decoration: none; color: var(--muted); padding: .55rem .85rem; border-radius: 8px; font-weight: 650; }
.nav a:hover, .nav a[aria-current] { color: var(--deep); background: #e8f0e7; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-block: 2.65rem 1.5rem; }
h1, h2, p, dl, dd { margin: 0; }
h1 { font-size: clamp(1.85rem, 4.7vw, 3rem); line-height: 1.1; letter-spacing: -.045em; font-weight: 760; }
h1:focus { outline: none; }
h2 { font-size: 1.03rem; font-weight: 740; letter-spacing: -.012em; }
.button {
  display: inline-flex; justify-content: center; align-items: center; min-height: 44px; padding: .57rem .95rem;
  text-align: center; font-weight: 680; border: 1px solid transparent; border-radius: 8px;
}
.secondary { color: var(--deep); background: var(--paper); border-color: #c9d7cd; }
.secondary:hover { background: #eef4ee; }
.primary { color: #fff; background: var(--forest); }
.primary:hover { background: var(--deep); }
.plain { color: var(--forest); background: transparent; }
.plain:hover { background: #e8f0e8; }

.calculator-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.75fr); gap: 1.2rem; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.sale-form, .detail, .settings-panel { padding: 1.25rem; }
.sale-form > label, .parameters-grid div > label:not(.check-label), .rule-fields > label:not(.check-label) {
  display: block; color: var(--ink); font-size: .91rem; font-weight: 670;
}
.sale-form > label, .parameters-grid div > label:not(.check-label) { margin: 1rem 0 .36rem; }
input:not([type="checkbox"]):not([type="file"]), select {
  width: 100%; min-height: 45px; min-width: 0; border: 1px solid #b8c9bc; border-radius: 8px;
  padding: .55rem .7rem; background: #fff; color: var(--ink); font-size: 1rem;
}
input::placeholder { color: #66776e; opacity: 1; }
input[aria-invalid="true"] { border-color: #9d3029 !important; }
.money-input { position: relative; }
.money-input input { padding-inline-end: 2.25rem !important; }
.money-input span { position: absolute; right: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.form-separator { height: 1px; background: var(--line); margin: 1.35rem 0 1.15rem; }
.field-error, .error { color: #8b2a21; }
.field-error { margin-top: .35rem; font-size: .86rem; }

.results { display: grid; gap: .9rem; min-width: 0; }
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.result-card { padding: 1.15rem 1.2rem; border-radius: 14px; }
.result-primary { color: #fff; background: var(--forest); border: 1px solid var(--forest); }
.result-card h2 { font-size: .88rem; color: var(--muted); }
.result-primary h2, .result-primary p { color: #e4f0e8; }
.result-card output {
  display: block; font-size: clamp(1.7rem, 3.4vw, 2.45rem); line-height: 1.15; letter-spacing: -.045em;
  font-weight: 760; margin-top: .5rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}
.result-card p { margin-top: .42rem; font-size: .83rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; margin-top: .4rem; }
.detail h2 { margin-bottom: .65rem; }
.detail table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; table-layout: fixed; }
.detail th, .detail td { padding: .6rem .35rem; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.detail th[scope="col"] { color: var(--muted); font-size: .78rem; }
.detail th:not(:first-child), .detail td { width: 25%; text-align: right; }
.detail tbody tr { border-top: 1px solid #e3e9e3; }
.detail tbody th { font-weight: 590; }
.breakdown { font-size: .93rem; }
.breakdown > div { display: flex; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-top: 1px solid #e3e9e3; }
.breakdown dd { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-width: 0; }
.detail-note { margin-top: .6rem; font-size: .85rem; }
.notice { padding: .72rem .85rem; border-radius: 8px; color: #28473a; background: #e8f0e8; }
.notice.error { color: #783127; background: #fbede8; }
.notice a { font-weight: 700; }

.settings-panel + .settings-panel { margin-top: 1rem; }
.parameters-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 1rem 2rem; align-items: start; }
.personal-setting { margin-top: 1rem; }
.check-label { display: flex; align-items: center; gap: .5rem; min-height: 38px; font-size: .9rem; font-weight: 650; }
.check-label input { width: 1.15rem; height: 1.15rem; margin: 0; flex: none; accent-color: var(--forest); }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .5rem; }
#rules { display: grid; gap: .7rem; }
.rule { min-inline-size: 0; margin: 0; padding: .7rem .8rem .85rem; border: 1px solid #dce5dd; border-radius: 9px; }
.rule legend { padding-inline: .35rem; color: var(--muted); font-size: .82rem; font-weight: 650; }
.rule-fields {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(4.4rem, .55fr) minmax(8rem, 1.35fr) minmax(8.8rem, 1.2fr) auto;
  align-items: end; gap: .55rem .8rem;
}
.rule-fields label > input:not([type="checkbox"]), .rule-fields label > select { margin-top: .28rem; }
.rule-markup, .remove-rule { min-height: 45px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-block: 1rem .65rem; }
.file-button { position: relative; cursor: pointer; }
.file-button:focus-within { outline: 3px solid #347f60; outline-offset: 3px; }
.file-button input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.footer { margin-block: 1.4rem 2.2rem; color: var(--muted); font-size: .82rem; }

@media (max-width: 845px) {
  .rule-fields { grid-template-columns: minmax(0, 1.3fr) minmax(4rem, .65fr) minmax(0, 1.45fr); }
  .rule-fields .remove-rule { justify-self: end; grid-column: 3; }
  .rule-markup { grid-column: 1 / 3; }
}
@media (max-width: 720px) {
  .calculator-layout { grid-template-columns: minmax(0, 1fr); }
  .page-header { padding-block: 1.7rem 1.25rem; }
}
@media (max-width: 460px) {
  .shell { width: calc(100% - 1.5rem); }
  .topbar-inner { min-height: 57px; }
  .brand { gap: .4rem; font-size: .91rem; }
  .nav a { padding-inline: .48rem; font-size: .89rem; }
  .page-header { flex-wrap: wrap; gap: .65rem; }
  .summary { gap: .55rem; }
  .result-card { padding: .85rem .72rem; }
  .result-card h2 { font-size: .78rem; }
  .result-card output { font-size: 1.55rem; }
  .result-card p { font-size: .77rem; }
  .panel { padding: .9rem; }
  .detail th, .detail td { font-size: .83rem; }
  .detail th[scope="col"] { font-size: .71rem; }
  .parameters-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .settings-heading { align-items: flex-start; flex-wrap: wrap; }
  .rule-fields { grid-template-columns: minmax(0, .62fr) minmax(0, 1.38fr); }
  .rule-name { grid-column: 1 / -1; }
  .rule-markup { grid-column: 1 / -1; }
  .rule-fields .remove-rule { grid-column: 2; }
}
