:root {
  --bg: #edf0f5;
  --panel: #ffffff;
  --ink: #122945;
  --muted: #5f6f85;
  --line: #cfd7e4;
  --soft: #f5f7fa;
  --accent: #001841;
  --accent-soft: #e7ecf4;
  --danger: #d7193f;
  --danger-soft: #fff0f3;
  --danger-line: #f1a9b8;
  --good: #15803d;
  --warn: #a15c00;
  --shadow: 0 8px 24px rgba(0, 24, 65, 0.12);
  --focus-ring: 0 0 0 3px rgba(215, 25, 63, 0.14);
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(90deg, rgba(215, 25, 63, 0.08) 0 1px, transparent 1px 100%), var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 12px;
}

button,
input,
select,
textarea {
  font: inherit;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.05;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
}

button {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 9px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.16) inset;
}

button[data-icon]::before {
  content: attr(data-icon);
  width: 17px;
  height: 17px;
  display: inline-grid;
  place-items: center;
  color: currentColor;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 3px;
  font-size: 11px;
}

button:hover { filter: brightness(0.96); }
button:disabled { cursor: not-allowed; opacity: 0.62; }

.secondary-action {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #b8c5d8;
  box-shadow: none;
}

.secondary-action[data-icon]::before {
  color: #fff;
  background: var(--accent);
}

.danger-action {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-line);
  box-shadow: none;
}

.danger-action[data-icon]::before {
  color: #fff;
  background: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  min-height: 28px;
  padding: 5px 7px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}

textarea {
  resize: vertical;
  line-height: 1.35;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--danger);
  box-shadow: var(--focus-ring);
  outline: none;
}

label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 4px 5px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
}

th {
  color: var(--muted);
  background: var(--soft);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

td input,
td select {
  min-width: 88px;
}

.machine-description {
  min-width: 280px;
}

.machine-quantity,
.machine-actual,
.machine-price {
  min-width: 96px;
}

.machine-note {
  min-width: 150px;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 12px 9px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--danger);
  box-shadow: var(--shadow);
  z-index: 2;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 16px;
  bottom: -2px;
  width: 72px;
  height: 3px;
  background: var(--danger);
  border-radius: 999px;
}

.brand-copy p,
.section-head span,
.muted {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.brand-copy p { margin-top: 4px; }

.top-actions,
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

#newOffer,
#saveOffer,
#savePricelist {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 6px 14px rgba(215, 25, 63, 0.22);
}

#newOffer[data-icon]::before,
#saveOffer[data-icon]::before,
#savePricelist[data-icon]::before {
  color: var(--danger);
  background: #fff;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

.panel,
.subpanel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.panel {
  min-height: 0;
  overflow: hidden;
}

.list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.editor-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.section-head {
  justify-content: space-between;
  min-height: 34px;
  padding: 7px 8px;
  background: var(--soft);
  border-bottom: 1px solid var(--line);
}

.filters {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.offer-rows {
  overflow: auto;
}

.offer-row {
  width: 100%;
  display: grid;
  align-items: start;
  justify-content: stretch;
  justify-items: start;
  gap: 2px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
  box-shadow: none;
}

.offer-row.active {
  background: var(--accent-soft);
  border-left: 3px solid var(--danger);
}

.offer-row strong,
.offer-row span,
.offer-row small {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.offer-row small {
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 6px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.tab {
  color: var(--accent);
  background: var(--soft);
  border-color: var(--line);
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  box-shadow: none;
}

.tab.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.tab-view {
  display: none;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.tab-view.active {
  display: grid;
  gap: 8px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.7fr);
  gap: 8px;
}

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

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

.wide {
  grid-column: 1 / -1;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 14px;
}

.check-line input {
  width: auto;
  min-height: 0;
}

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

.summary-grid div {
  min-height: 44px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
}

.summary-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.summary-grid strong {
  font-size: 15px;
  line-height: 1.1;
}

.actual-summary {
  border-color: #b8c5d8;
  background: var(--accent-soft);
}

.validation-box {
  min-height: 22px;
  margin: 0 8px 8px;
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
}

.manual-price {
  background: var(--danger-soft);
  border-color: var(--danger-line);
}

.is-selected,
tr.is-selected td {
  background: #eef6ff;
}

.transport-card.is-selected,
.extra-row.is-selected {
  border-color: #9fb8d8;
  box-shadow: inset 3px 0 0 var(--accent);
}

tr.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.total-cell {
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.two-cols {
  display: grid;
  grid-template-columns: minmax(300px, 0.75fr) minmax(0, 1.25fr);
  gap: 0;
  min-height: 238px;
  overflow: visible;
}

.two-cols > div + div {
  border-left: 1px solid var(--line);
}

.transport-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 6px;
  padding: 8px;
  align-items: start;
}

.transport-card {
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.transport-card > label:first-child {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.transport-card input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.operator-description {
  min-width: 150px;
}

.operator-quantity,
.operator-actual,
.operator-price {
  min-width: 76px;
}

.operator-note {
  min-width: 140px;
}

.extra-rows,
.admin-list {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.extra-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 6px;
  align-items: end;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.extra-row,
.admin-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 130px auto;
  gap: 5px;
  align-items: end;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
}

.admin-row.machine {
  grid-template-columns: 90px minmax(190px, 1.4fr) 100px 110px 110px 70px auto;
}

.admin-row {
  grid-template-columns: minmax(150px, 1.5fr) 90px 110px minmax(120px, 1fr) auto;
}

.remove-line {
  min-width: 28px;
  padding: 4px 7px;
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-line);
  box-shadow: none;
}

.loading-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 24, 65, 0.24);
  z-index: 20;
}

.loading-panel {
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--danger);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell,
  .workspace,
  .panel,
  .tab-view {
    height: auto;
    overflow: visible;
  }

  .topbar,
  .workspace,
  .editor-grid,
  .two-cols {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .section-head {
    justify-content: flex-start;
  }

  .two-cols > div + div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .extra-row,
  .admin-row,
  .admin-row.machine,
  .form-grid,
  .form-grid.compact,
  .transport-box {
    grid-template-columns: 1fr;
  }
}
