/* ============================================================
   Document tabs — compact ERP layout for Договір / ДУ / Накладна
   Visual target: soft paper shell, green accent, metric tiles
   ============================================================ */

.doc-erp {
  max-width: 1080px;
  margin: 0 auto;
  /* CRITICAL: no padding-top — sticky children would travel those px before locking (люфт).
     Top spacing lives inside .doc-erp-sticky itself so it is part of the stuck box. */
  padding: 0 12px 40px;
}

/* Sticky chrome: title + meta + tabs — locked solid, zero travel on scroll.
   Root cause of jitter was parent padding-top + sticky top:0 (element slides up
   until it hits the scrollport edge). Fix: zero parent top padding; spacing inside sticky. */
.doc-erp-sticky {
  position: sticky;
  top: 0;
  z-index: 30;
  /* Opaque solid fill matching scrollport — content must not show through */
  background: var(--surface, #fff);
  /* Former .doc-erp top padding + internal gap — counted as sticky height, does not travel */
  padding: 8px 0 0;
  margin: 0;
  /* Soft edge only; first layer masks any 1px gap under sticky */
  box-shadow:
    0 1px 0 var(--surface, #fff),
    0 6px 12px -8px rgba(31, 36, 33, 0.18);
  /* No transform / will-change — those cause subpixel re-raster and visible bounce */
  transform: none;
  will-change: auto;
  backface-visibility: hidden;
  /* Block margin-collapse with following body */
  display: flow-root;
}

/* White card shell (content panels only — tabs moved into sticky) */
.doc-erp-body {
  background: var(--surface, #fff);
  border: 1px solid var(--line-soft, #eae7df);
  border-radius: 14px;
  padding: 0 18px 18px;
  box-shadow: 0 1px 2px rgba(31, 36, 33, 0.04);
  /* Tabs no longer inside body — add top radius / spacing */
  margin-top: 0;
}

/* ---------- Header ---------- */
.doc-erp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  padding: 4px 2px 0;
}

.doc-erp-title-block {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.doc-erp-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
  color: var(--ink, #1f2421);
}

.doc-erp-title .num {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark, #234f45);
  letter-spacing: 0.02em;
}

.doc-erp-title-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-tint, #e6efec);
  color: var(--accent-dark, #234f45);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

/* Header action buttons — outline style like screenshot */
.doc-erp-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
}

.doc-erp-actions .btn.ghost {
  background: var(--surface, #fff);
  border: 1px solid var(--line, #dedad0);
  color: var(--ink, #1f2421);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 600;
  font-size: 12.5px;
}

.doc-erp-actions .btn.ghost:hover {
  background: var(--accent-tint, #e6efec);
  border-color: var(--accent, #2f6f62);
}

.doc-erp-actions .btn.danger.ghost {
  color: var(--danger, #a3402f);
  border-color: #e5c4bc;
  background: var(--surface, #fff);
}

.doc-erp-actions .btn.danger.ghost:hover {
  background: var(--danger-tint, #f6e9e6);
  border-color: var(--danger, #a3402f);
}

/* ---------- Meta strip ---------- */
.doc-erp-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--ink-soft, #5b6460);
  margin: 0 0 10px;
  padding: 9px 14px;
  background: var(--accent-tint, #e6efec);
  border-radius: 10px;
  border: 1px solid transparent;
}

.doc-erp-sticky .doc-erp-meta {
  margin-bottom: 8px;
  margin-top: 0;
}

.doc-erp-sticky .doc-erp-header {
  margin-bottom: 8px;
  margin-top: 0;
  padding-top: 4px;
}

.doc-erp-meta b {
  color: var(--ink, #1f2421);
  font-weight: 600;
}

.doc-erp-meta-sep {
  opacity: 0.55;
  user-select: none;
}

/* ---------- Segmented tabs (sticky chrome, above card body) ---------- */
.doc-erp-sticky .doc-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  border: 1px solid var(--line-soft, #eae7df);
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  margin: 0;
  padding: 10px 12px 0;
  list-style: none;
  background: var(--surface, #fff);
  /* Connect visually with .doc-erp-body below */
  /* Lock geometry — no translate / animation on scroll */
  position: relative;
  top: auto;
  transform: none;
  will-change: auto;
  flex-shrink: 0;
}

.doc-erp-sticky + .doc-erp-body {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  padding-top: 16px;
}

/* Fallback if tabs still rendered inside body (other doc types) */
.doc-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line-soft, #eae7df);
  margin: 0 -6px 16px;
  padding: 10px 6px 0;
  list-style: none;
}

.doc-tab {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft, #5b6460);
  padding: 9px 14px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  position: relative;
  transition: color 0.12s, background 0.12s;
}

.doc-tab:hover {
  color: var(--ink, #1f2421);
  background: rgba(47, 111, 98, 0.06);
}

.doc-tab.is-active {
  color: var(--accent-dark, #234f45);
  background: var(--accent-tint, #e6efec);
}

.doc-tab.is-active::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  background: var(--accent, #2f6f62);
  border-radius: 2px 2px 0 0;
}

.doc-tab:focus-visible {
  outline: 2px solid var(--accent, #2f6f62);
  outline-offset: 1px;
}

.doc-tab-panel {
  display: none;
}

.doc-tab-panel.is-active {
  display: block;
  /* No translateY animation — vertical motion next to sticky chrome looks like chrome drift */
  animation: none;
}

/* ---------- Form grid ---------- */
.doc-erp .field-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 16px;
  margin-bottom: 16px;
}

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

.doc-erp .field.span-2 { grid-column: span 2; }
.doc-erp .field.span-4 { grid-column: span 4; }

.doc-erp .field label {
  font-size: 11.5px;
  color: var(--ink-soft, #5b6460);
  font-weight: 600;
}

.doc-erp .field input,
.doc-erp .field textarea,
.doc-erp .field select {
  border: 1px solid var(--line, #dedad0);
  border-radius: 8px;
  padding: 8px 11px;
  background: var(--surface, #fff);
  width: 100%;
  font-size: 13.5px;
  color: var(--ink, #1f2421);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.doc-erp .field input:focus,
.doc-erp .field textarea:focus,
.doc-erp .field select:focus {
  border-color: var(--accent, #2f6f62);
  box-shadow: 0 0 0 3px rgba(47, 111, 98, 0.12);
  outline: none;
  background: #fff;
}

.doc-erp .field .cpv-row {
  display: flex;
  gap: 8px;
}

.doc-erp .field .cpv-row input:first-child {
  width: 120px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.doc-erp .field-readonly.field-status {
  min-height: 36px;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  border: none;
  background: transparent;
}

.doc-erp .field-amount {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink, #1f2421);
  padding: 8px 0 4px;
  letter-spacing: 0.01em;
}

/* ---------- Badges ---------- */
.doc-erp .badge {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
}

.doc-erp .badge.badge-success {
  background: var(--accent-tint, #e6efec);
  color: var(--accent-dark, #234f45);
}

.doc-erp .badge.badge-closed {
  background: var(--line-soft, #eae7df);
  color: var(--ink-soft, #5b6460);
}

.doc-erp .import-status-badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1.4;
}

.doc-erp .import-status-badge.is-verified {
  background: var(--accent-tint, #e6efec);
  color: var(--accent-dark, #234f45);
}

.doc-erp .import-status-badge.is-edata {
  background: #f3efe6;
  color: var(--amber, #9c6b15);
}

.doc-erp .import-status-badge.is-empty {
  background: var(--line-soft, #eae7df);
  color: var(--ink-soft, #5b6460);
}

/* ---------- Metric tiles ---------- */
.doc-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 4px;
  margin-bottom: 2px;
}

.doc-metric {
  background: var(--surface, #fff);
  border: 1px solid var(--line-soft, #eae7df);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.doc-metric-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft, #5b6460);
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-metric-ico {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-tint, #e6efec);
  color: var(--accent, #2f6f62);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.doc-metric-value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink, #1f2421);
  letter-spacing: 0.01em;
  padding-left: 30px;
}

.doc-metric-value.is-zero { color: var(--ink-soft, #5b6460); }
.doc-metric-value.is-warn { color: var(--danger, #a3402f); }
.doc-metric-value.is-ok { color: var(--accent-dark, #234f45); }

/* Soft cards inside panels */
.doc-panel-card {
  background: var(--surface, #fff);
  border: 1px solid var(--line-soft, #eae7df);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.doc-panel-card h4 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft, #5b6460);
  letter-spacing: 0.02em;
}

.doc-erp-footer {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft, #eae7df);
}

/* Nested legacy sections inside tabs */
.doc-tab-panel > .section {
  margin-top: 0;
  margin-bottom: 12px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.doc-tab-panel > .section > .section-head {
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft, #eae7df);
}

.doc-tab-panel > .section > .section-head h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft, #5b6460);
  margin: 0;
}

.doc-tab-panel .scd-pulse {
  border-radius: 12px;
  border: 1px solid var(--line-soft, #eae7df);
  background: var(--paper, #f7f6f2);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.doc-tab-panel .scd-pulse h3 {
  font-size: 12.5px;
  margin: 0 0 8px;
}

.doc-tab-panel .scd-contractor {
  border-radius: 12px;
  border: 1px solid var(--line-soft, #eae7df);
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface, #fff);
}

.doc-tab-panel .funds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.doc-tab-panel .table-scroll {
  border-radius: 10px;
  border: 1px solid var(--line-soft, #eae7df);
  overflow: auto;
}

.doc-tab-panel .req-empty,
.doc-tab-panel .empty-state {
  padding: 24px 12px;
  text-align: center;
  color: var(--ink-soft, #5b6460);
  font-size: 13px;
}

@media (max-width: 900px) {
  .doc-erp .field-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .doc-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .doc-erp { padding: 8px 8px 32px; }
  .doc-erp-header { flex-direction: column; }
  .doc-tab { padding: 8px 10px; font-size: 12px; }
  .doc-erp-body { padding: 0 12px 14px; border-radius: 12px; }
  .doc-metric-value { padding-left: 0; }
}

/* DU timeline chips on contract card */
.ds-timeline-wrap {
  margin: 0 0 12px;
}
.ds-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.ds-chip {
  appearance: none;
  border: 1px solid var(--line-soft, #eae7df);
  background: var(--surface, #fff);
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink, #1f2421);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}
.ds-chip:hover {
  background: var(--accent-tint, #e6efec);
  border-color: var(--accent, #2f6f62);
}
.ds-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, #2f6f62);
  flex-shrink: 0;
}
.field-check .check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  padding-top: 22px;
}
.vat-toggle {
  display: flex;
  gap: 14px;
  padding: 8px 0;
  font-size: 13px;
}
.badge.amber {
  background: #f3efe6;
  color: var(--amber, #9c6b15);
}

/* ===== Design parity with mock (icons in soft green circles) ===== */
.doc-erp-title-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-tint, #e6efec);
  color: var(--accent, #2f6f62);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(47, 111, 98, 0.08);
}
.doc-erp-title-icon .erp-ico {
  display: block;
}

.doc-metric {
  background: #fff;
  border: 1px solid var(--line-soft, #eae7df);
  border-radius: 14px;
  padding: 14px 16px 14px 14px;
  box-shadow: 0 1px 2px rgba(31, 36, 33, 0.03);
}

.doc-metric-ico {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-tint, #e6efec);
  color: var(--accent, #2f6f62);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(47, 111, 98, 0.1);
}
.doc-metric-ico .erp-ico {
  width: 14px;
  height: 14px;
  display: block;
}

.doc-metric-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft, #5b6460);
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-metric-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink, #1f2421);
  padding-left: 38px; /* align under label text, past icon */
  letter-spacing: 0.01em;
  margin-top: 2px;
}

/* Header action buttons — outline like mock */
.doc-erp-actions .btn.small {
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
}
.doc-erp-actions .btn.ghost {
  background: #fff;
  border: 1px solid var(--line, #dedad0);
  color: var(--ink, #1f2421);
}
.doc-erp-actions .btn.ghost:hover {
  background: var(--accent-tint, #e6efec);
  border-color: var(--accent, #2f6f62);
  color: var(--accent-dark, #234f45);
}
.doc-erp-actions .btn.danger.ghost,
.doc-erp-actions .btn.danger {
  background: #fff;
  border: 1px solid #e8c5bd;
  color: var(--danger, #a3402f);
}
.doc-erp-actions .btn.danger:hover {
  background: var(--danger-tint, #f6e9e6);
}

/* Active tab pill like mock */
.doc-tab.is-active {
  color: var(--accent-dark, #234f45);
  background: var(--accent-tint, #e6efec);
  border-radius: 10px 10px 0 0;
}

/* Status badges in header/field */
.doc-erp .badge.badge-success {
  background: #dceee8;
  color: #1f6b5a;
  border: 1px solid transparent;
}
.doc-erp .import-status-badge.is-empty {
  background: #eef1ef;
  color: #7a8580;
}

@media (max-width: 720px) {
  .doc-metric-value { padding-left: 0; }
}

/* ========== Metric tiles — exact mock proportions ========== */
.doc-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 8px;
}

.doc-metric {
  background: #fff;
  border: 1px solid var(--line-soft, #e8e4dc);
  border-radius: 16px;
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 92px;
  box-shadow: 0 1px 3px rgba(31, 36, 33, 0.04);
}

.doc-metric-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft, #5b6460);
  line-height: 1.2;
}

/* Large soft circle — match photo ~40px */
.doc-metric-ico {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: #e4f0ec;
  color: #2f6f62;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
  border: none;
}

.doc-metric-ico .erp-ico {
  width: 20px;
  height: 20px;
  display: block;
}

.doc-metric-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink, #1f2421);
  letter-spacing: 0.01em;
  padding-left: 0; /* full width under label row, not indented past icon */
  margin: 0;
  line-height: 1.25;
}

.doc-metric-value.is-zero { color: var(--ink-soft, #5b6460); }
.doc-metric-value.is-warn { color: var(--danger, #a3402f); }
.doc-metric-value.is-ok { color: var(--accent-dark, #234f45); }

/* Title icon — larger square */
.doc-erp-title-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: #e4f0ec;
  color: #2f6f62;
}
.doc-erp-title-icon .erp-ico {
  width: 22px;
  height: 22px;
}

/* Subject — multi-line expanding field */
.doc-erp .field-subject textarea,
.doc-erp textarea.field-textarea-grow,
.doc-erp .field textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line, #dedad0);
  background: #fff;
  font-size: 13.5px;
  width: 100%;
  font-family: inherit;
  color: inherit;
}

.doc-erp .field-subject textarea:focus,
.doc-erp textarea.field-textarea-grow:focus {
  border-color: var(--accent, #2f6f62);
  box-shadow: 0 0 0 3px rgba(47, 111, 98, 0.12);
  outline: none;
}

@media (max-width: 900px) {
  .doc-metrics { grid-template-columns: 1fr; }
  .doc-metric { min-height: auto; }
}
