:root {
  --font-ui: "Rubik", "Segoe UI", Arial, sans-serif;
  --bg: #f3f7fb;
  --bg-soft: #f8fbfe;
  --card: #ffffff;
  --card-soft: #f9fbfd;
  --text: #132238;
  --text-strong: #071a2f;
  --muted: #6f7f92;
  --line: #e1e8f0;
  --line-strong: #ccd8e5;
  --nav: #071d32;
  --nav-2: #0a2946;
  --nav-hover: rgba(255,255,255,.075);
  --nav-active: rgba(37,171,225,.16);
  --blue: #238fdd;
  --blue-2: #25afe1;
  --blue-dark: #1476bc;
  --cyan: #2dc3e8;
  --green: #159b67;
  --green-bg: #eaf9f2;
  --amber: #b86d08;
  --amber-bg: #fff6e6;
  --red: #c43c45;
  --red-bg: #fff0f1;
  --shadow-sm: 0 2px 8px rgba(20,47,75,.045);
  --shadow: 0 10px 30px rgba(20,47,75,.075);
  --shadow-lg: 0 24px 70px rgba(6,29,50,.18);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, rgba(45,195,232,.09), transparent 26%),
    var(--bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

a { color: inherit; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 258px;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  color: #fff;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 7%, rgba(45,195,232,.18), transparent 28%),
    linear-gradient(180deg, var(--nav-2) 0%, var(--nav) 58%, #061827 100%);
  box-shadow: 16px 0 40px rgba(7,29,50,.08);
}

.sidebar::after {
  content: "";
  position: absolute;
  width: 190px;
  height: 190px;
  right: -120px;
  bottom: 90px;
  border: 1px solid rgba(45,195,232,.11);
  border-radius: 50%;
  box-shadow: 0 0 0 35px rgba(45,195,232,.025), 0 0 0 70px rgba(45,195,232,.018);
  pointer-events: none;
}

.brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 25px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue) 0%, var(--cyan) 100%);
  box-shadow: 0 8px 24px rgba(35,143,221,.28), inset 0 1px 0 rgba(255,255,255,.25);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -.02em;
}

.brand b {
  display: block;
  color: #fff;
  font-size: 18px;
  line-height: 1.05;
  letter-spacing: -.025em;
}

.brand small {
  display: block;
  margin-top: 5px;
  color: #90a5b9;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .035em;
}

.sidebar nav {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 5px;
}

.sidebar nav::before {
  content: "НАВИГАЦИЯ";
  padding: 2px 12px 8px;
  color: #6e879e;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .13em;
}

.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 43px;
  padding: 10px 13px 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #c6d3df;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}

.sidebar nav a::before {
  content: "";
  width: 5px;
  height: 5px;
  margin-right: 11px;
  border: 2px solid #6d879d;
  border-radius: 50%;
  transition: all .16s ease;
}

.sidebar nav a:hover {
  color: #fff;
  background: var(--nav-hover);
  transform: translateX(2px);
}

.sidebar nav a.active {
  color: #fff;
  border-color: rgba(61,190,232,.17);
  background: linear-gradient(90deg, var(--nav-active), rgba(255,255,255,.035));
  box-shadow: inset 3px 0 0 var(--cyan);
}

.sidebar nav a.active::before {
  border-color: var(--cyan);
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(45,195,232,.11);
}

.sidebar-user {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding: 15px 12px 11px;
  border-top: 1px solid rgba(255,255,255,.09);
}

.sidebar-user small {
  display: block;
  margin-bottom: 4px;
  color: #70879d;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .11em;
}

.sidebar-user b {
  display: block;
  overflow: hidden;
  color: #edf5fb;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
}

.logout {
  position: relative;
  z-index: 1;
  margin-top: 7px;
}

.logout button {
  width: 100%;
  height: 38px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 9px;
  color: #94a9bb;
  background: rgba(255,255,255,.025);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .16s ease;
}

.logout button:hover {
  color: #fff;
  border-color: rgba(255,255,255,.2);
  background: rgba(255,255,255,.07);
}

/* ===== Main layout ===== */
main {
  width: auto;
  max-width: 1900px;
  min-height: 100vh;
  margin-left: 258px;
  padding: 31px 36px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  color: var(--text-strong);
  font-size: 27px;
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: -.035em;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 39px;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: #33465b;
  background: #fff;
  box-shadow: 0 1px 2px rgba(21,45,70,.03);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
}

.btn:hover {
  border-color: #b9c9d8;
  background: #f9fbfd;
  box-shadow: 0 4px 12px rgba(21,45,70,.07);
  transform: translateY(-1px);
}

.btn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-2) 100%);
  box-shadow: 0 7px 18px rgba(35,143,221,.22);
}

.btn.primary:hover {
  background: linear-gradient(135deg, var(--blue-dark) 0%, #20a5d8 100%);
  box-shadow: 0 9px 22px rgba(35,143,221,.28);
}

.btn.danger {
  color: #aa2d36;
  border-color: #f0c9cd;
  background: #fffafa;
}

.btn.warning {
  color: #9b5c0a;
  border-color: #ead2aa;
  background: #fffaf1;
}

.btn.wide { width: 100%; }

/* ===== Cards / stats ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(155px, 1fr));
  gap: 15px;
  margin-bottom: 19px;
}

.stat {
  position: relative;
  min-height: 105px;
  padding: 18px 19px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
  box-shadow: var(--shadow-sm);
}

.stat::after {
  content: "";
  position: absolute;
  right: -22px;
  top: -26px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(45,195,232,.085), transparent 70%);
}

.stat span {
  position: relative;
  z-index: 1;
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.stat b {
  position: relative;
  z-index: 1;
  color: #0a2946;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 750;
  letter-spacing: -.035em;
}

.stat .progress { margin-top: 13px; }

.card {
  margin-bottom: 18px;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.card h2 {
  margin: 0 0 16px;
  color: var(--text-strong);
  font-size: 17px;
  line-height: 1.25;
  font-weight: 730;
  letter-spacing: -.018em;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 15px;
}

.section-title h2 { margin: 0; }

.section-title a,
td a {
  color: #167fc6;
  text-decoration: none;
  font-weight: 600;
}

.section-title a:hover,
td a:hover {
  color: #0b679f;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ===== Tables ===== */
.table-wrap {
  overflow: auto;
  margin: 0 -4px;
  border-radius: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c5d4e0 transparent;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  border-top: 1px solid #edf2f6;
  border-bottom: 1px solid #e5ecf2;
  color: #738297;
  background: #f8fafc;
  text-align: left;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .055em;
  text-transform: uppercase;
}

th:first-child { border-left: 1px solid #edf2f6; border-radius: 9px 0 0 0; }
th:last-child { border-right: 1px solid #edf2f6; border-radius: 0 9px 0 0; }

td {
  padding: 12px;
  border-bottom: 1px solid #edf1f5;
  color: #314358;
  vertical-align: middle;
  background: #fff;
  transition: background .12s ease;
}

tbody tr:hover td { background: #fafdff; }
tbody tr:last-child td { border-bottom: 0; }

td b { color: #14283d; font-weight: 700; }

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

/* ===== Progress & badges ===== */
.progress {
  min-width: 115px;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eef5;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  box-shadow: 0 0 10px rgba(45,195,232,.22);
}

.minw { min-width: 180px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 9px;
  border: 1px solid #dfe6ee;
  border-radius: 999px;
  color: #5d6c7c;
  background: #f2f5f8;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .025em;
}

.badge.running {
  color: #176ba8;
  border-color: #c6e8f7;
  background: #eaf7fd;
}

.badge.running::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 4px rgba(45,195,232,.12);
}

.badge.completed,
.badge.matched {
  color: #16744f;
  border-color: #c9ecdc;
  background: var(--green-bg);
}

.badge.completed_errors,
.badge.warning,
.badge.paused {
  color: #9a5e0e;
  border-color: #f0ddba;
  background: var(--amber-bg);
}

.badge.error,
.badge.stopped {
  color: #9c3c43;
  border-color: #eed0d3;
  background: var(--red-bg);
}

.badge.draft {
  color: #637386;
  border-color: #dde4eb;
  background: #f3f6f9;
}

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.span2 { grid-column: span 2; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid2 .span2 { grid-column: span 2; }

label {
  display: block;
  margin-bottom: 14px;
  color: #45586d;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .015em;
}

input,
textarea,
select {
  width: 100%;
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid #d4dee8;
  border-radius: 9px;
  outline: none;
  color: #172a3e;
  background: #fff;
  box-shadow: inset 0 1px 2px rgba(10,41,70,.02);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input,
select { min-height: 42px; }

textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder { color: #9aa8b7; }

input:hover,
textarea:hover,
select:hover { border-color: #bdcbd8; }

input:focus,
textarea:focus,
select:focus {
  border-color: #49aee3;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(35,143,221,.11);
}

.hint {
  margin: -4px 0 13px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.58;
}

.muted { color: var(--muted); font-weight: 450; }

.file {
  display: block;
  padding: 12px;
  border: 1px dashed #bdcbd8;
  border-radius: 10px;
  color: #6e7e90;
  background: #fbfdff;
  transition: border-color .15s ease, background .15s ease;
}

.file:hover {
  border-color: #7cbfe3;
  background: #f5fbfe;
}

.file input {
  min-height: auto;
  margin-top: 5px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.file.big { padding: 19px; }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  font-weight: 600;
}

.check input {
  width: 17px;
  min-height: 17px;
  margin: 0;
  accent-color: var(--blue);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.calc-note,
.info-box,
.empty-box {
  padding: 14px 15px;
  border: 1px solid #dfe8ef;
  border-radius: 10px;
  color: #607287;
  background: #f7fafc;
  line-height: 1.58;
}

.info-box {
  border-left: 3px solid #69bfe8;
  background: #f4fbfe;
}

.alert {
  margin-bottom: 18px;
  padding: 12px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}

.alert.danger {
  color: #9e333b;
  border-color: #f0cdd0;
  background: #fff2f3;
}

.alert.success {
  color: #14704b;
  border-color: #c8eadb;
  background: #ecf9f2;
}

/* ===== Controls / utility ===== */
.controlbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.controlbar form,
.actions form { margin: 0; }

.actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.sections { align-items: start; }
.clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.wideclip { max-width: 360px; }
.text-danger { color: #b5343d !important; }

.danger-zone {
  display: flex;
  justify-content: flex-end;
  margin-top: 27px;
}

.filters,
.inline-form {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.filters { margin-bottom: 16px; }
.filters input,
.inline-form input { width: 180px; margin: 0; }
.filters label { margin: 0 6px 0 0; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  padding: 34px;
  color: #8795a4;
  text-align: center;
}

.linkbtn {
  padding: 0;
  border: 0;
  color: #1682c8;
  background: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.linkbtn:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ===== Login ===== */
.login-body {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
  padding: 40px clamp(40px, 12vw, 190px) 40px 40px;
  background: #eef4f9;
}

.login-body::before {
  content: "";
  position: absolute;
  inset: 0 42% 0 0;
  background:
    radial-gradient(circle at 30% 32%, rgba(42,190,232,.17), transparent 28%),
    linear-gradient(145deg, #0a2c4d 0%, #071c31 72%);
  clip-path: polygon(0 0, 100% 0, 72% 100%, 0 100%);
}

.login-body::after {
  content: "XMLRIVER";
  position: absolute;
  left: clamp(38px, 9vw, 150px);
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,.032);
  font-size: clamp(62px, 8vw, 150px);
  font-weight: 800;
  letter-spacing: -.06em;
  pointer-events: none;
}

.login-card {
  position: relative;
  z-index: 2;
  width: min(420px, calc(100vw - 42px));
  padding: 31px;
  border: 1px solid rgba(206,218,230,.85);
  border-radius: 18px;
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
}

.login-brand {
  padding: 0 0 23px;
  color: var(--text);
}

.login-brand .brand-mark {
  width: 46px;
  height: 46px;
  flex-basis: 46px;
  border-radius: 13px;
}

.login-brand b {
  color: #0b2945;
  font-size: 20px;
}

.login-brand small {
  color: #7690a8;
  font-size: 10px;
}

.login-card h2 {
  margin: 0 0 8px;
  color: #0b233b;
  font-size: 24px;
  font-weight: 760;
  letter-spacing: -.035em;
}

.login-note {
  margin: 0 0 21px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.login-card label {
  margin-bottom: 15px;
  color: #35495f;
  font-size: 11px;
}

.login-card input {
  height: 45px;
  border-radius: 10px;
  background: #fbfdff;
}

.login-card .btn.primary {
  height: 44px;
  margin-top: 4px;
  border-radius: 10px;
  font-size: 13px;
}

/* ===== Responsive ===== */
@media (max-width: 1120px) {
  .sidebar { width: 222px; }
  main { margin-left: 222px; padding: 26px 25px 55px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid,
  .grid2,
  .sections { grid-template-columns: 1fr; }
  .span2,
  .grid2 .span2 { grid-column: span 1; }
}

@media (max-width: 820px) {
  .sidebar { width: 78px; padding: 18px 10px; }
  .sidebar .brand div,
  .sidebar-user,
  .sidebar nav::before { display: none; }
  .brand { justify-content: center; padding: 2px 0 24px; }
  .brand-mark { width: 40px; height: 40px; flex-basis: 40px; }
  .sidebar nav a { justify-content: center; padding: 10px; font-size: 0; }
  .sidebar nav a::before { width: 7px; height: 7px; margin: 0; }
  .logout button { font-size: 0; }
  .logout button::after { content: "↪"; font-size: 17px; }
  main { margin-left: 78px; padding: 22px 18px 46px; }
  .login-body { justify-content: center; padding: 24px; }
  .login-body::before { inset: 0; clip-path: none; opacity: .11; }
  .login-body::after { display: none; }
}

@media (max-width: 620px) {
  .sidebar { display: none; }
  main { margin-left: 0; padding: 17px 13px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; margin-bottom: 18px; }
  .topbar h1 { font-size: 23px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { min-height: 92px; padding: 15px; }
  .stat b { font-size: 23px; }
  .card { padding: 15px; border-radius: 12px; }
  .filters input,
  .inline-form input { width: 100%; }
  .filters .btn,
  .inline-form .btn { flex: 1; }
  .form-actions { flex-wrap: wrap; }
  .login-card { padding: 24px 20px; }
}

