:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #17202a;
  --muted: #5d6b7a;
  --line: #d9e2ec;
  --accent: #155eef;
  --accent-soft: #e6efff;
  --success: #067647;
  --danger: #b42318;
  --warning: #b54708;
  --shadow: 0 10px 35px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --page-scale: 1;
  --table-cell-padding: 10px;
  --table-input-padding-y: 8px;
  --table-input-padding-x: 10px;
  --table-input-font-size: 13px;
  --table-textarea-min: 42px;
  --table-min-width: 1120px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
body { min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  max-width: none;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
}

.topbar, .statusbar, .content > .panel, .footer-note {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 12px;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.15;
}

.subtitle {
  margin: 10px 0 0;
  max-width: 880px;
  color: var(--muted);
  line-height: 1.5;
}

.toolbar-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.toolbar-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.view-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.density-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.density-toggle input {
  margin: 0;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
}
button.ghost {
  background: white;
  color: var(--accent);
}
button.mini {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
}
button.danger {
  border-color: var(--danger);
  background: #fff5f4;
  color: var(--danger);
}
button.secondary {
  background: white;
  color: var(--text);
  border-color: var(--line);
}

.statusbar {
  position: sticky;
  top: 12px;
  z-index: 40;
  margin-top: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.statusbar-main {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
}
.statusbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.statusbar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.toggle-chip {
  white-space: nowrap;
}
.toggle-chip.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
#stats { color: var(--muted); font-size: 14px; }
#flash { color: var(--success); font-weight: 600; min-height: 20px; }

.nav-strip {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  overflow: hidden;
}
.nav-strip-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.nav-strip-group-scroll {
  min-width: 0;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}
.nav-strip-divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  flex: 0 0 auto;
}
.nav-chip {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}
.nav-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.workspace-scale {
  margin-top: 12px;
  transform: scale(var(--page-scale));
  transform-origin: top left;
  width: calc(100% / var(--page-scale));
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.content { min-width: 0; }
.panel {
  padding: 16px;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.panel-title {
  margin: 0;
  font-size: 24px;
}
.panel-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.stats-grid,
.card-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.stat-card,
.info-card,
.summary-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.stat-card strong,
.summary-card strong { display: block; font-size: 26px; margin-top: 8px; }
.summary-card span,
.stat-card span,
.label { color: var(--muted); font-size: 13px; }

.issue-list {
  margin: 12px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.issue-item {
  line-height: 1.45;
}

.issue-item.error {
  color: var(--danger);
}

.issue-item.warning {
  color: var(--warning);
}

.issue-item.ok {
  color: var(--success);
}

.logic-ok {
  margin-top: 12px;
  color: var(--success);
  font-weight: 700;
}

.inline-hint {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 13px;
  line-height: 1.45;
}

.inline-hint-warning {
  border-color: color-mix(in srgb, var(--warning) 35%, var(--line));
  background: color-mix(in srgb, var(--warning) 8%, var(--panel-soft));
  color: var(--warning);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}
.field, .field-wide {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.field { grid-column: span 4; }
.field-wide { grid-column: span 12; }
.field.half { grid-column: span 6; }
.field.quarter { grid-column: span 3; }
.field label,
.field-wide label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }

.field-label {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.xml-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
  border: 1px solid rgba(15, 23, 42, 0.18);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
  cursor: help;
}

.xml-indicator.inline {
  margin-left: auto;
}

.xml-indicator.compact {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 9px;
  height: 9px;
}

.xml-indicator.is-direct {
  background: #22c55e;
}

.xml-indicator.is-derived {
  background: #f59e0b;
}

.xml-indicator.is-unused {
  background: #cbd5e1;
}

.xml-cell-wrap {
  position: relative;
}

.xml-cell-wrap.is-direct input,
.xml-cell-wrap.is-direct textarea,
.xml-cell-wrap.is-direct select,
.xml-cell-wrap.is-direct .table-muted-cell,
.xml-cell-wrap.is-direct .readonly,
.xml-cell-wrap.is-direct .amount-stack,
.xml-cell-wrap.is-direct span {
  border-color: rgba(34, 197, 94, 0.35);
}

.xml-cell-wrap.is-derived input,
.xml-cell-wrap.is-derived textarea,
.xml-cell-wrap.is-derived select,
.xml-cell-wrap.is-derived .table-muted-cell,
.xml-cell-wrap.is-derived .readonly,
.xml-cell-wrap.is-derived .amount-stack,
.xml-cell-wrap.is-derived span {
  border-color: rgba(245, 158, 11, 0.4);
}

.field input,
.field-wide input,
.field textarea,
.field-wide textarea,
.field select,
.field-wide select {
  width: 100%;
  border: 1px solid #c8d3df;
  border-radius: 10px;
  background: white;
  padding: 10px 12px;
  color: var(--text);
}
.field textarea,
.field-wide textarea { min-height: 82px; resize: vertical; }
.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #c8d3df;
  border-radius: 10px;
  background: white;
  font-weight: 600;
}
.checkbox-row input {
  width: 16px;
  height: 16px;
  margin: 0;
}
.readonly {
  padding: 10px 12px;
  min-height: 42px;
  border-radius: 10px;
  background: #eef2f6;
  border: 1px dashed #c7d0db;
}

.section-block {
  margin-top: 20px;
}
.section-block > h3 {
  margin: 0 0 12px;
  font-size: 18px;
}
.section-block > p {
  margin: 0 0 14px;
  color: var(--muted);
}

.excel-frame {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  overflow: hidden;
}

.excel-frame-tight {
  margin-top: 6px;
}

.excel-frame-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.excel-frame-caption {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.excel-frame-title {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 800;
}

.excel-frame-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.excel-code-box {
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  text-align: right;
}

.excel-code-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.excel-code-box strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.excel-org-list {
  display: flex;
  flex-direction: column;
}

.excel-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.excel-line-simple {
  grid-template-columns: minmax(0, 1fr);
}

.excel-line-main {
  min-width: 0;
}

.excel-line-label,
.excel-line-side-label,
.excel-basis-label,
.excel-meta-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.excel-line-value {
  display: block;
  margin-top: 4px;
  line-height: 1.45;
}

.excel-line-side {
  text-align: right;
}

.excel-line-side strong {
  display: block;
  margin-top: 4px;
}

.excel-line-hint {
  color: var(--muted);
  font-size: 12px;
}

.excel-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--line);
}

.excel-meta-cell {
  padding: 12px 16px;
  border-right: 1px solid var(--line);
}

.excel-meta-cell:last-child {
  border-right: 0;
}

.excel-meta-cell strong,
.excel-meta-cell em {
  display: block;
  margin-top: 4px;
  font-style: normal;
}

.excel-meta-cell-wide {
  background: #fcfdff;
}

.excel-basis-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px 16px;
}

.excel-basis-value {
  line-height: 1.5;
}

.excel-totals-block {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  overflow: hidden;
}

.excel-total-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.excel-total-line:last-child {
  border-bottom: 0;
}

.excel-total-line span {
  color: var(--muted);
  font-weight: 700;
}

.signature-table {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.signature-excel-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  padding: 12px 16px;
}

.signature-excel-main,
.signature-excel-hints,
.signature-excel-stamp {
  display: grid;
  grid-template-columns: 120px minmax(260px, 1fr) minmax(120px, 180px) minmax(140px, 180px);
  gap: 8px 12px;
  align-items: end;
}

.signature-excel-hints,
.signature-excel-stamp {
  margin-top: 6px;
}

.signature-role {
  font-weight: 700;
}

.signature-position-wide,
.signature-name-wide {
  min-height: 24px;
  line-height: 1.4;
}

.signature-sign-line {
  border-bottom: 1px solid #98a2b3;
  min-height: 24px;
}

.signature-mark,
.signature-stamp {
  color: var(--muted);
  font-size: 12px;
}

.ks2-footer-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(220px, 0.8fr);
  gap: 12px;
}

.ks2-breakdown-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: white;
}

.ks2-breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.ks2-breakdown-row:last-child {
  border-bottom: 0;
}

.ks2-breakdown-row span {
  color: var(--muted);
  font-weight: 700;
}

.holdbacks-totals-grid {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: white;
}

.holdbacks-total-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(8, minmax(88px, 1fr));
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.holdbacks-total-row:last-child {
  border-bottom: 0;
}

.holdbacks-total-row span {
  color: var(--muted);
  font-weight: 700;
}

.holdbacks-total-row strong {
  text-align: right;
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: var(--table-min-width);
}
.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: var(--table-cell-padding);
  text-align: left;
  vertical-align: top;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table thead .numbering-row th {
  top: 32px;
  z-index: 2;
  background: #eef3f8;
  color: #748396;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 700;
  text-align: center;
}
.table td input,
.table td textarea,
.table td select {
  width: 100%;
  border: 1px solid #ccd6e0;
  border-radius: 8px;
  padding: var(--table-input-padding-y) var(--table-input-padding-x);
  background: white;
  font-size: var(--table-input-font-size);
  line-height: 1.25;
}
.table td textarea {
  min-height: var(--table-textarea-min);
  resize: vertical;
}
.table tr.section-row td {
  background: #eef4ff;
}
.table tr.note-row td {
  background: #fff9ed;
}

.table-ks2 {
  min-width: 1360px;
}
.table-ks2 .ks2-col-type { width: 76px; }
.table-ks2 .ks2-col-code { width: 82px; }
.table-ks2 .ks2-col-line { width: 58px; }
.table-ks2 .ks2-col-estimate { width: 54px; }
.table-ks2 .ks2-col-name { width: 520px; }
.table-ks2 .ks2-col-unit { width: 68px; }
.table-ks2 .ks2-col-qty { width: 88px; }
.table-ks2 .ks2-col-price { width: 112px; }
.table-ks2 .ks2-col-amount { width: 122px; }
.table-ks2 .ks2-col-consumption { width: 50px; }
.table-ks2 .ks2-col-category { width: 110px; }
.table-ks2 .ks2-col-note { width: 160px; }
.table-ks2 .ks2-col-actions { width: 56px; }

.table-ks2 th:nth-child(3),
.table-ks2 th:nth-child(4),
.table-ks2 th:nth-child(10),
.table-ks2 td:nth-child(3),
.table-ks2 td:nth-child(4),
.table-ks2 td:nth-child(10) {
  text-align: center;
}

.table-ks2 td:nth-child(5) textarea {
  min-height: calc(var(--table-textarea-min) + 4px);
}

.holdback-section-row td {
  background: white;
}

.holdback-subitem-row td {
  background: #fbfcfe;
}

.holdback-section-cell {
  background: white;
  vertical-align: middle;
}

.holdback-section-title textarea {
  min-height: 40px;
  font-weight: 700;
}

.holdback-doc-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.holdback-doc-grid .field {
  margin: 0;
}

.holdback-summary-block {
  margin-top: 18px;
}

.holdback-summary-header {
  margin-bottom: 10px;
}

.xml-preview-focus-block {
  margin-bottom: 14px;
}

.xml-preview-focus-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.xml-preview-code-compact {
  max-height: 22vh;
}

.holdback-comment-cell textarea {
  min-height: 40px;
}

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

.holdback-percent-cell input {
  text-align: center;
}

.table-holdbacks tbody td {
  padding-top: 4px;
  padding-bottom: 4px;
}

.table-holdbacks tbody textarea,
.table-holdbacks tbody input {
  min-height: 28px;
  padding: 4px 6px;
  border-radius: 4px;
}

.holdback-section-row td {
  border-top: 1px solid #cfd6e4;
  border-bottom: 1px solid #d9dfeb;
}

.holdback-middle-result {
  white-space: nowrap;
  text-align: right;
  font-weight: 700;
  background: #fafbfd;
}

.holdback-middle-doc {
  text-align: center;
  color: #667085;
  font-size: 11px;
  background: #fafbfd;
}

.holdback-subitem-row td {
  background: #fcfdff;
}

.holdback-subitem-indent,
.subitem-money-cell,
.subitem-doc-cell,
.subitem-result-cell,
.holdback-subitem-right,
.subitem-comment-cell {
  background: #fcfdff;
}

.holdback-subitem-indent {
  border-top: 0;
  border-bottom: 0;
}

.subitem-money-cell,
.subitem-doc-cell,
.subitem-result-cell,
.holdback-subitem-right,
.subitem-comment-cell {
  border-top: 0;
}

.subitem-result-cell {
  white-space: nowrap;
  text-align: right;
  font-weight: 700;
}

.holdback-subitem-right {
  color: #667085;
  font-size: 11px;
}

.subitem-comment-cell textarea {
  min-height: 28px;
}

.holdback-subitem-caption {
  display: inline-block;
  padding-left: 4px;
}

.mini-readonly {
  min-height: 34px;
  background: #f4f7fb;
}

.table-holdbacks {
  min-width: 1500px;
}
.table-holdbacks .hold-col-name { width: 420px; }
.table-holdbacks .hold-col-ks2,
.table-holdbacks .hold-col-materials,
.table-holdbacks .hold-col-advance,
.table-holdbacks .hold-col-previous,
.table-holdbacks .hold-col-closing,
.table-holdbacks .hold-col-next,
.table-holdbacks .hold-col-retention,
.table-holdbacks .hold-col-payable { width: 120px; }
.table-holdbacks .hold-col-doc { width: 170px; }
.table-holdbacks .hold-col-percent { width: 54px; }
.table-holdbacks .hold-col-comment { width: 180px; }
.table-holdbacks .hold-col-actions { width: 28px; }
.table-holdbacks th:nth-child(9),
.table-holdbacks td:nth-child(9) {
  text-align: center;
}

.number-cell {
  min-width: 88px;
}
.amount-cell {
  white-space: nowrap;
  font-weight: 700;
}
.amount-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calc-mode-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.calc-mode-chip.subtract {
  background: #fff4e5;
  color: #b54708;
}
.table-muted-cell {
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}
.correction-row td {
  background: #fffaf5;
}
.correction-row td:first-child,
.correction-row td.amount-cell {
  box-shadow: inset 3px 0 0 #f79009;
}
.ks3-name-cell textarea {
  min-height: var(--table-textarea-min);
}
.ks3-row-total td {
  background: #f8fafc;
  font-weight: 700;
}
.ks3-row-subhead td {
  background: #fcfdff;
  color: var(--muted);
  font-weight: 600;
}
.actions-cell {
  min-width: 44px;
  position: relative;
}

.icon-button {
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
}

.row-action-stack {
  position: relative;
  width: 26px;
  min-width: 26px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: visible;
  background: white;
}

.stack-button {
  width: 100%;
  height: 18px;
  min-width: 26px;
  padding: 0;
  border: 0;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.stack-button.add {
  background: #ecfdf3;
  color: #067647;
  border-bottom: 1px solid var(--line);
}

.stack-button.remove {
  background: #fff5f4;
  color: #b42318;
}

.row-action-menu,
.row-action-confirm {
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
  z-index: 8;
  min-width: 108px;
  max-width: 124px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
}

.row-action-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row-action-menu-wide {
  min-width: 240px;
  max-width: 280px;
}

.inline-add-stack {
  display: inline-flex;
  align-items: center;
}

.row-action-menu-item,
.row-action-menu-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
}

.row-action-confirm {
  min-width: 118px;
}

.row-action-confirm-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.row-action-confirm-buttons {
  display: flex;
  gap: 6px;
}

.confirm-icon {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  font-weight: 800;
}

.confirm-yes {
  background: #ecfdf3;
  color: #067647;
  border: 1px solid #b7ebc6;
}

.confirm-no {
  background: #fff5f4;
  color: #b42318;
  border: 1px solid #f4c7c3;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
}

.resize-handle::after {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 3px;
  width: 2px;
  background: #d0d7e2;
  border-radius: 999px;
}

.table th:hover .resize-handle::after {
  background: var(--accent);
}

body[data-density="compact"] {
  --table-cell-padding: 6px;
  --table-input-padding-y: 6px;
  --table-input-padding-x: 8px;
  --table-input-font-size: 12px;
  --table-textarea-min: 32px;
  --table-min-width: 1040px;
}

body[data-density="comfortable"] {
  --table-cell-padding: 10px;
  --table-input-padding-y: 8px;
  --table-input-padding-x: 10px;
  --table-input-font-size: 13px;
  --table-textarea-min: 42px;
  --table-min-width: 1120px;
}

body[data-scale="85"] {
  --page-scale: 0.85;
}

body[data-scale="100"] {
  --page-scale: 1;
}

body[data-scale="115"] {
  --page-scale: 1.15;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.breakdown-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.breakdown-chip {
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #eefaf2;
  color: var(--success);
  font-size: 13px;
  font-weight: 700;
}

.kbd-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.ks2-header-actions {
  align-items: center;
}

.view-switcher {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
}

.xml-preview-pair-head {
  margin-top: 18px;
}

.xml-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
  align-items: start;
}

.xml-preview-block {
  margin-top: 18px;
}

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

.xml-preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.xml-preview-status {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #f8fafc;
}

.xml-preview-status.error,
.xml-preview-errors {
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff1f2;
  color: #991b1b;
  border: 1px solid #fecdd3;
}

.xml-preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 13px;
}

.xml-preview-meta.valid strong {
  color: var(--success);
}

.xml-preview-meta.invalid strong {
  color: #b45309;
}

.xml-preview-note {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.xml-preview-errors {
  margin-bottom: 12px;
  display: grid;
  gap: 6px;
}

.xml-preview-code {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 70vh;
}

.xml-line {
  display: block;
  padding: 1px 8px;
  border-radius: 8px;
}

.xml-line + .xml-line {
  margin-top: 1px;
}

.xml-line-text {
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.xml-line-sheet {
  background: rgba(59, 130, 246, 0.08);
}

.xml-line-section {
  background: rgba(148, 163, 184, 0.10);
}

.xml-line-work {
  background: rgba(34, 197, 94, 0.08);
}

.xml-line-settlement {
  background: rgba(244, 114, 182, 0.10);
}

.xml-line-retention {
  background: rgba(245, 158, 11, 0.12);
}

.xml-line-advance {
  background: rgba(168, 85, 247, 0.10);
}

.settlement-section-block {
  margin-top: 18px;
}

.settlement-block-header {
  align-items: flex-start;
  gap: 16px;
}

.settlement-add-menu {
  min-width: 320px;
  max-width: 360px;
}

.settlement-menu-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settlement-menu-group + .settlement-menu-group {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.settlement-menu-title {
  padding: 2px 4px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settlement-summary-grid {
  margin-bottom: 12px;
}

.settlement-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.settlement-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
}

.settlement-auto-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.settlement-auto-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  font-size: 13px;
}

.settlement-auto-meta {
  color: var(--muted);
  line-height: 1.4;
}

.settlement-chip-muted {
  color: var(--muted);
}

.settlement-preview {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.settlement-preview.muted {
  color: var(--muted);
}

.table-settlement {
  min-width: 1120px;
}

.table-settlement th:last-child,
.table-settlement td:last-child {
  width: 32px;
}

.settlement-primary-cell {
  min-width: 118px;
}

.settlement-primary-btn {
  width: 100%;
}

.settlement-primary-row td {
  background: #f3fbf6;
}

.settlement-readonly {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.settlement-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.panel-header-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.settlement-add-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.settlement-add-anchor .row-action-menu {
  top: calc(100% + 8px);
  right: 0;
}

.holdback-xml-preview-row td,
.holdback-xml-empty-row td,
.holdback-xml-row td {
  background: #f8fafc;
}

.holdback-xml-row.is-primary td {
  background: #f3fbf6;
}

.holdback-xml-card {
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  padding: 14px;
  background: white;
}

.holdback-xml-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.holdback-xml-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.holdback-xml-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.holdback-xml-grid {
  margin-top: 0;
}

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

.settlement-inline-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.footer-note {
  margin-top: 16px;
  padding: 16px 18px;
  color: var(--muted);
  line-height: 1.5;
}

.empty-state {
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .workspace-scale {
    transform: none;
    width: 100%;
  }
  .workspace { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .topbar, .statusbar, .panel-header, .toolbar-wrap, .statusbar-main, .statusbar-meta { flex-direction: column; }
  .statusbar-main,
  .statusbar-meta,
  .statusbar-controls {
    align-items: stretch;
  }
  .nav-strip {
    flex-direction: column;
    align-items: stretch;
  }
  .nav-strip-group,
  .nav-strip-group-scroll {
    flex-wrap: wrap;
    overflow: visible;
  }
  .nav-strip-divider {
    width: 100%;
    height: 1px;
  }
  .view-controls { justify-content: flex-start; }
  .signature-frame { grid-template-columns: 1fr; }
  .signature-excel-main,
  .signature-excel-hints,
  .signature-excel-stamp,
  .holdbacks-total-row,
  .ks2-footer-grid,
  .excel-frame-top, .excel-line, .excel-meta-grid, .excel-basis-row { grid-template-columns: 1fr; display: grid; }
  .field { grid-column: span 12; }
  .field.half { grid-column: span 12; }
  .field.quarter { grid-column: span 6; }
}
