:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1c2430; --muted: #6b7785;
  --line: #dde3ea; --accent: #2563eb; --accent-ink: #ffffff;
  --ok: #16a34a; --warn: #d97706; --danger: #dc2626; --pill: #eef2f7;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 1px 2px rgba(20,30,50,.06);
}
[data-theme="dark"] {
  --bg: #0f141b; --panel: #19212c; --ink: #e6edf5; --muted: #93a1b1;
  --line: #2a3543; --accent: #3b82f6; --accent-ink: #ffffff;
  --ok: #22c55e; --warn: #f59e0b; --danger: #ef4444; --pill: #222c39;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* --- Шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.brand { font-weight: 700; font-size: 16px; }
.rate-box { display: flex; align-items: center; gap: 6px; margin-left: 8px; padding: 4px 10px;
  background: var(--pill); border-radius: 8px; font-size: 13px; }
.rate-value { font-weight: 700; }
.rate-meta { color: var(--muted); font-size: 12px; }
.rate-box.stale { background: color-mix(in srgb, var(--warn) 22%, var(--pill)); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user { color: var(--muted); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; }
.inline { display: inline; margin: 0; }

/* --- Панель параметров --- */
.params {
  display: flex; flex-wrap: wrap; gap: 18px; padding: 14px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.param-group { display: flex; flex-direction: column; gap: 6px; }
.param-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; max-width: 560px; }
.pill {
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--pill);
  font-variant-numeric: tabular-nums; user-select: none;
}
.pill:hover { border-color: var(--accent); }
.pill.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.free { width: 92px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.free.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.free.invalid { border-color: var(--danger); }
select { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.presets .preset-actions { display: flex; gap: 6px; }
.mini { padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--pill); font-size: 13px; }
.mini.danger { color: var(--danger); }

.formula-hint {
  padding: 8px 18px; color: var(--muted); font-size: 13px; background: var(--bg);
  border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; min-height: 18px;
}

/* --- Таблица строк --- */
.work { padding: 0 18px 8px; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.grid thead th { position: sticky; top: 56px; background: var(--bg); z-index: 5; font-size: 12px; color: var(--muted); }
.col-idx { width: 40px; color: var(--muted); }
.col-art { width: 30%; }
.col-price, .col-result { width: 18%; }
.result-cur { color: var(--muted); font-weight: 400; }
.grid input { width: 100%; padding: 5px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; }
.grid input:focus { border-color: var(--accent); background: var(--panel); outline: none; }
.grid .cell-price input { text-align: right; font-variant-numeric: tabular-nums; }
.grid .cell-price input.invalid { color: var(--danger); }
.cell-result { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cell-result .empty { color: var(--muted); font-weight: 400; }
.cell-act { display: flex; gap: 6px; }
.cell-act button { padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--pill); font-size: 12px; }
.row-changed { animation: flash 0.7s ease; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 18%, transparent); } to { background: transparent; } }

/* --- Нижняя панель --- */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 18px;
  background: var(--panel); border-top: 1px solid var(--line); position: sticky; bottom: 0; box-shadow: var(--shadow); }
.actions button, .file-btn {
  padding: 7px 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--pill); font-weight: 500;
}
.actions button.danger { color: var(--danger); }
.file-btn { cursor: pointer; }
.actions .spacer { flex: 1; }
.dirty { color: var(--warn); font-size: 13px; }

.dropzone { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 18%, rgba(0,0,0,.4)); color: #fff; font-size: 22px; font-weight: 700; }

/* --- Модалки --- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(8,12,20,.45); }
.modal-card { background: var(--panel); border-radius: 12px; padding: 18px; width: 440px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 10px; }
.modal-wide .modal-card { width: 900px; }
.modal-card h3 { margin: 0; }
.modal-card textarea, .modal-card input[type=text] { width: 100%; padding: 8px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 4px; }
.modal-actions button { padding: 7px 14px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: #fff; }
.modal-actions .ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.import-controls { display: flex; gap: 16px; flex-wrap: wrap; align-items: end; }
.import-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.preview-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.preview { border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.preview th, .preview td { padding: 4px 8px; border: 1px solid var(--line); }
.preview th { background: var(--bg); position: sticky; top: 0; }
.preview col.price-col, .preview .price-col { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.import-summary { padding: 8px 10px; background: var(--pill); border-radius: 8px; font-size: 13px; }
.dl-btn { padding: 7px 14px; border: 1px solid var(--ok); border-radius: 8px; background: var(--ok); color: #fff; text-decoration: none; }

label { display: flex; flex-direction: column; gap: 4px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }

/* --- Тосты --- */
.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); }

/* --- Авторизация --- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow);
  width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-sub { margin: 0 0 6px; color: var(--muted); }
.auth-card label { font-size: 13px; color: var(--muted); }
.auth-card input { padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.auth-card button { padding: 10px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
.auth-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; }

@media (max-width: 1400px) { .pills { max-width: 100%; } }
