:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f7f7f9;
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #5c3ad9;
  --accent-hover: #4c2dc2;
  --accent-soft: #ede8ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 3px rgba(17, 24, 39, 0.04);
  --shadow-card-hover: 0 2px 4px rgba(17, 24, 39, 0.06), 0 4px 12px rgba(17, 24, 39, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Top bar ============ */

.top-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.logo-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  display: inline-block;
}

.top-actions .badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ============ Container ============ */

.container {
  flex: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
  width: 100%;
}

.hero {
  margin: 4px 0 20px;
}

.hero h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.hero-sub {
  color: var(--text-muted);
  margin: 0;
  font-size: 15px;
}

/* ============ Cards ============ */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 16px;
}

/* ============ Drop zone ============ */

.drop-card {
  border: 2px dashed var(--border-strong);
  background: var(--surface);
  transition: border-color 150ms ease, background-color 150ms ease;
  padding: 36px 24px;
  display: block;
  cursor: pointer;
  user-select: none;
}

.drop-card--hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-card--busy {
  border-style: solid;
  border-color: var(--border);
}

/* Когда документ уже загружен — карточка меньше, только для замены */
.drop-card--compact {
  padding: 16px 20px;
  border-style: solid;
  border-color: var(--border);
}
.drop-card--compact .drop-inner { gap: 14px; }
.drop-card--compact .drop-icon {
  width: 40px; height: 40px; border-radius: 10px;
}
.drop-card--compact .drop-icon svg { width: 20px; height: 20px; }
.drop-card--compact .drop-title { font-size: 14px; font-weight: 500; }
.drop-card--compact .drop-sub { font-size: 12px; }

.drop-inner {
  display: flex;
  align-items: center;
  gap: 18px;
}

.drop-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.drop-icon svg {
  width: 28px;
  height: 28px;
}

.drop-text {
  flex: 1;
  min-width: 0;
}

.drop-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============ Progress ============ */

.progress-wrap {
  flex: 1;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.progress-percent {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8b5cf6);
  border-radius: 999px;
  transition: width 250ms ease;
}

.progress-log {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Error ============ */

.error-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  padding: 14px 18px;
}

.error-icon {
  width: 28px;
  height: 28px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.error-text {
  flex: 1;
  color: #991b1b;
}

/* ============ Workspace (preview + form) ============ */

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

@media (min-width: 1024px) {
  .workspace--split {
    grid-template-columns: minmax(400px, 1fr) minmax(460px, 1fr);
    gap: 20px;
  }
  .workspace--split .doc-panel {
    position: sticky;
    top: 86px;
    max-height: calc(100vh - 110px);
  }
}

.form-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ============ Document preview panel ============ */

.doc-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  min-height: 500px;
  min-width: 0;
}

.doc-panel-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.doc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.doc-filename {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f3f5;
  border-radius: var(--radius-sm);
  overflow: auto;
  min-height: 480px;
}

.doc-frame {
  width: 100%;
  height: 100%;
  min-height: 480px;
  border: none;
  border-radius: var(--radius-sm);
  background: #f3f3f5;
}

.doc-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

/* ============ Payer collapsible details ============ */

.payer-details {
  padding: 0;
  overflow: hidden;
}

.payer-details > summary {
  list-style: none;
}
.payer-details > summary::-webkit-details-marker { display: none; }

.payer-summary {
  cursor: pointer;
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  user-select: none;
  transition: background 120ms ease;
}

.payer-summary:hover {
  background: var(--surface-muted);
}

.payer-summary h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  flex-shrink: 0;
}

.payer-brief {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payer-dot {
  margin: 0 6px;
  color: var(--text-faint);
}

.payer-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: transform 180ms ease;
  flex-shrink: 0;
}

.payer-details[open] .payer-icon {
  transform: rotate(180deg);
}

.payer-content {
  padding: 6px 22px 22px;
  border-top: 1px solid var(--border);
}

/* ============ Form ============ */

.form-card {
  padding: 0;
  overflow: hidden;
}

.section {
  padding: 24px 28px;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
}

.section-hint {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

.section-hint-warn {
  color: var(--danger);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  grid-column: span 2;
}

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

.field > span {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.field input,
.field textarea {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  width: 100%;
  min-width: 0;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input[readonly] {
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: default;
}

.field-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 17px !important;
}

/* ============ Buttons ============ */

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 120ms ease, box-shadow 120ms ease, transform 80ms ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-muted);
}

.btn-large {
  padding: 13px 24px;
  font-size: 16px;
  font-weight: 600;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 28px 24px;
  background: var(--surface-muted);
  border-top: 1px solid var(--border);
}

/* Скрываем input визуально, но оставляем доступным для label[for=…] */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============ Responsive ============ */

@media (max-width: 720px) {
  .container { padding: 16px 12px 40px; }
  .section { padding: 20px 18px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .field, .field--span-2, .field--span-3 { grid-column: span 1; }
  .drop-inner { flex-direction: column; text-align: center; }
  .hero h1 { font-size: 22px; }
}
