/* ═══════════════════════════════════════════════════
   Invoice Processor — CSS
   ═══════════════════════════════════════════════════ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: white;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.header-inner { max-width: 960px; margin: 0 auto; }
.logo         { font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.header-sub   { font-size: 12px; opacity: .75; margin-top: 2px; }

/* ── Main layout ──────────────────────────────────── */
.app-main {
  max-width: 960px;
  margin: 28px auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Validation banner (математические расхождения) ── */
.validation-banner {
  background: #fef2f2;
  border: 2px solid #dc2626;
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 18px;
  color: #991b1b;
}
.validation-banner .vb-title {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: .2px;
}
.validation-banner .vb-list {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
}
.validation-banner .vb-list li { margin-top: 4px; }

/* ── Card ─────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  padding: 28px 32px;
}
.card-title {
  font-size: 17px;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e8edf5;
}

/* ── Factory selector ─────────────────────────────── */
.row-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.field-label  { font-size: 13px; font-weight: 600; white-space: nowrap; color: #4a5568; }
.select-factory {
  flex: 1;
  max-width: 380px;
  padding: 8px 12px;
  border: 1.5px solid #d1d9e6;
  border-radius: 8px;
  font-size: 14px;
  background: #f8faff;
  cursor: pointer;
  transition: border-color .2s;
}
.select-factory:focus { outline: none; border-color: #2563eb; }

/* ── Drop zone ────────────────────────────────────── */
.drop-zone {
  border: 2.5px dashed #c5d2e8;
  border-radius: 12px;
  background: #f8faff;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 16px;
}
.drop-zone:hover, .drop-zone.over {
  border-color: #2563eb;
  background: #eef4ff;
}
.drop-icon  { font-size: 36px; margin-bottom: 8px; }
.drop-text  { font-size: 15px; color: #4a5568; line-height: 1.5; }
.drop-text span { font-size: 13px; color: #9aa5b4; }

/* ── File name display ────────────────────────────── */
.file-name-display {
  background: #eef4ff;
  border: 1px solid #c5d2e8;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  color: #2563eb;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:hover:not(:disabled)  { opacity: .9; transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled              { opacity: .45; cursor: not-allowed; }
.btn-wide { width: 100%; justify-content: center; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-success { background: #059669; color: #fff; margin-top: 16px; }
.btn-icon    { font-size: 17px; }

/* ── Spinner ──────────────────────────────────────── */
.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #e8edf5;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner-text { font-size: 14px; color: #4a5568; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error box ────────────────────────────────────── */
.error-box {
  background: #fff0f0;
  border: 1.5px solid #fca5a5;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #b91c1c;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.invalid-input {
  border-color: #dc2626 !important;
  background: #fff7f7 !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, .08);
}

/* ── Editor header ────────────────────────────────── */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #e8edf5;
}
.factory-badge {
  background: #dbeafe;
  color: #1e40af;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
}

/* ── Control panel ───────────────────────────────── */
.control-panel {
  border: 1.5px solid #dbeafe;
  background: #f8fbff;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 14px;
}
.control-title {
  font-size: 13px;
  font-weight: 800;
  color: #1e3a5f;
  margin-bottom: 10px;
}
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
}
.control-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  min-height: 38px;
}
.control-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.control-chip.ok .control-dot { background: #059669; }
.control-chip.warn .control-dot { background: #d97706; }
.control-chip.bad .control-dot { background: #dc2626; }
.control-chip.ok { border-color: #bbf7d0; background: #f0fdf4; }
.control-chip.warn { border-color: #fed7aa; background: #fff7ed; }
.control-chip.bad { border-color: #fecaca; background: #fef2f2; }
.control-label {
  font-size: 12px;
  font-weight: 800;
  color: #111827;
  white-space: nowrap;
}
.control-detail {
  font-size: 11px;
  color: #4b5563;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Section blocks ───────────────────────────────── */
.section-block {
  border: 1.5px solid #e8edf5;
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #f6f8fc;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.section-head:hover { background: #eef3fb; }
.section-icon  { font-size: 16px; }
.section-label { font-weight: 700; font-size: 14px; flex: 1; color: #1e3a5f; }
.section-toggle { font-size: 12px; color: #9aa5b4; transition: transform .2s; }
.section-toggle.collapsed { transform: rotate(180deg); }

.section-body {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 10px;
}
.section-body.collapsed { display: none; }

/* Special: items section and pp-row use full width */
#items-body { display: block; padding: 14px 16px; }

/* ── Field rows ───────────────────────────────────── */
.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.field-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #2563eb;
  flex-shrink: 0;
  cursor: pointer;
}
.field-row .fl-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  min-width: 130px;
  white-space: nowrap;
}
.field-row .fl-input {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid #d1d9e6;
  border-radius: 6px;
  font-size: 13px;
  background: #fafbff;
  transition: border-color .2s, opacity .2s;
}
.field-row .fl-input:focus   { outline: none; border-color: #2563eb; background: #fff; }
.field-row .fl-input.dimmed  { opacity: .45; background: #f3f4f6; }

/* ── Items table ──────────────────────────────────── */
.price-toggle-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
}
.toggle-label { font-weight: 600; color: #4a5568; }
.radio-opt    { display: flex; align-items: center; gap: 5px; cursor: pointer; }

.table-scroll { overflow-x: auto; }
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.items-table th {
  background: #1e3a5f;
  color: #fff;
  padding: 9px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}
.items-table td {
  border-bottom: 1px solid #e8edf5;
  padding: 7px 8px;
  vertical-align: middle;
}
.items-table tbody tr:hover { background: #f8faff; }
.items-table tbody tr.disabled-row { opacity: .4; }

.col-check { width: 36px; }
.col-name  { min-width: 180px; }
.col-hs    { min-width: 100px; }
.col-num   { width: 90px; }
.col-price { width: 100px; }

.cell-inp {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 12px;
  background: transparent;
  transition: border-color .15s, background .15s;
}
.cell-inp:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
}
.cell-inp.num { text-align: right; }

/* ── Primary packaging row ────────────────────────── */
.pp-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding: 12px 14px;
  background: #f0fdf4;
  border: 1.5px dashed #6ee7b7;
  border-radius: 8px;
  flex-wrap: wrap;
}
.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: #065f46;
}
.checkbox-wrap input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #059669;
  flex-shrink: 0;
}
.pp-input {
  flex: 1;
  min-width: 280px;
  padding: 7px 12px;
  border: 1.5px solid #a7f3d0;
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
}
.pp-input:focus { outline: none; border-color: #059669; }

/* ── Generate panel ───────────────────────────────── */
.generate-panel {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 2px solid #e8edf5;
}
.generate-title {
  font-size: 15px;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 14px;
}
.format-section-title {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.format-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.fmt-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 9px 16px;
  border: 2px solid #d1d9e6;
  border-radius: 9px;
  transition: border-color .2s, background .2s;
  user-select: none;
}
.fmt-checkbox:has(input:checked) { border-color: #059669; background: #f0fdf4; }
.fmt-checkbox input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #059669;
}
.fmt-icon { font-size: 18px; }

/* ── Utility ──────────────────────────────────────── */
.hidden { display: none !important; }
