:root {
  --bg: #0f1117;
  --panel: #181b24;
  --panel-2: #20242f;
  --line: #2b3040;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --accent: #7c5cff;
  --accent-2: #a48bff;
  --green: #3ecf8e;
  --sale: #a4d007;
  --sale-bg: #4c6b22;
  --danger: #ff6b6b;
  --gold: #ffc53d;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Шапка */
.top { position: sticky; top: 0; z-index: 5; background: rgba(15,17,23,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; padding-bottom: 10px; }
h1 { font-size: 22px; margin: 0; letter-spacing: .2px; }
.top-actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 10px 12px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--panel-2); font-size: 12px; color: var(--muted); }

/* Кнопки */
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.done { border-color: color-mix(in srgb, var(--green) 50%, transparent); color: var(--green); }
.btn.done:hover { background: color-mix(in srgb, var(--green) 15%, transparent); }
.btn.icon { padding: 5px 8px; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* Панель инструментов */
.toolbar { display: flex; gap: 10px; align-items: center; margin: 18px 0 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select, .dlg input, .dlg select, .dlg textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none;
}
.toolbar input:focus, .dlg input:focus, .dlg select:focus, .dlg textarea:focus { border-color: var(--accent); }
.toolbar input { flex: 1 1 220px; min-width: 0; }
.total { color: var(--muted); font-size: 14px; margin-left: auto; }

/* Карточки */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; padding-bottom: 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: border-color .15s, transform .15s; }
.card:hover { border-color: #3a4156; transform: translateY(-2px); }
.cover { position: relative; aspect-ratio: 460 / 215; background: var(--panel-2); display: block; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: #fff; text-align: center; padding: 10px;
  background: linear-gradient(135deg, #3b2a7a, #1d4b6b); }
.badges { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 6px; background: rgba(0,0,0,.72); }
.badge.sale { background: var(--sale-bg); color: var(--sale); }
.badge.soon { background: rgba(124,92,255,.9); color: #fff; }
.badge.free { background: rgba(62,207,142,.9); color: #062; }
.body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.title { font-size: 16px; font-weight: 650; margin: 0; }
.title a { color: inherit; text-decoration: none; }
.title a:hover { color: var(--accent-2); }
.desc { color: var(--muted); font-size: 13.5px; margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tags { font-size: 12px; color: var(--muted); }
.note { background: color-mix(in srgb, var(--accent) 12%, transparent); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 6px; font-size: 13.5px; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.link { font-size: 13px; color: var(--text); text-decoration: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link:hover { border-color: var(--accent); color: var(--accent-2); }
.price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.price b { font-size: 16px; }
.price s { color: var(--muted); font-size: 13px; }
.price .rub { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 6px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; }
.actions select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 13px; flex: 1 1 auto; min-width: 0; }
.actions .spacer { flex: 1; }
.actions select + .spacer { flex: 0; }
.meta { font-size: 12.5px; color: var(--muted); }
.rating { color: var(--gold); letter-spacing: 1px; }
.review { font-size: 13.5px; font-style: italic; }
.empty { text-align: center; color: var(--muted); padding: 50px 0; }

/* Диалоги */
.dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0 0 4px; font-size: 19px; }
.dlg label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.dlg label > * { color: var(--text); font-size: 15px; }
.dlg textarea { resize: vertical; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 0; min-height: 0; }
.error:empty { display: none; }
.results { list-style: none; margin: -4px 0 0; padding: 0; max-height: 280px; overflow-y: auto; border-radius: 10px; }
.results:empty { display: none; }
.results li { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; }
.results li:hover, .results li.sel { background: var(--panel-2); }
.results img { width: 92px; height: 34px; object-fit: cover; border-radius: 4px; flex: none; background: var(--panel-2); }
.results .r-name { flex: 1; font-size: 14px; }
.results .r-price { font-size: 13px; color: var(--muted); white-space: nowrap; }
.picked { display: flex; gap: 10px; align-items: center; background: var(--panel-2); border: 1px solid var(--accent); border-radius: 10px; padding: 8px; }
.picked img { width: 120px; border-radius: 6px; }
.picked .x { margin-left: auto; }
.stars { display: flex; gap: 4px; font-size: 30px; }
.stars button { background: none; border: 0; cursor: pointer; color: var(--line); padding: 0 2px; line-height: 1; }
.stars button.on { color: var(--gold); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: calc(100vw - 32px); }
.toast button { margin-left: 10px; }

@media (max-width: 560px) {
  h1 { font-size: 19px; white-space: nowrap; }
  .lbl { display: none; }
  #btnAdd, #btnLogin { min-width: 40px; font-size: 17px; }
  .total { margin-left: 0; width: 100%; }
  .grid { grid-template-columns: 1fr; }
}
