:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #17202c;
  --muted: #687385;
  --border: #e1e6ed;
  --border-strong: #cdd5df;
  --accent: #1d5fbf;
  --accent-hover: #174d9c;
  --accent-soft: #e9f1fc;
  --red: #c00000;
  --red-soft: #fdecec;
  --orange: #b85410;
  --orange-soft: #fff3e6;
  --green: #2a7a3b;
  --green-soft: #eaf6ec;
  --sidebar: #142131;
  --sidebar-text: #c6d0dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 33, 49, .06), 0 2px 8px rgba(20, 33, 49, .04);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 650; }
p { margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* каркас */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand .logo { font-weight: 700; font-size: 16px; color: #fff; letter-spacing: .01em; }
.brand .sub { font-size: 12px; color: #8b9bb0; margin-top: 2px; }
.nav { padding: 12px 10px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(77, 140, 230, .18); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: .85; }
.nav .sep { height: 1px; background: rgba(255,255,255,.07); margin: 10px 4px; }
.me { padding: 14px 20px 18px; border-top: 1px solid rgba(255,255,255,.07); font-size: 13px; }
.me .who { color: #fff; font-weight: 600; }
.me .role { color: #8b9bb0; font-size: 12px; }
.me form { margin-top: 8px; }
.me button { background: none; border: 1px solid rgba(255,255,255,.18); color: var(--sidebar-text); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.me button:hover { color: #fff; border-color: rgba(255,255,255,.35); }
.me a { color: #9fb6d6; font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 32px 0;
}
.content { padding: 18px 32px 48px; max-width: 1360px; width: 100%; }
.page-sub { color: var(--muted); margin-bottom: 18px; }

.balance {
  display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; color: var(--muted); box-shadow: var(--shadow); white-space: nowrap;
}
.balance b { color: var(--text); }
.balance.low b { color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa6b5; display: inline-block; }
.dot.ok { background: #36a852; } .dot.bad { background: var(--red); }

/* панели */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 16px; }
.card.tight { padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.step { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12.5px; margin-right: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* формы */
label { font-weight: 500; }
.field { margin-bottom: 14px; }
.field > label { display: block; margin-bottom: 5px; font-size: 13px; color: #344052; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; min-height: 260px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 95, 191, .14); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); vertical-align: -3px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; cursor: pointer; background: #fff; font-weight: 500; user-select: none;
}
.check:hover { border-color: var(--accent); }
.check.on { border-color: var(--accent); background: var(--accent-soft); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: #fff; color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #aab6c5; background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: #e9b4b4; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.big { padding: 11px 24px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 600; color: #4b5668; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border-strong); background: #f8fafc; position: sticky; top: 0; z-index: 1; }
.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.t tr:hover td { background: #fafbfd; }
#prod-table tbody tr { cursor: pointer; }
.t .num { text-align: right; white-space: nowrap; }
.t .nowrap { white-space: nowrap; }
.t td.wrap { word-break: normal; overflow-wrap: anywhere; min-width: 220px; }
#items td.small { min-width: 150px; }
.t input[type=text] { padding: 5px 8px; font-size: 13px; }
.t select { padding: 5px 8px; font-size: 13px; }
.scroll { max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }

/* бейджи и статусы */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f5; color: #4b5668; white-space: nowrap; }
.badge.ok, .badge.done, .badge.full, .badge.confirmed { background: var(--green-soft); color: var(--green); }
.badge.warn, .badge.partial, .badge.paused, .badge.parent_only, .badge.done_errors { background: var(--orange-soft); color: var(--orange); }
.badge.err, .badge.failed, .badge.empty, .badge.not_found, .badge.cancelled { background: var(--red-soft); color: var(--red); }
.badge.run, .badge.running, .badge.queued { background: var(--accent-soft); color: var(--accent); }
.badge.pending { background: #f1f3f6; color: #6b7686; }

.progress { height: 8px; background: #e8edf3; border-radius: 999px; overflow: hidden; min-width: 120px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.progress.big { height: 12px; }

.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { background: var(--green-soft); border-color: #bfe2c6; color: #1d5c2b; }
.alert.err { background: var(--red-soft); border-color: #f0c2c2; color: #8a1414; }
.alert.warn { background: var(--orange-soft); border-color: #f3d2b0; color: #7a3a09; }
.alert.info { background: var(--accent-soft); border-color: #c9dbf5; color: #173f78; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.red { color: var(--red); } .orange { color: var(--orange); } .green { color: var(--green); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb0 { margin-bottom: 0; }
.hidden { display: none !important; }

/* оценка */
.estimate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.estimate .cell { background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; }
.estimate .lbl { color: var(--muted); font-size: 12px; }
.estimate .val { font-size: 19px; font-weight: 650; margin-top: 2px; }
@media (max-width: 1100px) { .estimate { grid-template-columns: 1fr 1fr; } }

/* поиск раздела */
.picker { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border-strong); border-radius: 9px; box-shadow: 0 8px 28px rgba(20,33,49,.14); max-height: 360px; overflow: auto; z-index: 20; }
.suggest div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.suggest div:hover, .suggest div.active { background: var(--accent-soft); }
.suggest .path { color: var(--muted); font-size: 12px; }
.chosen { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--accent-soft); border: 1px solid #c9dbf5; border-radius: 9px; }
.chosen .path { color: #46597a; font-size: 12.5px; }

/* модалка */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 34, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.25); padding: 24px 26px; }
.modal h2 { font-size: 18px; }
.modal ul { padding-left: 18px; margin: 8px 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* результат товара */
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; }
.kv .k { color: var(--muted); }
.res-table td:first-child { width: 210px; font-weight: 600; background: #fafbfc; }
.res-table td { font-size: 13px; }
.res-table .site { color: var(--text); }
.res-table .new { color: var(--red); }
.res-table .warn { color: var(--orange); }
.res-table .muted { color: #8a94a3; }
.src { padding: 8px 0; border-bottom: 1px solid var(--border); }
.src:last-child { border-bottom: 0; }
.log { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: #0f1823; color: #c9d4e2; border-radius: 9px; padding: 12px 14px; max-height: 300px; overflow: auto; white-space: pre-wrap; }

/* вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-strong); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* вход */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #142131 0%, #1d3350 100%); padding: 20px; }
.login-card { width: 380px; background: #fff; border-radius: 14px; padding: 30px 30px 26px; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.login-card h1 { font-size: 20px; }
.login-card .btn { width: 100%; margin-top: 6px; }

.help h2 { margin-top: 26px; }
.help li { margin-bottom: 6px; }
.legend span { display: inline-block; margin-right: 18px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }

@media (max-width: 1180px) {
  .sidebar { width: 200px; flex-basis: 200px; }
  .content { padding: 16px 20px 40px; }
  .topbar { padding: 16px 20px 0; flex-wrap: wrap; }
}
