:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #142235;
  --muted: #647486;
  --line: #d7e1ec;
  --accent: #206ba8;
  --accent-strong: #15517f;
  --accent-soft: #eef6fc;
  --accent-soft-strong: #dcecf8;
  --good: #147a4a;
  --warn: #9a5a00;
  --shadow: 0 10px 32px rgba(20, 34, 53, 0.08);
  --motionsizer-layout-top: 73px;
  --motionsizer-layout-bottom: 18px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.brand {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 280px;
}

.brand-logo {
  width: auto;
  max-width: 118px;
  height: 52px;
  object-fit: contain;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.top-actions .top-help-button {
  flex: 0 0 auto;
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 50%;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  font-weight: 700;
}

h2 {
  font-size: 14px;
  font-weight: 700;
}

p {
  color: var(--muted);
}

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

button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

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

button.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.compact-button {
  min-height: 32px;
  padding: 0 12px;
}

.odoo-action {
  border-color: rgba(32, 107, 168, 0.35);
  color: var(--accent);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  height: calc(100dvh - var(--motionsizer-layout-top) - var(--motionsizer-layout-bottom));
  min-height: 0;
  overflow: hidden;
  padding: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
  padding: 16px 16px 48px;
  scroll-padding-bottom: 48px;
}

.controls section {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.controls section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

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

.field-group {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.has-entry-help {
  position: relative;
  padding-right: 28px;
}

.entry-help-button {
  position: absolute;
  top: 0;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
}

.entry-help-button:hover,
.entry-help-button:focus {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  outline: none;
}

.entry-help-popover {
  position: fixed;
  z-index: 30;
  width: min(320px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 12px;
}

.entry-help-popover strong {
  display: block;
  font-size: 13px;
}

.entry-help-popover p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-line;
}

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

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
}

.checkbox-section-title {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin-top: 4px;
  text-transform: uppercase;
}

.checkbox-item input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.inline-checkbox {
  justify-content: flex-start;
}

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

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(32, 107, 168, 0.22);
  border-color: var(--accent);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.unit-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 6px;
}

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

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

.filter-range {
  display: grid;
  gap: 6px;
}

.range-caption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.unit-input select {
  padding-inline: 6px;
}

.profile-distance-input {
  grid-template-columns: minmax(92px, 1fr) 58px;
}

.profile-distance-input select {
  min-width: 0;
  padding-inline: 4px;
}

.workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 0 4px 48px 0;
  scroll-padding-bottom: 48px;
}

@supports not (height: 100dvh) {
  .layout {
    height: calc(100vh - var(--motionsizer-layout-top) - var(--motionsizer-layout-bottom));
  }
}

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

.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-header input {
  max-width: 260px;
}

.section-header select {
  max-width: 320px;
}

.table-wrap {
  max-height: 560px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.profile-builder,
.motor-detail {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.profile-table-wrap {
  overflow-x: auto;
}

.profile-table {
  min-width: 1160px;
}

.profile-table input {
  min-height: 30px;
}

.profile-chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 2px 0 0;
}

.profile-chart-controls label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.profile-chart-controls .series-toggle-label::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--series-color, var(--accent));
}

.profile-chart-controls input {
  width: auto;
  min-height: 0;
  margin: 0;
}

.profile-param {
  display: grid;
  grid-template-columns: minmax(78px, 1fr) 76px;
  gap: 6px;
}

.profile-shape {
  min-width: 112px;
}

.profile-kind {
  min-width: 90px;
}

.profile-table button {
  min-height: 30px;
  padding: 0 10px;
}

.move-order {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drag-handle {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 30px;
  min-height: 28px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: grab;
  padding: 0;
}

.drag-handle span {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.drag-handle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

tr.is-dragging {
  opacity: 0.55;
}

tr.is-drop-target {
  box-shadow: inset 0 2px 0 var(--accent);
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.graph-tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: pre-line;
}

tr.is-selected {
  background: var(--accent-soft);
  outline: 2px solid rgba(32, 107, 168, 0.18);
  outline-offset: -2px;
}

tr.is-pinned {
  background: #f3f8fc;
}

tr.is-out-of-range {
  background: #fff8ea;
}

.row-note {
  display: block;
  max-width: 340px;
  margin-top: 3px;
  color: var(--warn);
  font-size: 11px;
  font-weight: 600;
  white-space: normal;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fbfd;
  color: var(--muted);
  font-size: 12px;
}

td.numeric,
th.numeric {
  text-align: right;
}

tbody tr:hover {
  background: #f1f8fd;
}

.breakdown {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.breakdown.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 0;
}

.breakdown.compact.padded {
  padding: 14px;
}

.breakdown.compact article {
  min-height: 70px;
}

.breakdown.compact article.source-detail {
  grid-column: span 2;
}

.breakdown.compact article.source-detail strong {
  font-size: 13px;
  line-height: 1.35;
}

.breakdown article {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fcfcfd;
}

.breakdown span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.breakdown strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
}

.ok {
  color: var(--good);
}

.warn {
  color: var(--warn);
}

.is-hidden {
  display: none;
}

.helper-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 0;
}

.helper-dialog::backdrop {
  background: rgba(20, 34, 53, 0.32);
}

.helper-dialog form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mechanics-dialog {
  width: min(1180px, calc(100vw - 32px));
}

.project-dialog {
  width: min(980px, calc(100vw - 32px));
}

.dialog-section {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.dialog-section:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.dialog-section h3 {
  margin: 0;
  font-size: 13px;
}

.project-list-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.project-table td:first-child {
  min-width: 210px;
}

.project-table {
  min-width: 760px;
}

.project-table strong,
.project-table span {
  display: block;
}

.project-table span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.project-table .project-row.is-openable {
  cursor: pointer;
}

.project-table .project-row.is-openable:hover,
.project-table .project-row.is-openable:focus-visible {
  background: #eef6fc;
  outline: none;
}

.project-table .project-row.is-placeholder {
  color: var(--muted);
}

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

.calc-table {
  min-width: 1080px;
}

.calc-table th,
.calc-table td {
  padding: 7px;
}

.calc-table input,
.calc-table select {
  min-height: 30px;
  padding: 4px 6px;
}

.calc-table .name-cell {
  min-width: 130px;
}

.calc-table .shape-cell {
  min-width: 130px;
}

.calc-table .material-cell {
  min-width: 150px;
}

.calc-table .numeric-cell {
  min-width: 82px;
}

.calc-table .total-cell {
  min-width: 112px;
  font-weight: 800;
}

.calc-table .inline-field {
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
  min-width: 132px;
}

.mini-unit-input {
  display: grid;
  grid-template-columns: minmax(78px, 1fr) 50px;
  gap: 4px;
}

.mini-unit-input select {
  min-height: 30px;
  padding-inline: 4px;
}

.unit-static {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.transmission-table {
  min-width: 980px;
}

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

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .controls,
  .workspace {
    overflow: visible;
  }

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

@media (max-width: 640px) {
  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1 1 150px;
  }

  .layout {
    padding: 12px;
  }

  .summary-grid,
  .breakdown {
    grid-template-columns: 1fr;
  }
}
