/* Портал «Поставка під ключ» — стилі. Світла тема, акцент #4f46e5. */

:root {
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --bg: #f4f5fa;
  --card: #ffffff;
  --text: #1e2130;
  --muted: #6b7280;
  --border: #e5e7eb;
  --row-line: #f0f1f5;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --yellow: #b45309;
  --yellow-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --gray-soft: #f3f4f6;
  --flag-row: #fffbeb;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.pre { white-space: pre-wrap; word-wrap: break-word; }

.noscript {
  background: var(--red-soft);
  color: var(--red);
  text-align: center;
  padding: 14px;
  font-weight: 600;
}

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 700; }
h2 { font-size: 20px; }

/* ── картки ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pad { padding: 20px; }
.block { margin-top: 16px; }
.block-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

/* ── кнопки ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--gray-soft);
  transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: #e8eaf0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--gray-soft); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.big { padding: 11px 26px; font-size: 15.5px; }
.btn.block { width: 100%; }
.btn.dl {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #d8ddfb;
}
.btn.dl:hover { background: #e0e5ff; }
.btn.warn {
  background: var(--yellow);
  color: #fff;
}
.btn.warn:hover:not(:disabled) { background: #92400e; }

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 14px;
}
.btn-back:hover { text-decoration: underline; }

/* ── поля вводу ── */
input, textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
textarea { resize: vertical; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 5px;
}
.form-error {
  background: var(--red-soft);
  color: var(--red);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin-top: 12px;
}

/* ── бейджі ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}
.badge.gray   { background: var(--gray-soft);   color: #4b5563; }
.badge.blue   { background: var(--blue-soft);   color: var(--blue); }
.badge.green  { background: var(--green-soft);  color: var(--green); }
.badge.red    { background: var(--red-soft);    color: var(--red); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.violet { background: var(--accent-soft); color: var(--accent); }

.flagcount { color: var(--yellow); font-weight: 700; }

/* ── екран логіну ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 34px 30px;
  text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.login-card form { text-align: left; }
.login-card .btn { margin-top: 18px; }

/* ── шапка ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px;
}
.brand {
  background: none;
  border: none;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
}
.brand:hover span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.hdr-user { color: var(--muted); font-size: 13.5px; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── список поставок ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.toolbar h2 { margin: 0; }

.plist { padding: 4px 0; overflow: hidden; }
.plist-head, .plist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 150px 90px 100px;
  gap: 12px;
  align-items: center;
  padding: 11px 18px;
}
.plist-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.plist-row {
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--row-line);
  transition: background .15s;
}
.plist-row:last-child { border-bottom: none; }
.plist-row:hover { background: var(--accent-soft); }
.pl-name { font-weight: 600; }
.pl-owner {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}
.pl-date { color: var(--muted); font-size: 13px; }
.pl-items { font-variant-numeric: tabular-nums; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}

/* ── нова поставка ── */
.new-card { max-width: 760px; }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.dropzone.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px rgba(79, 70, 229, .25);
}
.dz-icon { font-size: 36px; margin-bottom: 6px; }
.dz-text b { color: var(--accent); }
.dz-hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

.file-list { list-style: none; margin: 10px 0 0; padding: 0; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--row-line);
  font-size: 13.5px;
}
.fl-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.fl-size { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.fl-rm {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 6px;
}
.fl-rm:hover { background: var(--red-soft); color: var(--red); }

.new-actions { margin-top: 18px; text-align: right; }

/* ── сторінка поставки ── */
.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}
.post-main { min-width: 0; }

.post-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.post-title-row h2 { margin: 0; }
.post-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* степер етапів */
.stepper {
  display: flex;
  align-items: flex-start;
  margin-top: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 86px;
  text-align: center;
  flex-shrink: 0;
}
.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
}
.step-label { font-size: 12px; color: var(--muted); line-height: 1.3; max-width: 110px; }

.step.done .step-dot {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.step.done .step-label { color: var(--text); }

.step.active .step-dot {
  border-color: var(--accent);
  animation: pulse 1.6s ease-out infinite;
}
.step.active .step-dot::after {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.step.active .step-label { color: var(--accent); font-weight: 700; }

.step.pending .step-dot::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.step-line {
  flex: 1;
  min-width: 22px;
  height: 2px;
  background: var(--border);
  margin-top: 15px;
}
.step-line.filled { background: var(--green); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(79, 70, 229, .35); }
  70%  { box-shadow: 0 0 0 10px rgba(79, 70, 229, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

.progress-note {
  margin-top: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-weight: 600;
}

/* файли-джерела */
.file-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-soft);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  max-width: 100%;
}
.file-chip:hover { background: var(--accent-soft); color: var(--accent); }
.fc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
  font-weight: 600;
}
.fc-size { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* помилка */
.error-box {
  background: var(--red-soft);
  border-left: 4px solid var(--red);
  color: #7f1d1d;
}
.error-box .block-title { color: var(--red); }

/* кнопки скачування результату */
.downloads { display: flex; flex-wrap: wrap; gap: 10px; }

/* панель незбережених правок */
.dirty-bar {
  margin-top: 16px;
  background: var(--yellow-soft);
  border: 1px solid #f5d78e;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--yellow);
}

/* таблиця позицій */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}
table.items {
  border-collapse: collapse;
  width: 100%;
  min-width: 1220px;
  font-size: 13px;
}
table.items th {
  background: #f8f9fc;
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.items td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--row-line);
  vertical-align: top;
}
table.items tr:hover td { background: rgba(79, 70, 229, .03); }
table.items tr.flagged td { background: var(--flag-row); }
table.items .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.items td.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
}
table.items .flags div { color: var(--yellow); font-size: 12px; white-space: normal; }
table.items tfoot td {
  font-weight: 800;
  background: #f8f9fc;
  border-top: 2px solid var(--border);
  border-bottom: none;
}
.tot-label { text-align: right; }

/* інлайн-редаговані клітинки */
td.cell-edit { cursor: pointer; }
td.cell-edit:hover:not(.editing) {
  background: var(--accent-soft) !important;
  box-shadow: inset 0 -2px 0 var(--accent);
}
td.cell-edit:hover:not(.editing)::after {
  content: ' ✎';
  color: var(--accent);
  font-size: 11px;
}
td.cell-edit.editing { padding: 3px 4px; }
td.cell-edit input {
  min-width: 130px;
  padding: 4px 7px;
  font-size: 13px;
  border-radius: 6px;
  border-color: var(--accent);
}

/* ── чат ── */
.chat-panel {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 100px);
  overflow: hidden;
}
.chat-head {
  padding: 13px 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  font-size: 14.5px;
}
.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  min-height: 180px;
}
.chat-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 10px;
}
.msg {
  max-width: 90%;
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13.5px;
}
.msg.user {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  margin-right: auto;
  background: var(--gray-soft);
  border-bottom-left-radius: 4px;
}
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-at {
  font-size: 10.5px;
  opacity: .65;
  margin-top: 3px;
  text-align: right;
}
.chat-think {
  padding: 6px 16px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-form textarea { flex: 1; resize: none; min-height: 40px; }

/* ── адмін-модал ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 16px 16px;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 22px 24px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; }
.modal-x {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-x:hover { background: var(--gray-soft); color: var(--text); }

.users-list { margin-bottom: 18px; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-bottom: 1px solid var(--row-line);
}
.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-name { font-weight: 700; }
.user-login { color: var(--muted); font-size: 13px; }
.pwform {
  width: 100%;
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.pwform input { flex: 1; }

.users-add h4 { margin-bottom: 10px; }
#user-add-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
#user-add-form input#ua-pass { grid-column: 1; }
#user-add-form button { grid-column: 2; }

/* ── тост ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: min(92vw, 560px);
  text-align: center;
}
.toast.err { background: var(--red); }

/* ── спінер ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -3px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── адаптив ≤768px ── */
@media (max-width: 768px) {
  .container { padding: 14px 12px 40px; }
  .topbar { padding: 0 12px; }
  .brand span { font-size: 15px; }
  .hdr-user { display: none; }

  /* список: картки замість рядків */
  .plist { background: transparent; box-shadow: none; padding: 0; overflow: visible; }
  .plist-head { display: none; }
  .plist-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 10px;
    padding: 14px 16px;
    border-bottom: none;
  }
  .pl-title { width: 100%; order: 1; }
  .pl-status { order: 2; }
  .pl-items { order: 3; font-size: 13px; color: var(--muted); align-self: center; }
  .pl-items::before { content: 'Позицій: '; }
  .pl-flags { order: 4; align-self: center; }
  .pl-date { width: 100%; order: 5; font-size: 12.5px; }

  /* сторінка поставки: чат знизу */
  .post-layout { grid-template-columns: 1fr; }
  .chat-panel {
    position: static;
    max-height: none;
  }
  .chat-msgs { max-height: 320px; min-height: 140px; }

  .downloads .btn.dl { flex: 1 1 100%; }
  .new-actions { text-align: center; }
  .new-actions .btn { width: 100%; }

  #user-add-form { grid-template-columns: 1fr; }
  #user-add-form input#ua-pass, #user-add-form button { grid-column: 1; }

  table.items { font-size: 12.5px; }
}

/* блок «перевір вручну / брокеру» + звіт двигуна */
.warn-box {
  background: #fffbeb;
  border: 1px solid #f59e0b;
  border-radius: 12px;
  margin-bottom: 16px;
}
.warn-box .block-title { color: #92400e; }
.report-summary {
  cursor: pointer;
  font-weight: 600;
  color: #6b7280;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pre.report {
  max-height: 420px;
  overflow-y: auto;
  margin-top: 10px;
  font-size: 0.9rem;
}

/* режим запиту: блок відповіді двигуна */
.answer-text {
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.card.answer { border-left: 4px solid #4f46e5; }
