:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #16191f;
  --muted: #667085;
  --line: #e3e6ec;
  --accent: #2357d9;
  --accent-ink: #ffffff;
  --ok: #12805c;
  --warn: #b54708;
  --bad: #c0362c;
  --encar: #e8f0ff;
  --carsensor: #fff1e6;
  --dongchedi: #ffe9ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --ink: #e8eaee;
    --muted: #98a2b3;
    --line: #2c313a;
    --accent: #5b8cff;
    --encar: #1d2a44;
    --carsensor: #3a2a1c;
    --dongchedi: #3a1f25;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 17px; }
.topbar nav { display: flex; gap: 12px; margin-left: auto; align-items: center; }
.topbar .muted { font-size: 12px; }

.layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; padding: 20px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; padding: 12px; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel h2 { font-size: 15px; margin-bottom: 12px; }
.filters { position: sticky; top: 72px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label, .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 400; color: var(--ink); font-size: 14px; }
.checks input { width: auto; }
.model-src { font-size: 12px; color: var(--muted); margin: 2px 0; display: flex; justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn--small { padding: 4px 10px; font-size: 13px; }
.btn--danger { color: var(--bad); }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn--block { width: 100%; }

.status-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 12px; }
.chip--ok { color: var(--ok); }
.chip--bad { color: var(--bad); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; }
.card:hover { border-color: var(--muted); }
.card__img { aspect-ratio: 4 / 3; background: var(--bg) center / cover no-repeat; position: relative; }
.card__src { position: absolute; left: 8px; top: 8px; font-size: 11px; padding: 2px 8px; border-radius: 999px; color: #1b1f27; font-weight: 600; }
.src-encar { background: #cfe0ff; }
.src-carsensor { background: #ffd9bd; }
.src-dongchedi { background: #ffc9d1; }
.card__body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card__title { font-weight: 600; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card__meta { color: var(--muted); font-size: 12px; }
.card__price { font-size: 17px; font-weight: 700; margin-top: auto; padding-top: 6px; }
.card__price small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.card__actions { display: flex; gap: 6px; margin-top: 6px; }
.flags { display: flex; gap: 4px; flex-wrap: wrap; }
.flag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); }
.in-draft { outline: 2px solid var(--accent); }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.more { display: flex; justify-content: center; margin: 18px 0; }

/* Модальное окно карточки */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 16, 0.55); display: none; z-index: 20; padding: 24px; overflow: auto; }
.modal.open { display: block; }
.modal__box { background: var(--panel); max-width: 1040px; margin: 0 auto; border-radius: 14px; padding: 20px; position: relative; }
.modal__close { position: absolute; right: 12px; top: 12px; }
.detail { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }
.detail > * { min-width: 0; }
@media (max-width: 800px) { .detail { grid-template-columns: 1fr; } .modal { padding: 8px; } }
.gallery__main { aspect-ratio: 4 / 3; background: var(--bg) center / contain no-repeat; border-radius: 10px; }
.gallery__thumbs { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; padding-bottom: 4px; }
.gallery__thumbs img { width: 76px; height: 57px; object-fit: cover; border-radius: 6px; cursor: pointer; opacity: 0.75; flex: none; }
.gallery__thumbs img.active, .gallery__thumbs img:hover { opacity: 1; outline: 2px solid var(--accent); }
.specs { width: 100%; border-collapse: collapse; margin-top: 8px; }
.specs td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.specs td:first-child { color: var(--muted); width: 45%; padding-right: 10px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.box h3 { font-size: 13px; margin-bottom: 6px; }
.big-price { font-size: 26px; font-weight: 700; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }

/* Плашка черновика КТП */
.tray {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 10;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: none; gap: 12px; align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.tray.show { display: flex; }
.tray .btn { background: var(--panel); color: var(--ink); }

.toasts { position: fixed; right: 16px; top: 70px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: var(--shadow); }
.toast--bad { background: var(--bad); color: #fff; }
.toast--ok { background: var(--ok); color: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }
