:root {
  --bg: #f4efe7;
  --panel: #ffffff;
  --panel-soft: #fbf8f3;
  --ink: #172238;
  --muted: #657184;
  --line: #ddd2c1;
  --accent: #b98336;
  --accent-strong: #79501d;
  --focus: #4f93d8;
  --danger: #a33d3d;
  --warning: #8a641d;
  --success: #306b4f;
  --shadow: 0 18px 48px rgba(63, 49, 31, 0.12);
  --radius: 8px;
  --container: 1180px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(20, 31, 51, 0.96) 0, rgba(20, 31, 51, 0.9) 260px, var(--bg) 260px),
    var(--bg);
  font-family: Manrope, "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
}

a {
  color: var(--accent-strong);
}

button,
input,
select {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0.68rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #3b4658;
  background: #f8f3ec;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.container {
  width: min(calc(100% - 2rem), var(--container));
  margin: 0 auto;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-shell {
  width: min(100%, 720px);
}

.auth-panel,
.calculator-form,
.result-section,
.alert {
  border: 1px solid rgba(146, 112, 68, 0.22);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: clamp(1.4rem, 4vw, 2.4rem);
}

.eyebrow {
  margin-bottom: 0.55rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lead {
  margin-top: 0.8rem;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 0.85rem;
  margin-top: 1.4rem;
}

.bct-card {
  display: grid;
  gap: 0.85rem;
  margin-top: 1.2rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.bct-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.bct-actions,
.bct-update-form,
.header-button-group {
  display: flex;
  align-items: end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.compact-field {
  min-width: min(100%, 220px);
}

.small-line {
  margin-top: 0.25rem;
  font-size: 0.86rem;
}

.bct-source-panel {
  display: grid;
  gap: 0.85rem;
}

.bct-file-panel {
  padding: 0.85rem;
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: #fffaf2;
}

.bct-steps {
  display: grid;
  gap: 0.75rem;
}

.bct-step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.85rem;
  align-items: start;
  padding: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.bct-step-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: #344055;
  font-weight: 900;
}

.bct-step h3 {
  margin-bottom: 0.2rem;
}

.bct-step p {
  color: var(--muted);
}

.bct-step-status {
  min-width: 92px;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  text-align: center;
  font-size: 0.82rem;
}

.bct-step[data-state="run"] {
  border-color: rgba(79, 147, 216, 0.5);
  background: #f0f7ff;
}

.bct-step[data-state="ok"] {
  border-color: rgba(48, 107, 79, 0.36);
  background: #f0fbf6;
}

.bct-step[data-state="error"] {
  border-color: rgba(163, 61, 61, 0.36);
  background: #fff5f5;
}

.bct-step[data-state="run"] .bct-step-status {
  color: #2e5b85;
  border-color: rgba(79, 147, 216, 0.36);
}

.bct-step[data-state="ok"] .bct-step-status {
  color: var(--success);
  border-color: rgba(48, 107, 79, 0.36);
}

.bct-step[data-state="error"] .bct-step-status {
  color: var(--danger);
  border-color: rgba(163, 61, 61, 0.36);
}

.bct-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.68rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: inherit;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.button-primary {
  color: #fff;
  background: linear-gradient(135deg, #24314d, #a87934);
}

.button-secondary {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.icon-action {
  width: 44px;
  min-width: 44px;
  padding: 0;
}

.icon-action svg {
  width: 22px;
  height: 22px;
  display: block;
}

.tool-header {
  color: #fff;
  padding: 2rem 0 1.25rem;
}

.tool-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.tool-header .eyebrow {
  color: #e8c58f;
}

.tool-header h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  letter-spacing: -0.03em;
}

.tool-main {
  display: grid;
  gap: 1rem;
  padding: 1rem 0 3rem;
}

.calculator-form,
.result-section {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 2vw, 1.35rem);
}

.form-section {
  display: grid;
  gap: 1rem;
}

.section-title {
  display: grid;
  gap: 0.25rem;
}

.section-title p,
.source-line,
.legal-note {
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  color: #344055;
  font-weight: 700;
}

.radio-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0;
  border: 0;
}

.radio-group legend {
  width: 100%;
  margin-bottom: 0.4rem;
  color: #344055;
  font-weight: 800;
}

.radio-group label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
  font-weight: 800;
}

.radio-group input {
  width: auto;
  min-height: auto;
}

.payments-list {
  display: grid;
  gap: 0.75rem;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  width: fit-content;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
  color: #344055;
  font-weight: 800;
}

.toggle-row input {
  width: auto;
  min-height: auto;
}

.payments-panel {
  display: grid;
  gap: 1rem;
}

[hidden] {
  display: none !important;
}

.payment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: end;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.payment-actions {
  display: flex;
  gap: 0.4rem;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 900;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.form-actions,
.export-actions,
.result-heading,
.result-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.result-tools {
  justify-content: flex-end;
}

.result-view-toggle {
  margin-right: 0.25rem;
}

.alert {
  padding: 0.85rem 1rem;
  box-shadow: none;
}

.alert + .alert {
  margin-top: 0.5rem;
}

.alert-error {
  color: var(--danger);
  background: #fff5f5;
  border-color: rgba(163, 61, 61, 0.28);
}

.alert-warning {
  color: var(--warning);
  background: #fff8e7;
  border-color: rgba(138, 100, 29, 0.28);
}

.alert-info {
  color: #2e5b85;
  background: #f0f7ff;
  border-color: rgba(79, 147, 216, 0.28);
}

.alert-success {
  color: var(--success);
  background: #f0fbf6;
  border-color: rgba(48, 107, 79, 0.28);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.summary-item,
.print-summary > div {
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.summary-item span,
.print-summary span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.summary-item strong,
.print-summary strong {
  font-size: 1rem;
}

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

.table-wrap table th,
.table-wrap table td {
  white-space: nowrap;
}

.result-section h3 {
  margin-top: 0.4rem;
}

.legal-note {
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.print-page {
  background: #fff;
}

.print-document {
  width: min(calc(100% - 2rem), 1040px);
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.print-document section,
.print-header,
.print-footer,
.totals-block {
  margin-top: 1.2rem;
}

.print-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.print-header {
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
}

.totals-block {
  display: grid;
  justify-content: end;
  gap: 0.35rem;
}

.totals-block p {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  min-width: 280px;
}

.print-footer {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 920px) {
  .field-grid,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .container {
    width: min(calc(100% - 1rem), var(--container));
  }

  .tool-header-inner,
  .payment-row,
  .field-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .tool-header-inner,
  .payment-row {
    display: grid;
  }

  .radio-group {
    align-items: stretch;
    flex-direction: column;
  }

  .radio-group label,
  .button:not(.icon-action),
  .toggle-row {
    width: 100%;
  }

  .bct-grid,
  .bct-actions,
  .bct-update-form,
  .header-button-group,
  .bct-preview {
    display: grid;
    grid-template-columns: 1fr;
  }

  .bct-step {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .bct-step-status {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .payment-actions,
  .export-actions,
  .result-tools {
    justify-content: flex-end;
  }

  .result-tools {
    width: 100%;
  }
}

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

  .print-actions {
    display: none;
  }

  .print-document {
    width: 100%;
    padding: 0;
  }

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

  a {
    color: #000;
    text-decoration: none;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
  }
}
