:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #1b1f24;
  --muted: #6b7380;
  --accent: #e8590c;
  --accent-text: #ffffff;
  --down: #12805c;
  --down-bg: #e6f4ee;
  --up: #c92a2a;
  --up-bg: #fbeaea;
  --warn: #b35c00;
  --ozon: #005bff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #23272f;
    --border: #2e333c;
    --text: #e8eaed;
    --muted: #9aa2ae;
    --accent: #ff7a33;
    --accent-text: #1a1d23;
    --down: #4cc38a;
    --down-bg: #15301f;
    --up: #ff6b6b;
    --up-bg: #3a1d1d;
    --warn: #f0a04b;
    --ozon: #5c9dff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

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

.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }

/* --- шапка --- */
.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.brand small { font-weight: 500; color: var(--muted); font-size: 14px; margin-left: 6px; }
.top .spacer { flex: 1; }
.status { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }

/* --- кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.icon-btn {
  width: 32px; height: 32px; padding: 0; border-radius: 8px; border: 1px solid transparent;
  background: transparent; cursor: pointer; display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--up); }
.icon-btn svg, .btn svg { width: 16px; height: 16px; }

/* --- добавление --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.add { padding: 14px; margin-bottom: 16px; }
.add label { display: block; font-weight: 600; margin-bottom: 8px; }
.add textarea {
  width: 100%; min-height: 84px; resize: vertical; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px;
}
.add textarea:focus, .login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.add .row { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.msg { font-size: 13px; color: var(--muted); }
.msg.err { color: var(--up); }
.msg.ok { color: var(--down); }

/* --- таблица --- */
.table-card { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.thumb {
  width: 64px; height: 64px; padding: 0; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); overflow: hidden; cursor: zoom-in; display: block;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.empty { cursor: default; display: grid; place-items: center; color: var(--muted); }

.title a { text-decoration: none; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.title a:hover { color: var(--accent); text-decoration: underline; }
.meta { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.ali { color: var(--accent); }
.badge.ozon { color: var(--ozon); }
.card-price { color: var(--ozon); font-size: 12px; font-weight: 600; }

.attention {
  padding: 12px 14px; margin-bottom: 16px; border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, var(--surface));
}
.attention p { margin: 0 0 6px; }
.attention details { font-size: 13px; }
.attention summary { cursor: pointer; color: var(--muted); }
.attention ol { margin: 8px 0 0; padding-left: 20px; }
.attention li { margin: 4px 0; }
.attention code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.error { color: var(--warn); font-size: 12px; margin-top: 4px; }

.price { font-size: 16px; font-weight: 700; }
.price .range { font-weight: 500; color: var(--muted); font-size: 13px; }
.orig { color: var(--muted); text-decoration: line-through; font-size: 12px; }

.delta { display: inline-block; font-weight: 600; font-size: 13px; padding: 2px 8px; border-radius: 999px; }
.delta.down { color: var(--down); background: var(--down-bg); }
.delta.up { color: var(--up); background: var(--up-bg); }
.sub { font-size: 12px; color: var(--muted); }
.actions { white-space: nowrap; text-align: right; }

.empty-state { padding: 40px 16px; text-align: center; color: var(--muted); }

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

/* --- модалки --- */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: 100vw; max-height: 100vh; }
dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.img-modal img { display: block; max-width: min(92vw, 1100px); max-height: 88vh; border-radius: 8px; background: #fff; cursor: zoom-out; }
.img-modal .cap { color: #fff; text-align: center; margin-top: 8px; font-size: 13px; max-width: min(92vw, 1100px); }
.hist-modal .box { background: var(--surface); border-radius: var(--radius); width: min(560px, calc(100vw - 32px)); padding: 16px; }
.hist-modal h3 { margin: 0 0 4px; font-size: 15px; }
.hist-modal .close { float: right; }
.hist-modal svg.chart { width: 100%; height: 140px; display: block; margin: 12px 0; }
.hist-modal .list { max-height: 260px; overflow: auto; }
.hist-modal table td { padding: 6px 4px; }

/* --- вход --- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(340px, 100%); padding: 24px; }
.login h1 { margin: 0 0 16px; font-size: 20px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.login input {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.login .btn { width: 100%; margin-top: 16px; height: 40px; }

/* --- телефон: строки таблицы превращаются в карточки --- */
@media (max-width: 760px) {
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr {
    display: grid; grid-template-columns: 72px 1fr auto; column-gap: 12px; row-gap: 4px;
    padding: 12px; border-bottom: 1px solid var(--border);
  }
  tr:last-child { border-bottom: 0; }
  td { padding: 0; border: 0; }
  td.c-img { grid-row: 1 / span 3; }
  td.c-title { grid-column: 2 / span 2; }
  td.c-price, td.c-delta { grid-column: 2; text-align: left; }
  td.c-seen { display: none; }
  td.c-checked { grid-column: 2 / span 2; text-align: left; }
  td.c-actions { grid-column: 2 / span 2; text-align: left; margin-left: -6px; }
  .num { text-align: left; }
}
