/* KP Maker — v121 (incoming controls + mobile table fit) */
/* design-mark: v121-top-split */

:root {
  --brand: #fe5000;
  --brand-hover: #e64800;
  --brand-soft: #fff4ee;
  --brand-ring: rgba(254, 80, 0, 0.18);

  --ink: #1c1917;
  --ink-muted: #57534e;
  --ink-subtle: #a8a29e;
  --bg: #f5f3f0;
  --surface: #ffffff;
  --border: #e7e5e4;

  --md-primary: var(--brand);
  --md-on-primary: #ffffff;
  --md-primary-container: var(--brand-soft);
  --md-on-primary-container: #5c2a00;

  --md-secondary: #44403c;
  --md-on-secondary: #ffffff;
  --md-secondary-container: #f5f5f4;
  --md-on-secondary-container: #292524;

  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;

  --md-surface: #fffbff;
  --md-surface-dim: #ded8e1;
  --md-surface-bright: #fffbff;
  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #fafaf9;
  --md-surface-container: #f5f5f4;
  --md-surface-container-high: #eceae8;
  --md-surface-container-highest: #e7e5e4;

  --md-on-surface: #1c1b1f;
  --md-on-surface-variant: #49454f;
  --md-outline: #79747e;
  --md-outline-variant: #cac4d0;

  --md-inverse-surface: #313033;
  --md-inverse-on-surface: #f4eff4;

  /* Shape */
  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-xl: 24px;
  --md-shape-xxl: 28px;
  --action-delete: #fe5000;
  --action-delete-hover: #e64800;
  --card-radius-kpi: 24px;
  --card-radius-section: 16px;
  --card-radius-form: 24px;
  --field-radius: 9999px;
  --field-radius-row: 9999px;
  --design-version: 121;
  --figma-file: UZ0hbKoFmeqZSFDzo7D76b;
  --card-shadow: 0 1px 1.5px rgba(28, 25, 23, 0.06);
  --card-shadow-soft: 0 1px 1.5px rgba(28, 25, 23, 0.05);
  --field-radius-compact: var(--md-shape-md);
  --md-shape-full: 9999px;

  /* Elevation (MD3) */
  --md-elevation-0: none;
  --md-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --md-elevation-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --md-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.3);

  /* Typography scale */
  --md-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --md-title-large: 1.375rem;
  --md-title-medium: 1rem;
  --md-body-large: 1rem;
  --md-body-medium: 0.875rem;
  --md-label-large: 0.875rem;
  --md-label-medium: 0.75rem;

}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
.md-app {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  margin: 0;
  font-family: var(--md-font);
  font-size: var(--md-body-large);
  line-height: 1.5;
  letter-spacing: 0.01em;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body::before,
body::after {
  display: none;
}


/* —— Site header —— */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.site-header__inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 15px;
  padding-left: 24px;
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.site-header__logo {
  flex-shrink: 0;
  border-radius: 50%;
  box-shadow: none;
  background: none;
  animation: logo-spin 8s linear infinite;
}

@keyframes logo-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.site-header__brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
}

.site-header__tagline {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--ink-muted);
  font-weight: 500;
}


#ingest-result-text,
#ingest-list-note,
.ingest-note {
  min-height: 1.25rem;
}

tr.draft-row-new td {
  font-weight: 600;
  color: var(--ink);
}

tr.draft-row-new td:nth-child(6),
tr.draft-row-new td:nth-child(7) {
  color: var(--brand-hover);
}


.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 24px 40px;
}

.top-split {
  display: grid;
  grid-template-columns: 249px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  align-items: start;
}

.top-split > .kpi-card--inbox,
.top-split > .card--settings {
  margin-bottom: 0;
}

.card--settings {
  overflow: hidden;
  padding: 16px 23px 18px;
  border-radius: var(--card-radius-form);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow-soft);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  min-height: 249px;
  align-self: stretch;
  height: 100%;
}

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

.grid-span-2 {
  grid-column: span 2;
}

.kpi-card--inbox {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  height: 249px;
  min-height: 249px;
  max-height: 249px;
  aspect-ratio: 1 / 1;
  padding: 16px 21px 18px;
  border: none;
  border-radius: var(--card-radius-kpi);
  box-shadow: var(--card-shadow);
}

.kpi-card--inbox .kpi-label {
  transform: translateY(-5px);
}

.kpi-card--inbox .kpi-actions {
  margin-top: auto;
  padding-top: 27px;
  flex: 0 0 auto;
  height: auto;
  align-items: stretch;
  align-self: stretch;
  width: 100%;
  gap: 10px;
}

.kpi-card--inbox .kpi-actions .btn {
  flex: 0 0 42px;
  width: 100%;
  max-width: none;
  align-self: stretch;
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  padding: 0 22px;
  font-size: 14px;
  box-shadow: none;
}

.kpi-card--inbox .kpi-actions .btn:hover,
.kpi-card--inbox .kpi-actions .btn:active,
.kpi-card--inbox .kpi-actions .btn:focus-visible {
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  padding: 0 22px;
  box-shadow: none;
  filter: none;
  transform: none;
}

.kpi-card__hint {
  margin: 8px 0 0;
  min-height: 1.25rem;
  font-size: 12px;
}

.kpi-card--inbox .kpi-value {
  margin-bottom: 8px;
}

.card--settings .checkbox-label {
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  transform: translateY(4px);
  font-size: 14px;
  font-weight: 500;
  color: var(--md-on-surface);
}

.btn-inbox-link {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid rgba(254, 80, 0, 0.35);
  box-shadow: none;
}

.btn-inbox-link:hover {
  background: var(--brand-soft);
  filter: none;
  box-shadow: none;
}

.section-title {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
}

.hint {
  margin: 0 0 12px;
  font-size: var(--md-body-medium);
  color: var(--md-on-surface-variant);
}

.hint a {
  color: var(--md-primary);
  font-weight: 500;
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

/* —— KPI / dashboard cards —— */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius-kpi);
  padding: 19px 21px;
  box-shadow: var(--card-shadow);
}

.kpi-card:hover {
  transform: none;
}

.kpi-label {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
}

.kpi-value {
  margin: 0 0 12px;
  font-size: 2.25rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.kpi-card--chart .kpi-value {
  margin-bottom: 8px;
}

.kpi-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.kpi-btn {
  width: 100%;
  max-width: none;
  min-height: 42px;
  padding: 10px 22px;
  font-size: 14px;
}

.kpi-chart {
  margin-top: 12px;
  height: 88px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  padding: 8px;
  border-radius: var(--md-shape-sm);
  background: var(--md-surface-container);
}

.kpi-chart-col {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  height: 100%;
}

.kpi-chart-bar {
  width: 100%;
  max-width: 28px;
  min-height: 4px;
  border-radius: var(--md-shape-xs) var(--md-shape-xs) 0 0;
}

.kpi-chart-bar.sent {
  background: var(--md-primary);
}

.kpi-chart-bar.generated {
  background: linear-gradient(180deg, #fdba74 0%, var(--brand) 100%);
}

.kpi-chart-label {
  margin-top: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
}

/* —— Cards (elevated surfaces) —— */
.card {
  --col-item: minmax(200px, 2.2fr);
  --col-qty: 96px;
  --col-price: 112px;
  --col-sum: 120px;
  --col-action: 48px;
  --row-gap: 12px;

  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius-form);
  padding: 20px 22px;
  box-shadow: var(--card-shadow-soft);
  margin-bottom: 16px;
}

.card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.27;
  color: var(--md-on-surface);
}

.nomenclature-card {
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* —— Text fields (outlined) —— */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--md-on-surface-variant);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-height: 49px;
  padding: 12px 16px;
  font-family: var(--md-font);
  font-size: var(--md-body-large);
  font-weight: 400;
  color: var(--md-on-surface);
  background: var(--surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--field-radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:not([type="checkbox"]):focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-ring);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='%2349454f'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 40px;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  font-size: var(--md-body-medium);
  color: var(--md-on-surface);
  letter-spacing: 0.015em;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--md-primary);
  cursor: pointer;
}

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

.row-labels {
  display: grid;
  grid-template-columns: var(--col-item) var(--col-qty) var(--col-price) var(--col-sum) var(--col-action);
  gap: var(--row-gap);
  margin-bottom: 8px;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  background: transparent;
}

.row-item {
  display: grid;
  grid-template-columns: var(--col-item) var(--col-qty) var(--col-price) var(--col-sum) var(--col-action);
  gap: var(--row-gap);
  margin-bottom: 12px;
  align-items: center;
  padding: 8px 4px;
  border-radius: var(--md-shape-sm);
  transition: background 0.15s;
}

.row-item:hover {
  background: transparent;
}

.row-item > * {
  min-width: 0;
}

.row-item input,
.row-item select,
.row-item .amount {
  min-height: 48px;
  border-radius: var(--field-radius);
}

.amount {
  background: var(--surface);
  color: var(--md-on-surface);
  font-weight: 400;
  text-align: right;
  border: 1px solid var(--md-outline);
}

.field-wrap {
  width: 100%;
}

.stepper-input-wrap {
  position: relative;
  width: 100%;
}

.mobile-field-label {
  display: none;
}

.stepper-buttons {
  display: none;
}

/* —— Buttons (MD3: filled, tonal, outlined, text, error) —— */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 24px;
  font-family: var(--md-font);
  font-size: var(--md-label-large);
  font-weight: 500;
  letter-spacing: 0.006em;
  line-height: 1.25;
  color: var(--md-on-primary);
  background: var(--md-primary);
  border: none;
  border-radius: var(--md-shape-full);
  box-shadow: var(--md-elevation-0);
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
  transition: box-shadow 0.2s, background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  box-shadow: var(--md-elevation-1);
  filter: brightness(1.05);
}

.btn:active {
  box-shadow: var(--md-elevation-0);
  filter: brightness(0.95);
}

.btn.secondary {
  color: var(--md-on-secondary-container);
  background: var(--md-secondary-container);
}

.btn.secondary:hover {
  filter: brightness(0.97);
}

.btn-surface,
.btn-tonal {
  color: #292524;
  background: #f5f5f4;
  border: none;
  box-shadow: none;
}

.btn-surface:hover,
.btn-tonal:hover {
  background: #ebebea;
  filter: none;
  box-shadow: none;
}

.btn-outlined {
  color: var(--brand);
  background: transparent;
  border: 1px solid var(--md-outline);
  box-shadow: none;
  min-height: 40px;
}

.btn-outlined:hover {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
}

.btn-text {
  color: var(--md-primary);
  background: transparent;
  box-shadow: none;
  min-height: 40px;
  padding: 10px 12px;
}

.btn-text:hover {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
  box-shadow: none;
  filter: none;
}

.btn.danger {
  color: #ffffff;
  background: var(--brand);
  border: none;
  min-height: 40px;
  min-width: 132px;
  border-radius: var(--md-shape-full);
  box-shadow: none;
}

.btn.danger:hover,
.btn-preview:hover {
  background: #1c1917;
  color: #ffffff;
  filter: none;
  box-shadow: none;
}

.btn-remove-row,
.remove-row.btn-remove-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  color: #ffffff;
  background: var(--brand);
  border: none;
  border-radius: 50%;
  box-shadow: none;
  cursor: pointer;
  flex-shrink: 0;
  justify-self: end;
}

.btn-remove-row svg,
.btn-remove-row .icon-trash {
  display: inline-block;
  width: 22px;
  height: 22px;
  stroke: currentColor;
  margin: 0;
  vertical-align: middle;
  position: relative;
  top: -2px;
}

.btn-remove-row:hover,
.remove-row.btn-remove-row:hover {
  background: #1c1917;
  color: #ffffff;
  filter: none;
  box-shadow: none;
}

.btn-small {
  min-height: 42px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--md-shape-full);
  color: #292524;
  background: #f5f5f4;
  border: none;
  box-shadow: none;
}

.btn-small:hover {
  background: #ebebea;
  filter: none;
  box-shadow: none;
}

.actions {
  margin-bottom: 1.5rem;
}

#offer-form {
  display: flex;
  flex-direction: column;
}

@media (min-width: 769px) {
  #offer-form > .card:first-of-type {
    order: 1;
  }

  #offer-form > .calc-section {
    order: 2;
  }

  #offer-form > .actions--preview {
    order: 3;
  }
}

@media (max-width: 768px) {
  /* Align header brand with container/table left edge on mobile */
  .site-header__inner {
    padding-left: 0;
  }
  .review-page .site-header__inner {
    padding-left: 0;
    padding-right: 0;
  }

  #offer-form > .actions--preview {
    order: 2;
    margin: 4px 0 12px;
    width: 100%;
  }

  #offer-form > .calc-section {
    order: 3;
  }

  .actions--preview .btn-preview {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
}

.actions .btn-preview,
.btn-preview {
  width: auto;
  min-width: 185px;
  min-height: 42px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  background: var(--brand);
  border: none;
  border-radius: var(--md-shape-full);
  box-shadow: none;
}

.actions .btn-preview:hover {
  background: #1c1917;
  filter: none;
  box-shadow: none;
}

.calc-rounding-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.calc-rounding-row .hint {
  margin: 0;
  flex: 1 1 12rem;
}

.calc-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 16px;
  color: var(--ink);
}

.calc-row > span:first-child {
  font-weight: 700;
}

.calc-row .calc-value {
  font-weight: 500;
  color: #1a1a1a;
}

.calc-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid #e0e0e0;
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
}

/* —— Preview / tables —— */
.preview {
  border-top: 4px solid var(--md-primary-container);
}

.preview h2 {
  margin-bottom: 12px;
}

.preview p,
.preview-meta {
  margin: 0 0 8px;
  font-size: var(--md-body-medium);
}

.preview-table-wrap {
  margin: 12px 0;
}

.preview-totals {
  margin: 16px 0 20px;
  padding: 14px 16px;
  background: var(--md-surface-container-low);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-md);
}

.preview-totals__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--md-body-medium);
  color: var(--ink);
}

.preview-totals__row + .preview-totals__row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--md-outline-variant);
}

.preview-totals__row--total {
  font-size: 1.0625rem;
  font-weight: 600;
}

table,
.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  table-layout: fixed;
  background: var(--md-surface-container-lowest);
  border-radius: var(--md-shape-sm);
  overflow: hidden;
  box-shadow: var(--md-elevation-0);
  border: 1px solid var(--md-outline-variant);
}

th,
td {
  border-bottom: 1px solid var(--md-outline-variant);
  padding: 12px 16px;
  font-size: var(--md-body-medium);
  line-height: 1.43;
  text-align: left;
  word-break: break-word;
}

th {
  background: var(--md-surface-container-high);
  font-size: var(--md-label-medium);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
}

tr:last-child td {
  border-bottom: none;
}

.mail-send-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* —— Send email circular progress —— */
.mail-progress {
  width: 32px;
  height: 32px;
  display: none;
  flex-shrink: 0;
}

.mail-progress svg {
  width: 32px;
  height: 32px;
  transform: rotate(-90deg);
}

.mail-progress-track {
  stroke: var(--md-outline-variant);
}

.mail-progress-ring {
  stroke: #4caf50;
  stroke-linecap: round;
  stroke-dasharray: 97.39;
  stroke-dashoffset: 97.39;
  transition: stroke-dashoffset 0.25s linear, stroke 0.2s ease;
}

.mail-progress.show {
  display: inline-block;
}

.mail-progress.success .mail-progress-ring {
  stroke: #2e7d32;
}

.mail-progress.error .mail-progress-ring {
  stroke: var(--md-error);
}

#send-btn.success {
  background: #2e7d32 !important;
  color: #ffffff !important;
}

#send-btn.error {
  background: #c62828 !important;
  color: #ffffff !important;
}

/* —— Access page —— */
.access-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.access-card {
  width: min(92vw, 400px);
  padding: 24px;
  background: var(--md-surface-container-lowest);
  border-radius: var(--md-shape-lg);
  box-shadow: var(--md-elevation-3);
}

.access-card h1 {
  margin: 0 0 8px;
  font-size: var(--md-title-large);
  font-weight: 400;
}

.access-card p {
  margin: 0 0 16px;
  color: var(--md-on-surface-variant);
  font-size: var(--md-body-medium);
}

.access-card .err {
  color: var(--md-error);
  font-size: var(--md-body-medium);
  margin-bottom: 12px;
}

.access-card .btn {
  width: 100%;
  margin-top: 16px;
  min-height: 48px;
}

/* —— Review pages —— */
.review-page {
  padding: 0;
}

/* Inbox: align header with table left edge (full-width layout, 24px container padding) */
.review-page .site-header__inner {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

.review-page .site-header__brand {
  margin-left: 8px;
}

.review-layout .actions {
  margin-left: 3px !important;
}

.review-layout {
  max-width: none !important;
  padding-bottom: 32px;
}

@media (min-width: 769px) {
  .review-layout {
    margin-top: -12px;
  }
}

.review-layout .actions {
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.review-layout .actions form {
  display: inline-flex;
}

.review-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 20px;
  border: none;
  border-radius: var(--md-shape-sm);
  background: var(--md-surface-container-lowest);
  box-shadow: 0 2px 8px rgba(28, 25, 23, 0.10);
}

.review-layout table,
.review-layout #drafts-table {
  margin: 0;
  width: 100%;
  min-width: 1060px;
  table-layout: fixed;
}

#drafts-table th,
#drafts-table td {
  white-space: nowrap;
  vertical-align: middle;
}

#drafts-table th:nth-child(1),
#drafts-table td:nth-child(1) {
  width: 48px;
  text-align: center;
}

#drafts-table th:nth-child(2),
#drafts-table td:nth-child(2) {
  width: 58px;
}

#drafts-table th:nth-child(3),
#drafts-table td:nth-child(3) {
  width: 160px;
}

#drafts-table th:nth-child(4),
#drafts-table td:nth-child(4) {
  width: 160px;
}

#drafts-table th:nth-child(5),
#drafts-table td:nth-child(5) {
  width: 110px;
}

#drafts-table th:nth-child(8),
#drafts-table td:nth-child(8) {
  width: 144px;
}

#drafts-table th:nth-child(9),
#drafts-table td:nth-child(9) {
  width: 220px;
}

.inbox-cell {
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-cell--sender {
  max-width: 230px;
}

.inbox-cell--subject {
  max-width: 320px;
}

.inbox-actions {
  white-space: nowrap;
}

.review-layout__title {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.review-layout__lead {
  margin: 0 0 16px;
  color: var(--ink-muted);
  font-size: var(--md-body-medium);
  max-width: 52ch;
}

.review-page > h1 {
  margin: 16px 16px 4px;
  font-size: 1.5rem;
  font-weight: 600;
}

.review-page > p {
  margin: 0 16px 16px;
  color: var(--ink-muted);
  font-size: var(--md-body-medium);
}

.review-page .actions {
  margin: 0 16px 16px;
  padding: 0;
}

.review-page .actions form {
  display: inline-flex;
}

.review-page table {
  margin: 0 16px 24px;
  width: calc(100% - 32px);
}

.review-page .btn,
.review-page button:not(.step-btn) {
  min-height: 40px;
  min-width: 138px;
}

.review-page .ok {
  color: var(--md-on-primary);
  background: var(--brand);
}

.review-page .bad,
.review-page .danger {
  color: #292524;
  background: #f5f5f4;
}

.review-page .back {
  text-decoration: none;
}

.review-page .aux {
  color: #292524;
  background: #f5f5f4;
}

.review-page td .btn {
  min-width: 102px;
  padding: 8px 14px;
}

.review-page td .btn + .btn {
  margin-left: 8px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 12px;
  border-radius: var(--md-shape-full);
  font-size: var(--md-label-medium);
  font-weight: 500;
}

.status-ready-for-review {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

.status-needs-clarification {
  background: #fff8e1;
  color: #5d4200;
}

.status-approved {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

.status-sent {
  background: #e8f5e9;
  color: #1b5e20;
}

.status-rejected {
  background: var(--md-error-container);
  color: var(--md-on-error-container);
}

.reply-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: var(--md-shape-full);
  font-size: var(--md-label-medium);
  font-weight: 500;
}

.reply-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.reply-sent {
  background: #e8f5e9;
  color: #1b5e20;
}

.reply-sent::before {
  background: #2e7d32;
}

.reply-generator {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

.reply-generator::before {
  background: var(--md-secondary);
}

.reply-pending {
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface-variant);
}

.reply-pending::before {
  background: var(--md-outline);
}

.review-detail .meta {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr;
  gap: 8px 16px;
  margin: 0 16px 16px;
}

.review-detail .meta-label {
  color: var(--md-on-surface-variant);
  font-size: var(--md-label-medium);
  font-weight: 500;
}

.review-detail .text-block {
  background: var(--md-surface-container);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-sm);
  padding: 20px 24px;
  line-height: 1.5;
}

.preview-block {
  overflow: visible !important;
}

.preview-meta {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 16px;
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.preview-meta dt {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  padding-top: 2px;
  align-self: start;
}

.preview-meta dd {
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  margin: 0;
  word-break: break-word;
}

.review-detail .pdf-preview-wrap {
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-shape-md);
  overflow: hidden;
  box-shadow: var(--md-elevation-1);
}

.review-detail .pdf-preview {
  width: 100%;
  height: 78vh;
  min-height: 480px;
  border: 0;
  background: var(--md-surface-container-lowest);
}

.review-detail .ingest-note {
  margin: 0;
  font-size: var(--md-body-medium);
  color: var(--md-on-surface-variant);
}

.review-detail .preview-total {
  margin-top: 12px;
  font-size: var(--md-title-medium);
  font-weight: 500;
}

.review-detail input[type="text"] {
  min-height: 48px;
  margin-right: 8px;
}

.review-detail .card {
  margin: 0 16px 16px;
}

.review-detail .actions + .card {
  margin-top: 22px;
}

.review-detail .card h3 {
  margin: 0 0 12px;
  font-size: var(--md-title-medium);
  font-weight: 500;
  color: var(--md-on-surface);
}

.review-detail .actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.review-detail .actions form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.review-detail .actions .btn {
  min-width: 168px;
  min-height: 42px;
}

.review-detail #approve-btn {
  color: #ffffff;
  background: var(--brand);
}

.review-detail #approve-btn:hover {
  background: #1c1917;
  color: #ffffff;
  filter: none;
}

.review-detail .actions form .btn.btn-surface {
  color: #292524;
  background: #f5f5f4;
}

.review-detail .actions form .btn.btn-surface:hover {
  background: #ebebea;
  color: #292524;
  filter: none;
}

.review-detail .progress-wrap {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.review-detail .progress-ring {
  width: 32px;
  height: 32px;
  transform: rotate(-90deg);
}

.review-detail .progress-bg {
  fill: none;
  stroke: var(--md-outline-variant);
  stroke-width: 4;
}

.review-detail .progress-fill {
  fill: none;
  stroke: var(--md-primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 75.4;
  stroke-dashoffset: 75.4;
  transition: stroke-dashoffset 0.25s linear, stroke 0.2s linear;
}

.review-detail .progress-text {
  font-size: var(--md-body-medium);
  color: var(--md-on-surface-variant);
}

/* —— Responsive —— */
@media (max-width: 900px) {
  .top-split {
    grid-template-columns: 1fr;
  }

  .kpi-card--inbox {
    height: auto;
    min-height: 232px;
    max-height: none;
    aspect-ratio: auto;
  }

  .card--settings {
    min-height: 0;
    height: auto;
  }

  .card--settings .checkbox-label {
    transform: translateY(4px);
    margin-top: 4px;
  }

  .grid--settings {
    grid-template-columns: 1fr;
  }

  .grid-span-2 {
    grid-column: 1 / -1;
  }

  .kpi-btn {
    max-width: none;
  }

  .kpi-value {
    font-size: 1.75rem;
  }

  .card {
    --col-item: minmax(160px, 1fr);
    --col-qty: 80px;
    --col-price: 96px;
    --col-sum: 100px;
    --col-action: 120px;
  }

  .review-layout .actions {
    align-items: stretch;
  }

  .review-layout .actions .btn,
  .review-layout .actions form {
    width: 100%;
  }

  .review-layout .actions form .btn {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .top-app-bar {
    flex-wrap: wrap;
    min-height: 56px;
  }

  .top-app-bar__title {
    font-size: 1.125rem;
  }

  .container {
    padding: 12px 12px 24px;
  }

  .card--settings input[type="date"],
  .card--settings input:not([type="checkbox"]),
  .card--settings select {
    width: 100%;
    max-width: 100%;
    min-height: 48px;
    box-sizing: border-box;
  }

  .card--settings input[type="date"] {
    display: block;
    appearance: none;
    -webkit-appearance: none;
    line-height: 1.25;
    padding: 12px 16px;
  }

  .rows-header {
    flex-wrap: wrap;
  }

  .rows-header .btn {
    width: 100%;
  }

  .row-labels {
    display: none;
  }

  .row-item {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "item item"
      "qty price"
      "amount action";
    gap: 8px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    margin-bottom: 12px;
  }

  .row-item > :nth-child(1) {
    grid-area: item;
  }

  .row-item > :nth-child(2) {
    grid-area: qty;
  }

  .row-item > :nth-child(3) {
    grid-area: price;
  }

  .row-item > :nth-child(4) {
    grid-area: amount;
  }

  .row-item > :nth-child(5) {
    grid-area: action;
  }

  .mobile-field-label {
    display: block;
    font-size: var(--md-label-medium);
    font-weight: 500;
    color: var(--md-on-surface-variant);
    margin-bottom: 4px;
  }

  .stepper-input-wrap input[type="number"] {
    padding-right: 84px;
    min-height: 48px;
    background: var(--surface);
  }

  .stepper-buttons {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .step-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #f5f5f4;
    color: var(--ink-muted);
    font-size: 17px;
    font-weight: 300;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-font-smoothing: antialiased;
  }

  .step-btn:active {
    background: #ebebea;
  }

  .field-wrap {
    background: transparent;
  }

  .row-item .btn-remove-row {
    margin-left: auto;
  }

  input,
  select {
    font-size: 16px;
  }

  .preview-table-wrap {
    margin: 12px 0 0;
  }

  .preview-table {
    border: none;
    box-shadow: none;
    background: transparent;
    margin: 0;
  }

  .preview-table thead {
    display: none;
  }

  .preview-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .preview-table tr {
    display: block;
    width: 100%;
    margin: 0;
    padding: 12px 14px;
    background: var(--md-surface-container-lowest);
    border: 1px solid var(--md-outline-variant);
    border-radius: var(--md-shape-md);
    box-shadow: none;
  }

  .preview-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    width: 100%;
    border: 0;
    padding: 7px 0;
  }

  .preview-table td:last-child {
    border-bottom: 0;
    font-weight: 600;
  }

  .preview-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: var(--md-label-medium);
    font-weight: 500;
    color: var(--md-on-surface-variant);
    margin: 0;
  }

  .review-table-wrap {
    margin: 0 -2px 16px;
    border-radius: var(--md-shape-md);
  }

  #drafts-table {
    min-width: 940px;
  }
}

@media (max-width: 420px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .row-item {
    grid-template-columns: 1fr;
    grid-template-areas:
      "item"
      "qty"
      "price"
      "amount"
      "action";
  }

  .mail-send-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* —— Access gate —— */
.access-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: transparent;
}

.access-gate__card {
  width: min(100%, 400px);
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--md-shape-xl);
  box-shadow: 0 12px 40px rgba(28, 25, 23, 0.1);
  text-align: center;
}

.access-gate__logo {
  margin: 0 auto 16px;
  border-radius: 12px;
  box-shadow: 0 4px 16px var(--brand-ring);
}

.access-gate__card h1 {
  margin: 0 0 8px;
  font-size: 1.375rem;
  font-weight: 600;
}

.access-gate__card > p {
  margin: 0 0 20px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.access-gate__field {
  display: block;
  text-align: left;
  margin-bottom: 16px;
}

.access-gate__field span {
  display: block;
  margin-bottom: 6px;
  font-size: var(--md-label-medium);
  font-weight: 500;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.access-gate__field input {
  width: 100%;
}

.access-gate__card .btn {
  width: 100%;
  min-height: 48px;
}

.access-gate__err {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--md-shape-sm);
  background: var(--md-error-container);
  color: var(--md-error);
  font-size: 0.875rem;
  text-align: left;
}

/* --- v74 corrective override incoming UI --- */
.review-layout .actions {
  display: flex !important;
  gap: 12px !important;
  align-items: center !important;
  flex-wrap: wrap !important;
}

.review-layout .actions .btn,
.review-layout .actions form .btn {
  min-height: 42px !important;
  padding: 10px 20px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  border-radius: 9999px !important;
}

.review-layout .actions .btn.btn-surface {
  background: #ebebea !important;
  color: #292524 !important;
  border: none !important;
  box-shadow: none !important;
}

.review-layout .actions form .btn:not(.btn-surface) {
  background: var(--brand) !important;
  color: #ffffff !important;
}

.review-table-wrap {
  overflow: hidden !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--card-radius-form) !important;
  background: var(--surface) !important;
  box-shadow: var(--card-shadow-soft) !important;
}

#drafts-table tbody td {
  background: #ffffff !important;
}

#drafts-table th {
  background: var(--md-surface-container-high) !important;
}

#drafts-table th,
#drafts-table td {
  border-bottom: 1px solid #f0edeb !important;
}

#drafts-table tr:last-child td {
  border-bottom: none !important;
}


#drafts-table {
  width: 100% !important;
  min-width: 1400px !important;
  table-layout: fixed !important;
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

/* Column widths */
#drafts-table th:nth-child(1),
#drafts-table td:nth-child(1) { width: 48px !important; padding-left: 16px !important; overflow: visible !important; }  /* checkbox */
#drafts-table th:nth-child(2),
#drafts-table td:nth-child(2) { width: 32px !important; }   /* № */
#drafts-table th:nth-child(3),
#drafts-table td:nth-child(3) { width: 12% !important; }    /* Ответ */
#drafts-table th:nth-child(4),
#drafts-table td:nth-child(4) { width: 12% !important; }    /* Статус */
#drafts-table th:nth-child(5),
#drafts-table td:nth-child(5) { width: 7% !important; }     /* Контекст */
#drafts-table th:nth-child(6),
#drafts-table td:nth-child(6) { width: 15% !important; }    /* Отправитель */
#drafts-table th:nth-child(7),
#drafts-table td:nth-child(7) { width: 12% !important; }    /* Создан */
#drafts-table th:nth-child(8),
#drafts-table td:nth-child(8) { width: 22% !important; }    /* Тема */
#drafts-table th:nth-child(9),
#drafts-table td:nth-child(9) { width: 10% !important; padding-right: 20px !important; } /* Действие */

#drafts-table th,
#drafts-table td {
  white-space: nowrap !important;
  vertical-align: middle !important;
  padding: 16px 10px !important;
  font-size: 13px !important;
  line-height: 1.35 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

#drafts-table td.inbox-actions {
  overflow: visible !important;
  white-space: nowrap !important;
}

/* Action button in table */
.inbox-action-btn {
  min-height: 36px !important;
  padding: 6px 18px !important;
  border-radius: 9999px !important;
  font-size: 13px !important;
}

#drafts-table th {
  white-space: nowrap !important;
  font-size: 11px !important;
  letter-spacing: 0.03em !important;
}

.inbox-cell--sender,
.inbox-cell--subject {
  max-width: none !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.inbox-actions {
  white-space: nowrap !important;
}

.inbox-actions .btn {
  min-width: 0 !important;
  min-height: 42px !important;
  padding: 10px 18px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  border-radius: 9999px !important;
  color: #292524 !important;
  background: #f5f5f4 !important;
  border: none !important;
  box-shadow: none !important;
}

.inbox-actions .btn:hover {
  background: #ebebea !important;
  filter: none !important;
}

.inbox-actions .btn + .btn {
  margin-left: 6px !important;
}

.review-detail .actions {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  flex-wrap: wrap !important;
}

.review-detail .actions form {
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
}

.review-detail .actions .btn {
  min-height: 42px !important;
  min-width: 176px !important;
  padding: 10px 22px !important;
  border-radius: 9999px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
}

.review-detail #approve-btn {
  background: var(--brand) !important;
  color: #ffffff !important;
}

.review-detail #approve-btn:hover {
  background: #1c1917 !important;
}

.review-detail .actions form .btn.btn-surface {
  background: #f5f5f4 !important;
  color: #292524 !important;
}

.review-detail .actions + .card {
  margin-top: 26px !important;
}

@media (max-width: 768px) {
  #drafts-table {
    min-width: 920px !important;
  }

  .review-detail .actions .btn {
    min-width: 100% !important;
  }
}

/* --- v75 precise fixes from screenshots --- */
.review-detail .actions .btn {
  border-radius: 9999px !important;
  min-height: 42px !important;
  padding: 10px 24px !important;
  font-family: var(--md-font) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  line-height: 1.25 !important;
}

/* "Назад к входящим" — оранжевая primary */
.review-detail .actions a.btn.back {
  background: var(--brand) !important;
  color: #ffffff !important;
  min-width: 0 !important;
}
.review-detail .actions a.btn.back:hover {
  background: #1c1917 !important;
  color: #ffffff !important;
  filter: none !important;
}

.review-detail #approve-btn {
  background: var(--brand) !important;
  color: #ffffff !important;
}

.review-detail #approve-btn:hover {
  background: #1c1917 !important;
  color: #ffffff !important;
  filter: none !important;
}

/* "Отклонить" — серая pill */
.review-detail .actions form .btn.btn-surface {
  background: #ebebea !important;
  color: #292524 !important;
  border: none !important;
  box-shadow: none !important;
  min-width: 0 !important;
}

.review-detail .actions form .btn.btn-surface:hover {
  background: #d6d3d1 !important;
  color: #292524 !important;
  filter: none !important;
}

.review-detail .aux {
  background: #f5f5f4 !important;
  color: #292524 !important;
  border-radius: 9999px !important;
  min-height: 42px !important;
  padding: 10px 24px !important;
  font-family: var(--md-font) !important;
  font-size: 14px !important;
  font-weight: 500 !important;
}

@media (max-width: 768px) {
  .review-table-wrap {
    overflow-x: hidden !important;
  }

  #drafts-table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: fixed !important;
  }

  #drafts-table th,
  #drafts-table td {
    font-size: 13px !important;
    padding: 12px 8px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Mobile: show only №, Отправитель, Создан, Действие */
  #drafts-table th:nth-child(1),
  #drafts-table td:nth-child(1),
  #drafts-table th:nth-child(3),
  #drafts-table td:nth-child(3),
  #drafts-table th:nth-child(4),
  #drafts-table td:nth-child(4),
  #drafts-table th:nth-child(5),
  #drafts-table td:nth-child(5),
  #drafts-table th:nth-child(8),
  #drafts-table td:nth-child(8) {
    display: none !important;
  }

  /* Mobile column widths: №, Отправитель, Дата, Кнопка */
  #drafts-table th:nth-child(2),
  #drafts-table td:nth-child(2) { width: 32px !important; padding-left: 12px !important; }
  #drafts-table th:nth-child(6),
  #drafts-table td:nth-child(6) { width: auto !important; }
  #drafts-table th:nth-child(7),
  #drafts-table td:nth-child(7) { width: 110px !important; }
  #drafts-table th:nth-child(9),
  #drafts-table td:nth-child(9) { width: 90px !important; padding-right: 12px !important; overflow: visible !important; }

  .inbox-actions .btn {
    min-width: 76px !important;
    min-height: 34px !important;
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
}
