:root {
  --paper: #f5f3ee;
  --surface: #fffefb;
  --surface-2: #ebe8e1;
  --ink: #202522;
  --muted: #6f746f;
  --line: #d9d6cf;
  --accent: #d7482f;
  --accent-dark: #ad2f20;
  --green: #23724c;
  --green-pale: #e1f0e6;
  --amber: #9a6318;
  --amber-pale: #fff1d8;
  --blue-pale: #e8eff3;
  --shadow: 0 16px 50px rgba(36, 39, 36, .08);
  --radius: 3px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(56, 61, 57, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 61, 57, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

a { color: inherit; }

.topbar {
  min-height: 74px;
  padding: 12px clamp(18px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 243, 238, .9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
}

.brand-mark svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: .08em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.autoplay-button {
  min-height: 38px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .15s;
}

.autoplay-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.autoplay-button:active { transform: translateY(1px); }

.autoplay-button svg {
  width: 15px;
  fill: currentColor;
}

.autoplay-button.is-running {
  border-color: var(--ink);
  background: var(--ink);
}

.autoplay-button.is-running svg path {
  d: path("M6 5h3v10H6zm5 0h3v10h-3z");
}

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

.safe-badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-pale);
}

.ghost-button,
.text-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.ghost-button {
  padding: 8px 0;
  border-bottom: 1px solid currentColor;
}

.autoplay-strip {
  position: fixed;
  left: 0;
  right: 0;
  top: 74px;
  z-index: 9;
  padding: 9px clamp(18px, 4vw, 64px) 0;
  color: white;
  background: var(--ink);
  transform: translateY(-110%);
  visibility: hidden;
  transition: transform .3s, visibility .3s;
}

body.is-autoplaying .autoplay-strip {
  transform: translateY(0);
  visibility: visible;
}

.autoplay-caption {
  min-height: 27px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  font-size: 11px;
}

.autoplay-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #ffb9ab;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.autoplay-live i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(215, 72, 47, .18);
}

body.is-autoplay-paused .autoplay-live i { animation: none; opacity: .45; }
body.is-autoplaying:not(.is-autoplay-paused) .autoplay-live i { animation: livePulse 1.25s infinite; }

.autoplay-caption strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#autoplayTime {
  color: #aeb4af;
  font-variant-numeric: tabular-nums;
}

.autoplay-track {
  height: 3px;
  margin-top: 3px;
  background: #3f4541;
}

.autoplay-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .1s linear;
}

@keyframes livePulse {
  50% { opacity: .45; transform: scale(.8); }
}

main {
  width: min(1540px, calc(100% - 48px));
  margin: 0 auto;
  padding: clamp(38px, 6vw, 82px) 0 58px;
}

.intro {
  display: grid;
  grid-template-columns: 1.25fr .75fr;
  gap: clamp(32px, 6vw, 100px);
  align-items: end;
  margin-bottom: 52px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1 {
  max-width: 960px;
  margin: 0;
  font-size: clamp(40px, 5.7vw, 86px);
  line-height: .96;
  letter-spacing: -.055em;
  font-weight: 680;
}

.intro-copy {
  max-width: 490px;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: clamp(15px, 1.3vw, 18px);
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(255, 254, 251, .5);
}

.step {
  min-height: 72px;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #9b9e99;
  border-right: 1px solid var(--line);
  transition: color .25s, background .25s;
}

.step:last-child { border-right: 0; }

.step > span {
  font-size: 11px;
  font-weight: 800;
}

.step strong, .step small { display: block; }
.step small { font-size: 11px; margin-top: 2px; }
.step.is-active { color: var(--ink); background: var(--surface); }
.step.is-active > span { color: var(--accent); }
.step.is-done { color: var(--green); background: var(--green-pale); }

.workspace {
  display: grid;
  grid-template-columns: .95fr 1.15fr .9fr;
  align-items: start;
  border: 1px solid var(--line);
  background: var(--line);
  gap: 1px;
  box-shadow: var(--shadow);
}

.panel {
  min-width: 0;
  min-height: 682px;
  padding: 24px;
  background: var(--surface);
  position: relative;
  transition: box-shadow .28s, transform .28s, outline-color .28s;
}

.panel.is-auto-focus {
  z-index: 4;
  outline: 3px solid rgba(215, 72, 47, .7);
  outline-offset: -3px;
  box-shadow: 0 18px 60px rgba(91, 38, 27, .22);
  transform: translateY(-3px);
}

.panel.is-auto-focus::before {
  content: "Сейчас";
  position: absolute;
  right: 12px;
  top: -12px;
  z-index: 7;
  padding: 4px 8px;
  background: var(--accent);
  color: white;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.auto-pulse {
  position: relative;
  z-index: 5;
  animation: autoPulse 1.25s ease-in-out 2;
}

@keyframes autoPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(215, 72, 47, 0); }
  50% { box-shadow: 0 0 0 7px rgba(215, 72, 47, .2); }
}

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

.panel h2,
.dialog-shell h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
  letter-spacing: -.025em;
}

.status {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.status-new { color: var(--accent-dark); background: #f7e4df; }
.status-review { color: var(--amber); background: var(--amber-pale); }
.status-done { color: var(--green); background: var(--green-pale); }

.mail-meta {
  padding: 16px 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: white;
  font-size: 11px;
  font-weight: 800;
}

.mail-meta strong,
.mail-meta a { display: block; }
.mail-meta a, .mail-meta time { color: var(--muted); font-size: 11px; }
.mail-meta time { align-self: start; }

.mail-panel h3 {
  margin: 24px 0 15px;
  font-size: 17px;
}

.mail-body {
  color: #414640;
  font-size: 13px;
}

.mail-body p { margin: 0 0 12px; }
.mail-body ul { margin: 0 0 12px; padding-left: 18px; }
.mail-body li { margin: 5px 0; }

.attachment {
  margin: 18px 0;
  padding: 11px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #faf9f5;
}

.file-icon {
  width: 34px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-size: 9px;
  font-weight: 900;
}

.attachment strong, .attachment small { display: block; }
.attachment strong { font-size: 12px; }
.attachment small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.check-icon { color: var(--green); font-weight: 900; }

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 11px 16px;
  border: 1px solid transparent;
  font-weight: 750;
  cursor: pointer;
  transition: background .2s, color .2s, transform .15s, opacity .2s;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: white;
  background: var(--accent);
}

.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.primary-button:active:not(:disabled), .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .35; cursor: not-allowed; }
.primary-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; }

.secondary-button {
  border-color: var(--ink);
  background: transparent;
  color: var(--ink);
}

.secondary-button:hover { background: var(--ink); color: white; }
.full-width { width: 100%; }

.text-button {
  min-height: 42px;
  margin-top: 6px;
  color: var(--accent-dark);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.is-locked > .panel-content {
  opacity: 0;
  pointer-events: none;
}

.panel-lock {
  position: absolute;
  inset: 0;
  z-index: 3;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    repeating-linear-gradient(-45deg, rgba(45, 49, 46, .018) 0 8px, transparent 8px 16px),
    var(--surface);
  transition: opacity .25s, visibility .25s;
}

.panel:not(.is-locked) .panel-lock {
  opacity: 0;
  visibility: hidden;
}

.lock-symbol {
  width: 58px;
  height: 58px;
  margin-bottom: 16px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  color: #a2a49f;
  font-weight: 800;
  font-size: 12px;
}

.panel-lock strong { font-size: 17px; }
.panel-lock p { max-width: 230px; margin: 6px 0; color: var(--muted); font-size: 12px; }

.confidence {
  padding: 14px;
  background: var(--blue-pale);
  margin-bottom: 17px;
}

.confidence > div:first-child {
  display: flex;
  justify-content: space-between;
  color: #506169;
  font-size: 11px;
}

.confidence strong { font-size: 13px; color: var(--ink); }
.confidence-track { height: 3px; margin-top: 9px; background: #c8d5db; }
.confidence-track i { display: block; width: 92%; height: 100%; background: var(--green); transform: scaleX(0); transform-origin: left; transition: transform .8s .2s; }
.order-panel:not(.is-locked) .confidence-track i { transform: scaleX(1); }

.company-data {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0 0 20px;
  background: var(--line);
  border: 1px solid var(--line);
}

.company-data div {
  min-width: 0;
  padding: 10px;
  background: var(--surface);
}

.company-data dt {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.company-data dd { margin: 3px 0 0; font-weight: 700; font-size: 12px; }

.table-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 8px;
}

.table-heading h3, .audit-log h3 { margin: 0; font-size: 13px; }
.table-heading span { color: var(--muted); font-size: 10px; }

.product-list { border-top: 1px solid var(--line); }

.product-row {
  min-height: 59px;
  padding: 9px 4px;
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.product-row input { position: absolute; opacity: 0; pointer-events: none; }

.custom-check,
.confirm-box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid #aaa;
  color: transparent;
  font-size: 10px;
  transition: .2s;
}

.product-row input:checked + .custom-check,
.manager-confirm input:checked + .confirm-box {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.product-info { min-width: 0; }
.product-info strong, .product-info small { display: block; }
.product-info strong { font-size: 11px; }
.product-info small { color: var(--green); font-size: 9px; margin-top: 2px; }
.needs-attention .product-info small { color: var(--amber); }
.qty { text-align: right; font-weight: 800; font-size: 11px; white-space: nowrap; }
.qty small { color: var(--muted); font-weight: 500; }

.warning-box {
  margin: 13px 0;
  padding: 11px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  background: var(--amber-pale);
  color: #654312;
}

.warning-box svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.warning-box strong { font-size: 11px; }
.warning-box p { margin: 2px 0 0; font-size: 9px; }

.manager-confirm {
  margin: 12px 0;
  padding: 9px 0;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

.manager-confirm input { position: absolute; opacity: 0; }
.manager-confirm strong, .manager-confirm small { display: block; }
.manager-confirm strong { font-size: 11px; }
.manager-confirm small { color: var(--muted); font-size: 9px; }

.success-block {
  margin-bottom: 17px;
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--green);
  background: var(--green-pale);
}

.success-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-weight: 900;
}

.success-block strong { font-size: 12px; }
.success-block p { margin: 2px 0 0; font-size: 9px; }

.crm-card {
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.crm-title {
  padding: 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  background: #faf9f5;
}

.crm-title > span {
  padding: 3px 5px;
  background: var(--ink);
  color: white;
  font-size: 8px;
  font-weight: 900;
}

.crm-title strong { font-size: 11px; }
.crm-card dl { margin: 0; padding: 4px 11px; }

.crm-card dl div {
  padding: 8px 0;
  display: grid;
  grid-template-columns: .8fr 1.2fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.crm-card dl div:last-child { border-bottom: 0; }
.crm-card dt { color: var(--muted); font-size: 9px; }
.crm-card dd { margin: 0; font-size: 9px; font-weight: 700; text-align: right; }

.stage-pill { padding: 3px 5px; color: var(--amber); background: var(--amber-pale); }

.document-card {
  margin-bottom: 12px;
  padding: 11px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
}

.document-icon {
  width: 34px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: white;
  font-weight: 900;
}

.document-card strong, .document-card small { display: block; }
.document-card strong { font-size: 11px; }
.document-card small { color: var(--muted); font-size: 9px; margin-top: 2px; }
.draft-label { color: var(--accent); font-size: 8px; font-weight: 900; transform: rotate(-5deg); }

.audit-log {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.audit-log h3 { margin-bottom: 7px; }
.audit-log p { margin: 0; padding: 4px 0; display: grid; grid-template-columns: 38px 1fr; color: var(--muted); font-size: 9px; }
.audit-log time { font-variant-numeric: tabular-nums; color: var(--ink); }

.summary {
  margin-top: 80px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.summary-grid article { padding: clamp(22px, 3vw, 38px); background: var(--surface); }
.summary-grid span { display: block; margin-bottom: 34px; color: var(--accent); font-size: 11px; font-weight: 800; }
.summary-grid strong { font-size: clamp(16px, 1.5vw, 21px); }
.summary-grid p { margin: 9px 0 0; color: var(--muted); }
.demo-note { margin: 18px 0 0; color: var(--muted); font-size: 11px; }

dialog {
  width: min(860px, calc(100% - 30px));
  max-height: calc(100vh - 30px);
  padding: 0;
  border: 0;
  background: transparent;
}

dialog::backdrop { background: rgba(25, 28, 26, .74); backdrop-filter: blur(3px); }

.dialog-shell { padding: 28px; background: var(--paper); position: relative; }
.dialog-small { width: min(540px, 100%); margin: auto; }
.dialog-close { position: absolute; right: 14px; top: 10px; width: 36px; height: 36px; border: 0; background: transparent; font-size: 28px; cursor: pointer; z-index: 2; }

.paper {
  min-height: 490px;
  padding: clamp(24px, 5vw, 54px);
  overflow: hidden;
  position: relative;
  background: white;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .08);
}

.watermark {
  position: absolute;
  left: 50%;
  top: 50%;
  color: rgba(215, 72, 47, .08);
  font-size: clamp(38px, 8vw, 78px);
  font-weight: 900;
  white-space: nowrap;
  transform: translate(-50%, -50%) rotate(-25deg);
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 25px;
  border-bottom: 3px solid var(--ink);
}

.invoice-head strong, .invoice-head span, .invoice-head small { display: block; }
.invoice-head strong, .invoice-head span { font-size: 15px; font-weight: 850; }
.invoice-head small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.invoice-head > div:last-child { text-align: right; }

.invoice-parties { padding: 18px 0; }
.invoice-parties p { margin: 7px 0; display: grid; grid-template-columns: 100px 1fr; font-size: 11px; }
.invoice-parties span { color: var(--muted); }

.paper table { width: 100%; border-collapse: collapse; font-size: 10px; position: relative; z-index: 1; }
.paper th, .paper td { padding: 9px; border: 1px solid #bbb; text-align: left; }
.paper th { background: #efefec; font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.paper td:first-child { width: 38px; }
.invoice-footer { margin-top: 24px; color: var(--accent-dark); font-size: 10px; font-weight: 700; }

.reply-preview {
  margin: 22px 0;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.reply-preview p { margin: 0 0 12px; }
.reply-preview p:last-child { margin-bottom: 0; }

.is-loading .panel-content { opacity: .35; }

.is-loading::after {
  content: "Распознаём письмо и вложение…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 254, 251, .8);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
}

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 1fr 1fr; }
  .result-panel { grid-column: 1 / -1; min-height: 540px; }
  .result-panel .panel-content { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .result-panel .panel-header { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar { position: static; padding: 12px 18px; }
  .safe-badge { display: none; }
  .autoplay-strip { top: 0; }
  .ghost-button { font-size: 12px; }
  main { width: min(100% - 28px, 620px); padding-top: 36px; }
  .intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 36px; }
  h1 { font-size: clamp(40px, 13vw, 64px); }
  h1 br { display: none; }
  .steps { grid-template-columns: 1fr; border-bottom: 1px solid var(--line); }
  .step { min-height: 58px; border-right: 0; border-bottom: 1px solid var(--line); }
  .step:last-child { border-bottom: 0; }
  .workspace { display: block; background: transparent; border: 0; box-shadow: none; }
  .panel { min-height: auto; margin-bottom: 14px; border: 1px solid var(--line); }
  .panel.is-locked { min-height: 260px; }
  .result-panel .panel-content { display: block; }
  .summary { margin-top: 48px; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-grid span { margin-bottom: 15px; }
}

@media (max-width: 440px) {
  .brand small { display: none; }
  .brand strong { font-size: 13px; }
  .brand-mark { width: 34px; height: 34px; }
  .topbar-actions { gap: 8px; }
  .autoplay-button { width: 38px; padding: 0; justify-content: center; }
  .autoplay-button span { display: none; }
  .ghost-button { display: none; }
  .autoplay-caption { grid-template-columns: auto 1fr; }
  #autoplayTime { display: none; }
  .panel { padding: 18px; }
  .panel-header { display: block; }
  .panel-header .status { margin-top: 10px; }
  .company-data { grid-template-columns: 1fr; }
  .product-row { grid-template-columns: 20px 1fr; }
  .qty { grid-column: 2; text-align: left; }
  .invoice-head { display: block; }
  .invoice-head > div:last-child { margin-top: 16px; text-align: left; }
  .dialog-shell { padding: 12px; }
  .paper { padding: 22px 14px; overflow-x: auto; }
  .paper table { min-width: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
