/*
 * Токены в духе Dye: при подключении Dye этот блок можно удалить —
 * остальные правила используют только переменные.
 */
:root {
  --dye-gray-0: #ffffff;
  --dye-gray-25: #fafaf8;
  --dye-gray-50: #f3f3f0;
  --dye-gray-100: #e9e9e4;
  --dye-gray-200: #d8d8d1;
  --dye-gray-400: #a2a299;
  --dye-gray-600: #64645d;
  --dye-gray-800: #33332f;
  --dye-gray-900: #22221f;

  --dye-orange-50: #fdf4ec;
  --dye-orange-100: #f9e2cd;
  --dye-orange-300: #efb485;
  --dye-orange-500: #e0844a;
  --dye-orange-700: #a35722;

  --dye-green-100: #e2eedd;
  --dye-green-700: #3e6a33;
  --dye-red-100: #f5dfda;
  --dye-red-700: #973a2b;
  --dye-blue-100: #e0e8f1;
  --dye-blue-700: #345981;

  --dye-color-bg: var(--dye-gray-50);
  --dye-color-surface: var(--dye-gray-0);
  --dye-color-border: var(--dye-gray-200);
  --dye-color-text: var(--dye-gray-900);
  --dye-color-muted: var(--dye-gray-600);
  --dye-color-primary: var(--dye-orange-500);
  --dye-color-primary-strong: var(--dye-orange-700);
  --dye-color-primary-soft: var(--dye-orange-100);

  --dye-radius: 2px;
  --dye-font: "IBM Plex Sans", "Segoe UI", Roboto, system-ui, sans-serif;
  --dye-font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --dye-space: 0.25rem;
}

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

html { font-size: 14px; }

body {
  margin: 0;
  font-family: var(--dye-font);
  line-height: 1.45;
  color: var(--dye-color-text);
  background: var(--dye-color-bg);
}

a { color: var(--dye-color-primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--dye-color-primary); outline-offset: 1px; }

h1, h2 { font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }

/* Каркас ------------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: 15.5rem 1fr; min-height: 100vh; }

.side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 0.75rem;
  background: var(--dye-gray-100);
  border-right: 1px solid var(--dye-color-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: block;
  padding: 0 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--dye-color-text);
  border-left: 3px solid var(--dye-color-primary);
}
.brand:hover { text-decoration: none; }

.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }

.nav-group {
  margin: 1rem 0 0.25rem;
  padding: 0 0.5rem;
  font-size: 0.85rem;
  color: var(--dye-color-muted);
}

.nav-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  color: var(--dye-color-text);
  border-radius: var(--dye-radius);
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--dye-gray-50); text-decoration: none; }
.nav-link.is-active { background: var(--dye-color-surface); border-left-color: var(--dye-color-primary); font-weight: 600; }
.nav-exit { color: var(--dye-color-muted); }

/* Счётчики очередей — главный сигнал интерфейса: сколько работы ждёт человека. */
.count {
  min-width: 1.6rem;
  padding: 0 0.35rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--dye-color-primary-strong);
  background: var(--dye-color-primary-soft);
  border-radius: var(--dye-radius);
}

.main { padding: 1.5rem 2rem 4rem; min-width: 0; max-width: 90rem; }
.page-title { margin: 0 0 1.25rem; font-size: 1.5rem; }

/* Обзор -------------------------------------------------------------------- */

.queues { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 1rem; }

.queue {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.1rem;
  color: var(--dye-color-muted);
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-color-border);
  border-radius: var(--dye-radius);
}
.queue:hover { text-decoration: none; border-color: var(--dye-gray-400); }
.queue-num { font-size: 2rem; font-weight: 600; line-height: 1.1; color: var(--dye-gray-400); font-variant-numeric: tabular-nums; }
.queue.has-work { border-top: 3px solid var(--dye-color-primary); background: var(--dye-orange-50); }
.queue.has-work .queue-num { color: var(--dye-color-primary-strong); }

.stats { display: flex; flex-wrap: wrap; gap: 0.5rem 2rem; margin-bottom: 1rem; }
.stats b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* Блоки -------------------------------------------------------------------- */

.panel {
  margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-color-border);
  border-radius: var(--dye-radius);
}
.panel > summary { cursor: pointer; font-weight: 600; }
.panel > summary + .table { margin-top: 0.75rem; }

.lead { max-width: 46rem; margin: 0 0 1rem; color: var(--dye-color-muted); }
.hint { margin: 0; color: var(--dye-color-muted); font-size: 0.9rem; }
.muted { color: var(--dye-color-muted); }
.small { font-size: 0.85rem; }
.code { font-family: var(--dye-font-mono); font-size: 0.9em; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--dye-color-muted);
  background: var(--dye-color-surface);
  border: 1px dashed var(--dye-color-border);
  border-radius: var(--dye-radius);
}

.flash {
  margin-bottom: 1rem;
  padding: 0.65rem 0.9rem;
  white-space: pre-line;
  border-radius: var(--dye-radius);
  border-left: 3px solid;
}
.flash-ok { background: var(--dye-green-100); border-color: var(--dye-green-700); }
.flash-error { background: var(--dye-red-100); border-color: var(--dye-red-700); }
.flash-info { background: var(--dye-blue-100); border-color: var(--dye-blue-700); }

.tag {
  display: inline-block;
  margin: 0 0.15rem 0.15rem 0;
  padding: 0 0.4rem;
  font-size: 0.8rem;
  background: var(--dye-gray-100);
  border-radius: var(--dye-radius);
  white-space: nowrap;
}
.tag-ok { background: var(--dye-green-100); color: var(--dye-green-700); }
.tag-failed { background: var(--dye-red-100); color: var(--dye-red-700); }
.tag-skipped { background: var(--dye-gray-100); color: var(--dye-color-muted); }
.tag-running { background: var(--dye-blue-100); color: var(--dye-blue-700); }

/* Прогресс пересчёта ------------------------------------------------------ */

.progress { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--dye-color-border); }
.progress-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; font-weight: 500; }
.progress-head .muted { font-variant-numeric: tabular-nums; font-weight: 400; }
.progress-track { height: 0.6rem; background: var(--dye-gray-100); border-radius: var(--dye-radius); overflow: hidden; }
.progress-fill { width: 0; height: 100%; background: var(--dye-color-primary); transition: width 0.4s ease; }
.progress .hint { margin-top: 0.4rem; }
.progress.is-error .progress-fill { background: var(--dye-red-700); }
.progress.is-error #apply-stage { color: var(--dye-red-700); }
.btn:disabled { opacity: 0.55; cursor: progress; }

@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}

/* Таблицы ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; margin-bottom: 1rem; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-color-border);
}
.table th, .table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--dye-gray-100);
}
.table th { font-weight: 600; font-size: 0.85rem; color: var(--dye-color-muted); background: var(--dye-gray-25); border-bottom-color: var(--dye-color-border); }
.table tbody tr:hover { background: var(--dye-gray-25); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.is-muted td { color: var(--dye-gray-400); }
.table tr.is-chosen td { background: var(--dye-orange-50); }
.table tr.is-chosen td:first-child { box-shadow: inset 3px 0 0 var(--dye-color-primary); }
.table-queue td { vertical-align: middle; }

.samples { max-width: 22rem; color: var(--dye-color-muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.message { max-width: 28rem; font-size: 0.9rem; overflow-wrap: anywhere; }

.pager { display: flex; gap: 0.25rem; align-items: center; }
.pager a { padding: 0.25rem 0.6rem; border: 1px solid var(--dye-color-border); border-radius: var(--dye-radius); background: var(--dye-color-surface); }
.pager a.is-active { background: var(--dye-color-primary); border-color: var(--dye-color-primary); color: #fff; }

/* Формы -------------------------------------------------------------------- */

input, select, textarea, button { font: inherit; color: inherit; }

input:not([type=checkbox]), select, textarea {
  padding: 0.35rem 0.5rem;
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-color-border);
  border-radius: var(--dye-radius);
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--dye-color-primary); outline: none; box-shadow: 0 0 0 2px var(--dye-color-primary-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  color: var(--dye-color-text);
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-gray-400);
  border-radius: var(--dye-radius);
}
.btn:hover { background: var(--dye-gray-50); text-decoration: none; }
.btn-primary { color: #fff; background: var(--dye-color-primary); border-color: var(--dye-color-primary); }
.btn-primary:hover { background: var(--dye-color-primary-strong); border-color: var(--dye-color-primary-strong); }
.btn-danger { color: var(--dye-red-700); border-color: var(--dye-red-700); }
.btn-small { padding: 0.2rem 0.55rem; font-size: 0.9rem; }

.inline-form, .filters, .toolbar, .actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.75rem; }
.filters, .toolbar { margin-bottom: 1rem; }
.inline-form label, .filters label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--dye-color-muted); }
.table .inline-form { align-items: center; }
.table .inline-form select { max-width: 16rem; }
form.inline { display: inline; }

.input-unit { width: 4.5rem; }
.input-id { width: 6rem; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 500; }
.field small { font-weight: 400; color: var(--dye-color-muted); }
.field-wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.form-actions { grid-column: 1 / -1; }

.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--dye-color-border); }

/* Товар -------------------------------------------------------------------- */

.product-head { display: grid; grid-template-columns: 1fr 18rem; gap: 1.5rem; }
.product-name { margin: 0 0 0.75rem; font-size: 1.25rem; }
.props { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0; }
.props dt { color: var(--dye-color-muted); }
.props dd { margin: 0; }
.thumbs { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.thumbs img { width: 72px; height: 72px; object-fit: contain; background: var(--dye-gray-25); border: 1px solid var(--dye-color-border); border-radius: var(--dye-radius); }

.price-box { display: flex; flex-direction: column; gap: 0.35rem; padding-left: 1.5rem; border-left: 1px solid var(--dye-color-border); }
.price { font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stack-form { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.75rem; }
.stack-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--dye-color-muted); }

.description { max-width: 52rem; }

.value-cloud { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.value-chip { padding: 0.15rem 0.5rem; background: var(--dye-color-surface); border: 1px solid var(--dye-color-border); border-radius: var(--dye-radius); }

/* Вход --------------------------------------------------------------------- */

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: min(22rem, 92vw);
  padding: 1.75rem;
  background: var(--dye-color-surface);
  border: 1px solid var(--dye-color-border);
  border-top: 3px solid var(--dye-color-primary);
  border-radius: var(--dye-radius);
}
.login h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }

/* Узкие экраны ------------------------------------------------------------- */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 1rem; }
  .queues { grid-template-columns: 1fr; }
  .product-head { grid-template-columns: 1fr; }
  .price-box { padding-left: 0; border-left: 0; }
}
