:root {
  --ink: #1e1b24;
  --muted: #706b76;
  --paper: #f6f4f0;
  --surface: #fff;
  --line: #ded9e2;
  --violet: #5b3d79;
  --violet-dark: #3d2854;
  --violet-soft: #eee8f4;
  --green: #176a4c;
  --green-soft: #e3f2eb;
  --danger: #9a3742;
  font-family: Inter, "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 0;
  background:
    radial-gradient(circle at 74% 9%, rgba(91, 61, 121, .055), transparent 25rem),
    var(--paper);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; }
.hidden { display: none !important; }

.staff-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 0 max(24px, calc((100vw - 1220px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 247, .94);
  box-shadow: 0 1px 0 rgba(30, 27, 36, .025);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 16px; color: inherit; text-decoration: none; }
.brand img { width: 116px; height: 40px; object-fit: contain; }
.brand span { padding-left: 16px; border-left: 1px solid var(--line); font-size: 14px; font-weight: 650; letter-spacing: -.01em; }
nav { display: flex; gap: 28px; }
nav a { position: relative; color: var(--ink); font-size: 14px; font-weight: 650; text-decoration: none; }
nav a::after { position: absolute; right: 0; bottom: -7px; left: 0; height: 2px; border-radius: 2px; background: var(--violet); content: ""; opacity: 0; transform: scaleX(.5); transition: opacity .18s ease, transform .18s ease; }
nav a:hover::after { opacity: 1; transform: scaleX(1); }
.staff-session { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--surface); font-size: 12px; font-weight: 700; white-space: nowrap; }
.staff-session-dot { width: 8px; height: 8px; border-radius: 50%; background: #b8b2bc; }
.staff-session-dot, .staff-logout { flex-shrink: 0; }
.staff-header a:focus-visible, .staff-header button:focus-visible { outline: 3px solid var(--violet); outline-offset: 4px; border-radius: 4px; }
.staff-session.is-authenticated { color: var(--green); border-color: #bcdcca; background: var(--green-soft); }
.staff-session.is-authenticated .staff-session-dot { background: var(--green); }
.staff-session.is-anonymous { color: var(--danger); border-color: #e5c3c7; background: #fbf0f1; }
.staff-session.is-anonymous .staff-session-dot { background: var(--danger); }
.staff-logout { padding: 0 0 0 8px; border: 0; border-left: 1px solid currentColor; color: inherit; background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }

main { width: min(1220px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 84px; }
.intro { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 56px; align-items: center; }
.eyebrow { margin: 0 0 10px; color: var(--violet); font-size: 12px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 760px; margin-bottom: 14px; font-size: clamp(40px, 4vw, 54px); font-weight: 700; line-height: 1.06; letter-spacing: -.04em; }
.lead { max-width: 690px; margin-bottom: 0; color: var(--muted); font-size: 17px; line-height: 1.55; }
.security-note { display: grid; gap: 5px; padding: 18px 20px; border: 1px solid rgba(23, 106, 76, .1); border-radius: 16px; color: var(--green); background: rgba(227, 242, 235, .78); }
.security-note strong { font-size: 14px; font-weight: 700; }
.security-note span { color: #48534f; font-size: 13px; line-height: 1.45; }

.workspace-card { margin-top: 30px; padding: clamp(24px, 3vw, 38px); border: 1px solid rgba(91, 61, 121, .16); border-radius: 22px; background: rgba(255, 255, 255, .96); box-shadow: 0 18px 48px rgba(46, 33, 55, .075); }
.state > h2 { margin-bottom: 8px; font-size: 28px; font-weight: 700; line-height: 1.2; letter-spacing: -.025em; }
.step-description { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); line-height: 1.5; }
.small { margin: 14px 0 0; font-size: 12px; }
.primary { display: inline-flex; min-height: 50px; align-items: center; justify-content: center; padding: 0 24px; border: 0; border-radius: 12px; color: #fff; background: var(--violet); box-shadow: 0 7px 16px rgba(91, 61, 121, .16); cursor: pointer; font-weight: 700; text-decoration: none; transition: background .18s ease, box-shadow .18s ease, transform .18s ease; }
.primary:hover { background: var(--violet-dark); }
.primary:disabled { cursor: wait; opacity: .55; }

.session-line, .selection-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.status { padding: 8px 12px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 700; }
.session-line > .status { display: none; }
.customer-search { margin-top: 24px; }
.customer-search > label, .selection-grid label { display: grid; gap: 8px; color: #4e4854; font-size: 13px; font-weight: 650; }
.customer-search > div { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 8px; }
input, select { width: 100%; min-height: 50px; padding: 0 15px; border: 1px solid #d7d1db; border-radius: 12px; color: var(--ink); background: var(--surface); font-size: 15px; transition: border-color .18s ease, box-shadow .18s ease; }
input::placeholder { color: #9a949f; }
input:focus, select:focus { border-color: var(--violet); outline: 0; box-shadow: 0 0 0 3px var(--violet-soft); }

.customer-results { display: grid; gap: 8px; margin-top: 18px; }
.customer-result { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: #fbfafc; cursor: pointer; text-align: left; }
.customer-result:hover { border-color: var(--violet); background: var(--violet-soft); }
.customer-result:disabled { cursor: wait; opacity: .72; }
.customer-result strong { display: block; margin-bottom: 4px; }
.customer-result span { color: var(--muted); font-size: 12px; }
.customer-result::after { content: "Выбрать"; color: var(--violet); font-size: 12px; font-weight: 700; }
.customer-result.is-loading::after { content: "Проверяем…"; }
.empty { padding: 18px; border-radius: 14px; color: var(--muted); background: #f8f6f9; }

.selection-panel { margin-top: 28px; padding-top: 28px; border-top: 1px solid var(--line); }
#customer-search-step.hidden + .selection-panel { margin-top: 0; padding-top: 0; border-top: 0; }
#selected-customer-name { scroll-margin-top: 140px; }
#selected-customer-name:focus-visible { outline: 2px solid var(--violet); outline-offset: 4px; }
.selection-heading h3 { margin-bottom: 0; font-size: 26px; }
.text-button { min-height: 40px; padding: 0; border: 0; color: var(--violet); background: transparent; cursor: pointer; font-weight: 700; }
.selection-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 24px; }
.selection-grid > label { min-width: 0; align-content: start; }
.field-hint { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.45; }
#selection-guidance { margin: 16px 0 10px; }
#continue-button:disabled { cursor: not-allowed; }
.selection-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.selection-summary span { padding: 7px 10px; border-radius: 999px; color: var(--muted); background: #f4f1f6; font-size: 12px; }
.drafts-panel { margin-top: 30px; padding: 24px; border: 1px solid #e7e2e9; border-radius: 18px; background: #faf9fb; }
.drafts-heading, .draft-row-header, .draft-row-summary, .drafts-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drafts-heading h3 { margin-bottom: 0; font-size: 21px; font-weight: 700; letter-spacing: -.015em; }
.drafts-heading .eyebrow { margin-bottom: 5px; }
.draft-filters { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(190px, .55fr) auto auto; gap: 10px; align-items: end; margin-top: 16px; }
.draft-filters label { display: grid; gap: 6px; color: #4e4854; font-size: 12px; font-weight: 650; }
.draft-filters .draft-open, .draft-filters .text-button { min-height: 48px; }
.drafts-actions > span { min-width: 30px; padding: 5px 9px; border-radius: 999px; color: var(--violet); background: var(--violet-soft); text-align: center; font-size: 12px; font-weight: 700; }
.draft-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.draft-row { display: grid; gap: 10px; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fbfafc; }
.draft-row-header strong { font-size: 14px; }
.draft-row-header time, .draft-row small, .draft-empty { color: var(--muted); font-size: 12px; }
.draft-row-summary span:last-child { color: var(--violet-dark); font-weight: 700; }
.draft-row small, .draft-empty { line-height: 1.45; }
.draft-open { justify-self: start; min-height: 34px; padding: 0 12px; border: 1px solid var(--violet); border-radius: 10px; color: var(--violet); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }
.draft-open:hover { color: #fff; background: var(--violet); }
.draft-empty { grid-column: 1 / -1; margin: 0; padding: 16px; border-radius: 12px; background: #f7f5f9; }
.draft-empty.error { color: var(--danger); }
.draft-detail-panel { margin-top: 32px; padding-top: 28px; border-top: 1px solid var(--line); }
.draft-detail-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.draft-detail-heading h3 { margin-bottom: 0; font-size: 26px; }
.draft-detail-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.draft-detail-summary > * { padding: 7px 10px; border-radius: 999px; color: var(--muted); background: #f4f1f6; font-size: 12px; }
.draft-detail-summary > strong { color: var(--violet-dark); background: var(--violet-soft); }
.draft-detail-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.draft-cancel { min-height: 38px; padding: 0 14px; border: 1px solid var(--danger); border-radius: 10px; color: var(--danger); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; }
.draft-cancel:hover { color: #fff; background: var(--danger); }
.draft-cancel:disabled { cursor: wait; opacity: .55; }
.draft-detail-lines { display: grid; gap: 9px; margin-top: 18px; }
.draft-line { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fbfafc; }
.draft-line-image { display: grid; width: 64px; height: 64px; place-items: center; overflow: hidden; border-radius: 10px; color: var(--violet); background: var(--violet-soft); font-size: 20px; font-weight: 700; }
.draft-line-image img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.draft-line-main { display: grid; gap: 5px; min-width: 0; }
.draft-line-main strong { overflow: hidden; text-overflow: ellipsis; }
.draft-line-main span, .draft-line-main small { color: var(--muted); font-size: 12px; }
.draft-line-main .draft-line-state { color: var(--violet); font-weight: 700; }
.draft-line-commercial { display: grid; gap: 6px; justify-items: end; white-space: nowrap; }
.draft-line-commercial span { color: var(--violet-dark); font-size: 13px; font-weight: 700; }
.agreement-commercial-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.agreement-commercial-summary span { padding: 7px 10px; border-radius: 999px; background: #f1edf6; color: var(--violet-dark); font-size: 12px; font-weight: 700; }
.commercial-finance-summary { margin: 16px 0; padding: 16px; border: 1px solid #ddd5e4; border-radius: 16px; background: #faf8fb; }
.commercial-finance-summary > div:first-child { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; }
.commercial-finance-summary .eyebrow { margin: 0; }
.commercial-finance-values { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.commercial-finance-values span { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 10px; border-radius: 12px; background: #fff; }
.commercial-finance-values small { color: var(--muted); }
.commercial-finance-values strong { font-size: 15px; overflow-wrap: anywhere; }
.commercial-finance-warning { margin: 10px 0 0; }
.commercial-finance-details { margin-top: 16px; min-width: 0; }
.commercial-finance-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.commercial-finance-meta > div { min-width: 0; }
.commercial-finance-meta dt { color: var(--muted); font-size: 12px; }
.commercial-finance-meta dd { margin: 3px 0 0; font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.commercial-finance-table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.commercial-finance-details caption { padding: 10px; text-align: left; font-weight: 700; background: #fff; }
.commercial-finance-details table { width: 100%; border-collapse: collapse; background: #fff; font-size: 12px; }
.commercial-finance-details th,
.commercial-finance-details td { padding: 8px; border-bottom: 1px solid #eee8f2; text-align: left; white-space: nowrap; }
.commercial-finance-details th { color: var(--muted); font-weight: 700; }
.commercial-finance-details td:nth-child(n+4) { text-align: right; }
.commercial-finance-details tfoot td { text-align: right; font-weight: 700; }
.commercial-finance-details tfoot th { color: var(--ink); white-space: normal; }
.commercial-finance-details th { white-space: normal; }
.commercial-finance-details td:first-child { min-width: 100px; max-width: 240px; white-space: normal; overflow-wrap: anywhere; }
#commercial-finance-details-toggle { min-height: 40px; border: 1px solid var(--violet); border-radius: 10px; color: var(--violet); background: #fff; font-weight: 700; cursor: pointer; }
#commercial-finance-details-toggle:hover { background: var(--violet-soft); }
#commercial-finance-details-toggle:focus-visible, .commercial-finance-table-wrap:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }
.commercial-finance-summary .compact { margin-top: 10px; padding: 8px 12px; }
@media (max-width: 720px) { .commercial-finance-values { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.draft-line-quantity { display: grid; gap: 4px; justify-items: end; color: var(--muted); font-size: 10px; font-weight: 700; }
.draft-line-quantity input { width: 96px; min-height: 36px; padding: 0 10px; text-align: right; }
.draft-line-remove { padding: 0; border: 0; color: var(--danger); background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; }
.draft-edit-actions { display: flex; align-items: center; justify-content: flex-end; gap: 16px; margin-top: 14px; }
.draft-edit-actions small { max-width: 420px; color: var(--muted); line-height: 1.4; }
.draft-history { margin-top: 24px; }
.draft-history h4 { margin: 0 0 12px; font-size: 15px; }
.draft-history ol + h4 { margin-top: 20px; }
.draft-history ol { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.draft-history li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; background: #f7f5f9; font-size: 12px; }
.draft-history time { color: var(--muted); }
.draft-line-restore { padding: 0; border: 0; color: var(--violet); background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; }
.error { margin: 20px 0 0; color: var(--danger); line-height: 1.45; }

@media (max-width: 1100px) {
  .staff-header { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 180px); gap: 12px; padding-top: 12px; padding-bottom: 10px; }
  .staff-header .brand { min-width: 0; flex-wrap: wrap; gap: 6px 10px; }
  .staff-header .brand span { padding-left: 0; border-left: 0; }
  .staff-header nav { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .staff-header nav a { display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 44px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 12px; text-align: center; overflow-wrap: anywhere; }
  .staff-header nav a::after { display: none; }
  .staff-session { display: grid; grid-template-columns: 8px minmax(0, 1fr); min-width: 0; max-width: 100%; gap: 6px; justify-self: end; white-space: normal; border-radius: 12px; }
  .staff-logout { grid-column: 2; justify-self: end; }
  #staff-session-label { min-width: 0; flex: 1; overflow-wrap: anywhere; }
}

@media (max-width: 800px) {
  .intro { grid-template-columns: 1fr; gap: 24px; }
  .security-note { max-width: 480px; }
  .session-line > .status { display: inline-flex; justify-self: start; }
  .selection-grid { grid-template-columns: 1fr; }
  .draft-list { grid-template-columns: 1fr; }
  .draft-filters { grid-template-columns: 1fr 1fr; }
  .draft-line { grid-template-columns: 52px minmax(0, 1fr); }
  .draft-line-image { width: 52px; height: 52px; }
  .draft-line-commercial { grid-column: 2; display: flex; justify-content: space-between; width: 100%; }
  .draft-edit-actions { align-items: stretch; flex-direction: column; }
}

@media (max-width: 560px) {
  .staff-header { grid-template-columns: minmax(0, 1fr); padding: 12px 14px 10px; gap: 10px; }
  .staff-header .brand { flex-wrap: nowrap; }
  .staff-header nav { grid-row: 3; }
  .brand img { width: 92px; }
  .brand span { font-size: 11px; }
  .staff-session { grid-row: 2; width: 100%; grid-template-columns: 8px minmax(0, 1fr) auto; font-size: 11px; padding: 7px 9px; }
  .staff-logout { grid-column: 3; }
  main { width: calc(100% - 28px); padding-top: 28px; }
  .draft-filters { grid-template-columns: 1fr; }
  h1 { font-size: 38px; }
  .workspace-card { margin-top: 22px; padding: 22px 18px; border-radius: 18px; }
  .drafts-panel { padding: 18px; }
  .customer-search > div { grid-template-columns: 1fr; }
  .session-line, .selection-heading, .drafts-heading, .draft-detail-heading { display: grid; }
  .drafts-actions { justify-content: start; }
  .draft-history li { display: grid; }
}
