:root {
  color-scheme: light;
  --ink: #1d2246;
  --muted: #646b85;
  --brand: #303078;
  --brand-2: #5959a8;
  --surface: #ffffff;
  --soft: #f4f5fb;
  --line: #dfe2ef;
  --danger: #a12b36;
  --danger-soft: #fff1f2;
  --success: #13745b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  background: transparent;
}

body {
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button, input, select { font: inherit; }

.widget-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
  background: var(--surface);
}

.widget-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 2.3vw, 28px);
  line-height: 1.15;
}

.intro {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.formula-key {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 6px;
  flex: 0 0 auto;
}

.formula-key span {
  padding: 7px 9px;
  color: var(--brand);
  background: #ededfa;
  border: 1px solid #d6d6f1;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.rows { display: grid; gap: 12px; }

.equipment-row {
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(31, 38, 85, .06);
}

.equipment-row.invalid {
  border-color: #e2aab0;
  border-left-color: var(--danger);
  background: linear-gradient(90deg, var(--danger-soft), #fff 20%);
}

.row-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.row-number {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.remove-button {
  padding: 5px 9px;
  color: var(--danger);
  background: transparent;
  border: 1px solid #ebc9cd;
  border-radius: 7px;
  cursor: pointer;
}

.remove-button:hover { background: var(--danger-soft); }
.remove-button:disabled { opacity: .35; cursor: not-allowed; }

.identity-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, .28fr);
  gap: 10px;
  margin-bottom: 10px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, 1fr)) repeat(3, minmax(105px, 1fr));
  gap: 8px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
}

.field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.field input,
.field select,
.field output {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  align-items: center;
  padding: 9px 10px;
  color: var(--ink);
  background: #fafbfe;
  border: 1px solid #ccd1e3;
  border-radius: 8px;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(48, 48, 120, .13);
}

.field input[readonly] {
  color: var(--brand);
  background: #f0f0fa;
  font-weight: 700;
}

.field.computed output {
  color: var(--brand);
  background: #ededfa;
  border-color: #d6d6f1;
  font-weight: 800;
}

.field.money output { color: var(--success); }

.row-error {
  min-height: 0;
  margin: 9px 0 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
}

.row-error:empty { display: none; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 0;
}

.add-button {
  min-height: 42px;
  padding: 10px 16px;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 9px;
  font-weight: 750;
  cursor: pointer;
}

.add-button:hover { background: #24245f; }
.add-button:disabled { opacity: .5; cursor: not-allowed; }

.row-counter { margin: 0; color: var(--muted); font-size: 12px; }

.total-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
  color: #fff;
  background: linear-gradient(120deg, #24245f, var(--brand), var(--brand-2));
  border-radius: 12px;
}

.total-label { display: block; font-size: 14px; font-weight: 800; }
.total-card small { display: block; margin-top: 3px; color: #e1e1f5; }
.grand-total { font-size: clamp(22px, 3vw, 32px); font-weight: 850; white-space: nowrap; }

.global-errors {
  margin-bottom: 12px;
  padding: 11px 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #ebc9cd;
  border-radius: 8px;
  font-weight: 650;
}

@media (max-width: 900px) {
  .widget-header { display: block; }
  .formula-key { grid-template-columns: repeat(3, max-content); margin-top: 12px; }
  .metrics-grid { grid-template-columns: repeat(4, minmax(100px, 1fr)); }
  .metrics-grid .money { grid-column: span 2; }
}

@media (max-width: 620px) {
  .widget-shell { padding: 10px; }
  .formula-key { grid-template-columns: 1fr; }
  .formula-key span { width: max-content; }
  .identity-grid { grid-template-columns: 1fr 110px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics-grid .money { grid-column: span 2; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .add-button { width: 100%; }
  .total-card { align-items: flex-start; flex-direction: column; gap: 10px; }
}

@media (max-width: 390px) {
  .identity-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metrics-grid .money { grid-column: auto; }
}
