:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e3e2dd;
  --accent: #1f5fbf;
  --ok: #1d7a46;
  --ok-bg: #e7f4ec;
  --warn: #9a6200;
  --warn-bg: #fdf3df;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --radius: 12px;
  /* Кнопки одинаковые в обеих темах: белый текст на насыщенном фоне. */
  --btn-primary: #1f5fbf;
  --btn-danger: #c62828;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615;
    --surface: #20201e;
    --text: #ecebe6;
    --muted: #a3a29b;
    --line: #34332f;
    --accent: #7aa7f0;
    --ok: #6fd19a;
    --ok-bg: #1b3326;
    --warn: #f0c060;
    --warn-bg: #3a2f17;
    --bad: #f28b82;
    --bad-bg: #3d1f1d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 0.9em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.top nav a.on { background: var(--bg); color: var(--text); }

main { max-width: 1080px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid .card { margin-bottom: 0; }
.big { font-size: 20px; font-weight: 700; margin: 0; }
.muted { color: var(--muted); margin: 4px 0 0; }
.note { font-size: 13px; color: var(--warn); margin: 6px 0 0; }

.health.ok { border-left: 4px solid var(--ok); }
.health.warn { border-left: 4px solid var(--warn); }
.health.bad { border-left: 4px solid var(--bad); }

.stop {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.stop p { margin: 2px 0 0; color: var(--muted); }
.stop.on { background: var(--bad-bg); border-color: var(--bad); }
.stop.on strong { color: var(--bad); }
.stop form { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }
button.danger { background: var(--btn-danger); border-color: var(--btn-danger); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 6px; }

input {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}

.login { max-width: 360px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 10px; }
.login h1 { margin-bottom: 8px; }
.error { color: var(--bad); margin: 0; }

.flash {
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.counts { list-style: none; margin: 0; padding: 0; }
.counts li a { display: flex; justify-content: space-between; padding: 4px 0; color: var(--text); }

.chips { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li a {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.chips li.attention a { background: var(--warn-bg); border-color: var(--warn); }
.chips li.on a { background: var(--text); color: var(--surface); border-color: var(--text); }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.wrap { max-width: 360px; overflow-wrap: anywhere; }

.status { padding: 2px 8px; border-radius: 999px; font-size: 13px; white-space: nowrap; background: var(--bg); }
.s-done { background: var(--ok-bg); color: var(--ok); }
.s-failed { background: var(--bad-bg); color: var(--bad); }
.s-waiting { background: var(--warn-bg); color: var(--warn); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed p { margin: 4px 0 0; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.tag { background: var(--bg); padding: 0 8px; border-radius: 999px; }

@media (max-width: 600px) {
  .top { justify-content: space-between; }
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .top nav a { white-space: nowrap; }
}

a.button {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--text);
}
a.button.primary { background: var(--btn-primary); border-color: var(--btn-primary); color: #fff; }
a.button:hover { text-decoration: none; filter: brightness(1.08); }

.products { list-style: none; margin: 0; padding: 0; }
.products li { border-bottom: 1px solid var(--line); }
.products li:last-child { border-bottom: 0; }
.products a { display: flex; gap: 12px; align-items: center; padding: 10px 0; color: var(--text); }
.products a:hover { text-decoration: none; background: var(--bg); }
.products img, .products .noimg {
  width: 64px; height: 64px; flex: none; object-fit: cover; border-radius: 8px; background: var(--bg);
}
.products .noimg { display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.products .info { display: flex; flex-direction: column; min-width: 0; }
.products .info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.products .info .muted { margin: 0; font-size: 13px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.pre { white-space: pre-wrap; margin: 0; }

.lead { font-size: 16px; margin: 4px 0 16px; }
h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
.attention-card { border-left: 4px solid var(--warn); }
.stack { display: flex; flex-direction: column; gap: 8px; }
textarea {
  font: inherit; width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--text); resize: vertical;
}
table.money td:not(:first-child), table.money th:not(:first-child) { text-align: right; white-space: nowrap; }
tr.good th, th.good { color: var(--ok); }
tr.bad th { color: var(--bad); }
.s-parsed, .s-ready_for_kaspi { background: var(--ok-bg); color: var(--ok); }
.s-needs_info, .s-low_margin, .s-postponed { background: var(--warn-bg); color: var(--warn); }
.s-not_product { background: var(--bad-bg); color: var(--bad); }

.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
.stack input { width: 100%; }
label { font-size: 14px; color: var(--muted); }

.shot { margin: 0; }
.shot img { border: 2px solid transparent; }
.shot.ok img { border-color: var(--ok); }
.shot.bad img { opacity: 0.55; }
.shot figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.shot.ok figcaption { color: var(--ok); }
.upload { margin-top: 12px; }

.meter { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.meter span { display: block; height: 100%; background: var(--accent); }

.gallery.wide { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
