/* ============================================================
   tender-search — industrial procurement dashboard
   Light theme (default): warm charcoal shell, off-white cards,
   burnt orange accent. Dark theme via [data-theme="dark"].
   Spacing system: 4px unit. Font: system-ui, 14px base.
   ============================================================ */

:root {
  /* shell (page background, header) */
  --bg: #1e1d1b;
  --chrome: #262421;
  --chrome-brd: #35322d;
  --page-ink: #f2f0eb;
  --page-ink-2: #a29c90;

  /* cards */
  --surface: #faf9f6;
  --surface-2: #f1efea;
  --surface-3: #e9e7e1;
  --ink: #26241f;
  --ink-2: #6f6b63;
  --ink-3: #9c978c;
  --border: #e8e6e1;
  --border-2: #d8d5cd;

  /* accent */
  --accent: #c2510a;
  --accent-hover: #a84608;
  --accent-soft: #f7ede2;
  --accent-ink: #ffffff;

  /* semantic */
  --ok: #2e7d32;   --ok-soft: #e6f1e5;
  --err: #c1351d;  --err-soft: #f9e9e4;
  --info: #1f63a8; --info-soft: #e6eef6;
  --vio: #6a3fb5;  --vio-soft: #efe9f9;
  --warn: #a27607; --warn-soft: #f7f0dd;
  --grey: #7a766e;

  /* chips */
  --chip-bg: #efede8;
  --chip-ink: #6f6b63;
  --c-vi: #b3541a;
  --c-mi: #0f7b6c;
  --c-ya: #b3352d;
  --c-pr: #3f7d3a;
  --c-region: #5c6672;

  --track: #e8e6e1;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);

  /* toast (fixed on the shell) */
  --toast-bg: #2b2926;
  --toast-ink: #f2f0eb;
}

[data-theme="dark"] {
  --bg: #111111;
  --chrome: #161616;
  --chrome-brd: #2a2a2a;
  --page-ink: #e8e6e1;
  --page-ink-2: #8d8a82;

  --surface: #2a2a2a;
  --surface-2: #323232;
  --surface-3: #3a3a3a;
  --ink: #ecebe7;
  --ink-2: #9b9890;
  --ink-3: #6e6b64;
  --border: #3a3a38;
  --border-2: #46463f;

  --accent: #b06a38;
  --accent-hover: #a36130;
  --accent-soft: #3a2b1e;
  --accent-ink: #1c130a;

  --ok: #6fa965;   --ok-soft: #27432a;
  --err: #d0655d;  --err-soft: #45251f;
  --info: #5b8fc0; --info-soft: #23344a;
  --vio: #9c7cd0;  --vio-soft: #33294a;
  --warn: #c6a04c; --warn-soft: #413723;
  --grey: #85827a;

  --chip-bg: #3a3a38;
  --chip-ink: #b6b2a9;
  --c-vi: #d98a4f;
  --c-mi: #57a898;
  --c-ya: #dd7a71;
  --c-pr: #7fb47a;
  --c-region: #8b95a1;

  --track: #3a3a38;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

  --toast-bg: #262626;
  --toast-ink: #e8e6e1;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

html { font-size: 14px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--info); }

h1, h2 { margin: 0; }

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ink-2 { color: var(--ink-2); }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-brd);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--page-ink);
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
}

.logo-mark .ico { width: 16px; height: 16px; }

.logo-text { font-size: 15px; font-weight: 700; letter-spacing: 0.01em; }

.logo-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--page-ink-2);
  padding: 3px 8px;
  border: 1px solid var(--chrome-brd);
  border-radius: 999px;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--chrome-brd);
  border-radius: 6px;
  background: transparent;
  color: var(--page-ink-2);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.theme-btn:hover { color: var(--page-ink); border-color: var(--page-ink-2); }

/* ---------- page layout ---------- */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 28px 48px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--page-ink);
}

.page-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--page-ink-2);
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn .ico { width: 15px; height: 15px; }

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

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-2);
}
.btn-secondary:hover { border-color: var(--ink-3); }

.btn-danger {
  background: var(--surface);
  color: var(--err);
  border-color: var(--border-2);
}
.btn-danger:hover { border-color: var(--err); }

.btn-back {
  height: 30px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-2);
  margin-bottom: 16px;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.card-head .count { font-size: 13px; color: var(--ink-3); }

/* ---------- upload zone ---------- */

.dropzone {
  border: 1.5px dashed var(--border-2);
  border-radius: 10px;
  background: var(--surface);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 24px;
}

.dropzone:hover { border-color: var(--ink-3); }

.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.is-drag .dz-icon { color: var(--accent); }

.dropzone.is-busy { opacity: 0.65; pointer-events: none; }

.dz-icon { width: 34px; height: 34px; color: var(--ink-3); margin-bottom: 12px; }

.dz-title { font-size: 16px; font-weight: 700; color: var(--ink); }

.dz-sub { margin-top: 4px; font-size: 13px; color: var(--ink-2); }

.dz-note { margin-top: 8px; font-size: 12px; color: var(--ink-3); }

/* ---------- tables ---------- */

.tender-table {
  width: 100%;
  border-collapse: collapse;
}

.tender-table th {
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  color: var(--ink-3);
  border-bottom: 1px solid var(--border-2);
  white-space: nowrap;
}

.tender-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tender-table tbody tr:last-child td { border-bottom: none; }

.trow { cursor: pointer; transition: background 0.1s; }
.trow:hover { background: var(--surface-2); }
.trow .btn-del { opacity: 0; transition: opacity 0.15s; }
.trow:hover .btn-del { opacity: 1; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border: none; border-radius: 6px;
  background: transparent; cursor: pointer; color: var(--ink-2);
}
.btn-icon:hover { background: var(--surface-2); color: var(--ink); }
.btn-del:hover { color: #c62828; background: #ffebee; }

.act-cell { width: 40px; text-align: center; }

.file-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-cell .ico { width: 16px; height: 16px; color: var(--ink-3); flex: none; }

.file-name {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 460px;
}

.cell-progress { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.cell-progress-text { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- status badges (colored dot + text) ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--grey);
  flex: none;
}

.status-done::before { background: var(--ok); }   .status-done { color: var(--ok); }
.status-search::before { background: var(--info); } .status-search { color: var(--info); }
.status-enrich::before { background: var(--info); } .status-enrich { color: var(--info); }
.status-error::before { background: var(--err); }  .status-error { color: var(--err); }
.status-parsed::before { background: var(--vio); } .status-parsed { color: var(--vio); }
.status-queued::before { background: var(--warn); } .status-queued { color: var(--warn); }
.status-cancelled::before { background: var(--grey); } .status-cancelled { color: var(--grey); }
.status-parsing::before { background: var(--grey); }

.status-search::before,
.status-enrich::before { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- progress bar (4px, accent fill) ---------- */

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

.progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ---------- chips (pill, muted bg, colored left border) ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 9px;
  border-radius: 999px;
  border-left: 3px solid var(--grey);
  background: var(--chip-bg);
  color: var(--chip-ink);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-vi { border-left-color: var(--c-vi); color: var(--c-vi); }
.chip-mi { border-left-color: var(--c-mi); color: var(--c-mi); }
.chip-yandex { border-left-color: var(--c-ya); color: var(--c-ya); }
.chip-price { border-left-color: var(--c-pr); color: var(--c-pr); }
.chip-priority { border-left-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip-warn { border-left-color: var(--warn); color: var(--warn); }
.chip-region { border-left-color: var(--c-region); color: var(--c-region); }
.chip-attr { max-width: 200px; }

/* ---------- tender detail ---------- */

.tender-head { padding: 20px; }

.head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.head-line { display: flex; align-items: center; gap: 10px; }

.head-ico { color: var(--accent); width: 20px; height: 20px; }

.tender-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  word-break: break-word;
}

.tender-meta { margin-top: 4px; font-size: 13px; color: var(--ink-2); }

.head-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
}

.run-box { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.run-text {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.err-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--err);
  border-radius: 6px;
  background: var(--err-soft);
  color: var(--err);
  font-size: 13px;
}

.err-note .ico { width: 15px; height: 15px; margin-top: 1px; }

/* ---------- items table ---------- */

.items-card { margin-top: 20px; }

.item-row { cursor: pointer; transition: background 0.1s; }
.item-row:hover { background: var(--surface-2); }
.item-row.is-open { background: var(--surface-2); }

.item-num {
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  font-weight: 600;
  white-space: nowrap;
}

.item-name { font-weight: 600; color: var(--ink); }

.item-spec {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 640px;
}

.price { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.chev { width: 20px; text-align: right; }
.chev-ico {
  width: 15px;
  height: 15px;
  color: var(--ink-3);
  transform: rotate(0deg);
  transition: transform 0.15s;
}
.item-row.is-open .chev-ico { transform: rotate(90deg); }

.item-detail td {
  padding: 0 20px 16px;
  background: var(--surface-2);
}

.item-detail .empty { margin: 16px 0 4px; }

.item-note {
  margin: 14px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  border-radius: 0 6px 6px 0;
  color: var(--warn);
  font-size: 12.5px;
}

.attr-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 10px 0 14px;
}

.attr-label { font-size: 12px; color: var(--ink-3); margin-right: 4px; }

/* ---------- offer rows ---------- */

.offers {
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.offer-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.offer-row:last-child { border-bottom: none; }

.offer-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
  align-items: flex-start;
  padding-top: 1px;
}

.offer-main { flex: 1 1 auto; min-width: 0; }

.offer-title {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  word-break: break-word;
}

a.offer-title:hover { color: var(--accent); text-decoration: underline; }

.offer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-2);
}

.offer-alt {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-2);
}

.offer-alt a { text-decoration: none; }

.offer-extra {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding-top: 2px;
}

.offer-right {
  flex: none;
  text-align: right;
  min-width: 108px;
}

.offer-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.offer-base {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-decoration: line-through;
}

.compliant {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  flex: none;
}

.compliant .ico { width: 13px; height: 13px; stroke-width: 2.4; }

/* ---------- stock badges (colored dot + text) ---------- */

.st {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none; }

.st-in::before { background: var(--ok); }     .st-in { color: var(--ok); }
.st-order::before { background: var(--warn); } .st-order { color: var(--warn); }
.st-out::before { background: var(--err); }   .st-out { color: var(--err); }
.st-unknown::before { background: var(--ink-3); } .st-unknown { color: var(--ink-3); }

/* ---------- empty state ---------- */

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-2);
  font-weight: 600;
}

.empty .empty-ico { color: var(--ink-3); width: 30px; height: 30px; margin-bottom: 10px; }

.empty-sub { margin-top: 4px; font-weight: 400; font-size: 13px; color: var(--ink-3); }

.empty.sm { padding: 18px; font-weight: 500; font-size: 13px; }

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  max-width: 380px;
  padding: 11px 14px;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
}

.toast-err { border-left-color: var(--err); }

.toast.is-out { opacity: 0; transition: opacity 0.25s; }

@keyframes toast-in {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .topbar-inner, .page { padding-left: 16px; padding-right: 16px; }
  .offer-row { flex-wrap: wrap; }
  .offer-right { margin-left: auto; }
  .tender-table { display: block; overflow-x: auto; }
}
