:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 19px; }
h2 { font-size: 15px; }

code {
  background: #eef2f7;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

/* ---------- шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
}

.sub { margin: 0; color: var(--muted); font-size: 13px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #94a3b8;
}
.dot.running { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.done { background: var(--green); }
.dot.error { background: var(--red); }
.dot.cancelled { background: var(--amber); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------- табы ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow-x: auto;
}

.tab {
  border: none;
  background: none;
  padding: 9px 14px;
  border-radius: 8px 8px 0 0;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover { color: var(--text); background: #f8fafc; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- сетка ---------- */
main { padding: 20px 24px 60px; max-width: 1280px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric {
  margin: 8px 0 2px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.error-line {
  min-height: 18px;
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--red);
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
  margin-top: 10px;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2563eb, #22d3ee);
  transition: width .3s ease;
}

/* ---------- панели ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

/* ---------- кнопки ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}

.actions-small { margin-top: 8px; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s ease;
}

.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn.small { padding: 5px 10px; font-size: 13px; }

.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: #b91c1c; }

.btn.danger-ghost { color: var(--red); border-color: #fecaca; }
.btn.danger-ghost:hover { background: #fef2f2; }

/* ---------- прогресс ---------- */
.progress-block { margin: 12px 0 4px; }

.progress {
  height: 10px;
  background: #eef2f7;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2563eb, #22d3ee);
  transition: width .25s ease;
}

.progress-text {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text);
}

/* ---------- журнал ---------- */
.log {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  height: 300px;
  overflow: auto;
}

.log .row { display: flex; gap: 8px; }
.log .t { color: #64748b; flex: none; }
.log .lvl { flex: none; width: 58px; }
.log .lvl.INFO { color: #38bdf8; }
.log .lvl.WARNING { color: #fbbf24; }
.log .lvl.ERROR { color: #f87171; }
.log .lvl.DEBUG { color: #94a3b8; }
.log .msg { white-space: pre-wrap; word-break: break-word; }
.log .src { color: #64748b; }

/* ---------- формы ---------- */
.settings { display: grid; gap: 18px; }

.settings fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 16px;
  margin: 0;
}

.settings legend {
  padding: 0 6px;
  font-weight: 650;
  font-size: 13.5px;
  color: var(--accent);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

label { display: block; font-size: 13px; color: var(--muted); }

input[type=text], input[type=search], select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--accent);
}

textarea { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }

label.block { display: block; margin-top: 12px; }

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 6px;
}

.code {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  overflow: auto;
  max-height: 460px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- таблицы ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  position: sticky;
  top: 0;
}

.table td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.table tr:hover td { background: #f8fafc; }
.table tr.unmapped td { background: #fef2f2; }
.table tr.unmapped:hover td { background: #fee2e2; }

.table td select { margin: 0; padding: 5px 8px; font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.synced { background: #dcfce7; color: #15803d; }
.badge.pending { background: #e0e7ff; color: #3730a3; }
.badge.error { background: #fee2e2; color: #b91c1c; }

.nums { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input, .filters select { width: auto; margin: 0; }

@media (max-width: 640px) {
  main { padding: 14px 12px 48px; }
  .topbar { padding: 12px 14px; }
  .tabs { padding: 8px 12px 0; }
  .metric { font-size: 24px; }
}

/* ---------- авторизация ---------- */
.auth-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #e8eefb 0%, #f4f6fb 55%, #eaf1fd 100%); padding: 24px; z-index: 50;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card h1 { font-size: 18px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.auth-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- шапка: пользователь ---------- */
.topbar-right { display: flex; align-items: center; gap: 16px; }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.badge.role { background: #dbeafe; color: #1e40af; }

/* ---------- список переносов ---------- */
.transfers-bar { margin: 18px auto 0; max-width: 1280px; padding: 0 20px; }
.transfers-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.transfers-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.transfers-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.transfer-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, transform .15s;
}
.transfer-card:hover { transform: translateY(-1px); border-color: #c7d7f5; }
.transfer-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.transfer-card p { margin: 4px 0; }
.tc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tc-actions { display: flex; gap: 6px; margin-top: 8px; }
.chip { background: #eef2f7; border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); }
.muted-chip { background: #f1f5f9; }
.badge.test-contour { background: #fef3c7; color: #92400e; font-weight: 600; }

/* ---------- контур ---------- */
.contour-choice { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; }
.contour-choice .radio { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.warning-hint { color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; }

/* ---------- модальные окна ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 20px; overflow: auto; z-index: 40;
}
.modal-card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 560px; padding: 22px;
}
.wide-card { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.inline-form input, .inline-form select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.small { font-size: 12px; }
