:root {
  color-scheme: light;
  --bg: #f1f1f1;
  --panel: #ffffff;
  --panel-soft: #fbfdfc;
  --line: #e4ece8;
  --line-soft: #edf1ef;
  --text: #1e4c3d;
  --muted: #638175;
  --muted-strong: #46675c;
  --accent: #1e4c3d;
  --accent-strong: #018264;
  --ok-bg: #edf8f2;
  --ok-text: #146c43;
  --warn-bg: #fff6e5;
  --warn-text: #8d5d00;
  --err-bg: #fdeeee;
  --err-text: #a10301;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select { font: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.shell {
  width: min(1520px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 24px 0 40px;
}
.card {
  background: var(--panel);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(30, 76, 61, .08);
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
}
.eyebrow {
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 12px;
  font-weight: 700;
}
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--muted-strong);
}
input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #cfd8d4;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus {
  outline: 2px solid rgba(1, 130, 100, .16);
  border-color: #8dc7b8;
}
button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--accent);
  color: white;
  font-weight: 600;
}
button.secondary {
  background: #edf8f2;
  color: var(--accent);
}
button:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.error, .message {
  border-radius: 12px;
  padding: 12px 14px;
}
.error, .message.err {
  background: var(--err-bg);
  color: #7c1c1c;
}
.message.info {
  background: #f7faf8;
  color: var(--text);
}
.message.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.message.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 20px;
}
.app-title { display: grid; gap: 6px; }
.action-row, .toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.badge, .user-pill {
  background: var(--ok-bg);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
}
.badge.soft {
  background: #f7faf8;
  color: var(--muted);
}
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.panel { display: grid; gap: 14px; }
.preview-card,
.history-rail,
.history-card {
  min-width: 0;
}
.preview-card {
  overflow: hidden;
}
.history-card {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow: hidden;
}
#history-zone {
  overflow: auto;
  max-height: calc(100vh - 180px);
  padding-right: 4px;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}
.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: end;
}
.toolbar-grid > * {
  min-width: 0;
}
.field-instance {
  grid-column: span 4;
}
.field-operation {
  grid-column: span 4;
}
.field-order {
  grid-column: span 4;
}
.field-actions {
  grid-column: 1 / -1;
}
.align-end {
  align-items: end;
  justify-content: flex-start;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin: 8px 0 0;
}
.preview-apply-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}
.preview-apply-copy {
  display: grid;
  gap: 4px;
  flex: 1 1 320px;
  min-width: 0;
}
.preview-apply-btn {
  flex: 0 0 auto;
  margin-left: auto;
  max-width: 100%;
  white-space: nowrap;
}
.metric {
  padding: 14px;
  border-radius: 14px;
  background: #f7faf8;
}
.metric span {
  display: block;
  font-size: 12px;
  color: #56776c;
}
.metric strong {
  font-size: 24px;
  line-height: 1.1;
}
.metric.ok { background: var(--ok-bg); }
.metric.warn { background: var(--warn-bg); }
.metric.err { background: var(--err-bg); }
.blocked-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid #f1c9c9;
  border-radius: 14px;
  background: #fff7f7;
}
.blocked-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.blocked-list {
  display: grid;
  gap: 10px;
}
.blocked-item {
  padding: 12px;
  border-radius: 12px;
  background: white;
  border: 1px solid #f3d7d7;
  display: grid;
  gap: 6px;
}
.blocked-item-main {
  color: var(--err-text);
  font-weight: 600;
}
.blocked-item-sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-chip {
  background: #f7faf8;
  color: var(--muted-strong);
  border: 1px solid var(--line);
  padding: 9px 12px;
}
.filter-chip span {
  margin-left: 6px;
  opacity: .72;
}
.filter-chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.table-wrap {
  position: relative;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}
th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fbfdfc;
  color: var(--muted-strong);
}
tr:last-child td { border-bottom: 0; }
.text-block {
  white-space: normal;
  min-width: 320px;
  line-height: 1.4;
}
.current-block,
.proposal-block {
  max-width: 42ch;
}
.sticky-left,
.sticky-left-2,
.sticky-right {
  position: sticky;
  background: inherit;
  z-index: 2;
}
.sticky-left {
  left: 0;
}
.sticky-left-2 {
  left: 132px;
}
.sticky-right {
  right: 0;
  box-shadow: -10px 0 14px rgba(255, 255, 255, .92);
}
th.sticky-left,
th.sticky-left-2,
th.sticky-right {
  background: #fbfdfc;
  z-index: 4;
}
.col-line { min-width: 132px; width: 132px; }
.col-invoice { min-width: 140px; width: 140px; }
.col-status { min-width: 250px; width: 250px; }
.row-blocked td {
  background: #fff6f6;
}
.row-changed td {
  background: #f7fcf9;
}
.row-neutral td {
  background: white;
}
.status {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.status.ok { background: #e5f7ed; color: #146c43; }
.status.err { background: #fde8e8; color: #a10301; }
.status.muted { background: #f1f4f3; color: var(--muted); }
.cell-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.empty-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  background: #fbfdfc;
}
.history-list {
  display: grid;
  gap: 10px;
}
.history-item {
  padding: 12px;
  border-radius: 12px;
  background: #f7faf8;
  display: grid;
  gap: 8px;
}
.history-top {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.history-main { font-weight: 600; }
.history-sub {
  color: var(--muted);
  font-size: 13px;
}
.history-metrics {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}
.footer {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}
@media (max-width: 1760px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .history-rail { order: 2; }
  .history-card {
    position: static;
    max-height: none;
  }
  #history-zone {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}
@media (max-width: 1160px) {
  .toolbar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-instance,
  .field-operation,
  .field-order {
    grid-column: span 1;
  }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 920px) {
  .app-header { flex-direction: column; }
  .preview-toolbar,
  .blocked-head,
  .preview-apply-bar { flex-direction: column; }
  .text-block { min-width: 260px; }
  .col-status { min-width: 210px; width: 210px; }
}
@media (max-width: 720px) {
  .toolbar-grid { grid-template-columns: 1fr; }
  .field-instance,
  .field-operation,
  .field-order {
    grid-column: span 1;
  }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shell { width: min(100vw - 16px, 100%); }
  .align-end,
  .preview-apply-btn { width: 100%; }
  .preview-apply-btn { margin-left: 0; }
}
