:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --ink: #1F2A37;
  --ink-soft: #374151;
  --muted: #667085;
  --faint: #98A2B3;
  --accent: #2F6FED;
  --accent-hover: #2859C6;
  --accent-soft: #EBF1FE;
  --ok: #12B76A;
  --ok-soft: #E9F9F1;
  --warn: #F79009;
  --warn-soft: #FEF4E6;
  --err: #D92D20;
  --err-soft: #FDEBEA;
  --border: #E4E7EC;
  --border-strong: #CBD2DC;
  --sidebar-bg: #FFFFFF;
  --shadow: 0 1px 2px rgba(31, 42, 55, 0.06), 0 1px 3px rgba(31, 42, 55, 0.1);
  --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: var(--font); }

/* ===== Топбар ===== */
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 24px; height: 24px;
  border-radius: 5px;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}

.topbar-spacer { flex: 1; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}

.user-meta { line-height: 1.2; }
.user-meta .name { font-weight: 500; font-size: 13px; }

/* ===== Лейаут ===== */
.layout { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  padding: 8px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 13.5px;
  margin-bottom: 2px;
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-item:hover { background: var(--bg); text-decoration: none; color: var(--ink); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.content {
  flex: 1;
  padding: 24px 32px 48px;
  min-width: 0;
}

/* ===== Хлебные крошки ===== */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent); text-decoration: none; }
.breadcrumbs .sep { color: var(--faint); }
.breadcrumbs .current { color: var(--ink); font-weight: 500; }

/* ===== Заголовки страниц ===== */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.page-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ===== Кнопки ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: var(--muted); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  color: var(--err);
  border-color: #F2B8B5;
}
.btn-danger:hover { background: var(--err-soft); border-color: var(--err); }

.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Иконки — inline SVG без размеров: без явных width/height растягиваются на весь контейнер. */
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-icon { padding: 6px; }

/* ===== Карточки ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 24px; }

.card-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12.5px; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }

/* ===== Стат-карточки ===== */
.stat-card { padding: 20px 24px; }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.stat-value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ===== Таблицы ===== */
.table-wrap { overflow-x: auto; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #FAFBFC;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.table th:hover { color: var(--ink); }

.table th .sort-arrow { color: var(--accent); font-size: 10px; margin-left: 4px; }

.table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover { background: #FAFBFC; }
.table tbody tr:last-child td { border-bottom: none; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

.row-link { color: var(--accent); font-weight: 500; cursor: pointer; }
.row-link:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.word-break { word-break: break-all; }

/* ===== Бейджи статусов ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-ok { background: var(--ok-soft); color: #0E9B5D; }
.badge-warn { background: var(--warn-soft); color: #B85708; }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-neutral { background: #F0F2F5; color: var(--muted); }

/* ===== Формы ===== */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--ink-soft);
}

.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

textarea.code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  min-height: 200px;
  resize: vertical;
}

.form-row { display: flex; gap: 16px; }
.form-row .field { flex: 1; }

/* ===== Прогресс-бар ===== */
.progress {
  height: 6px;
  border-radius: 999px;
  background: #EDF0F4;
  overflow: hidden;
  min-width: 100px;
}

.progress-bar { height: 100%; background: var(--ok); border-radius: 999px; transition: width 0.3s ease; }
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--err); }

.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; gap: 8px; }

/* ===== Код-блок ===== */
.code-block {
  background: #F8F9FB;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  padding: 16px;
  overflow-x: auto;
  white-space: pre;
  max-height: 420px;
  overflow-y: auto;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #F1F3F6;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.code-block.attached { border-top: none; border-radius: 0 0 var(--radius) var(--radius); }

/* ===== Модалки ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 42, 55, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 16px;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(31, 42, 55, 0.2);
  width: 100%;
  max-width: 440px;
  animation: slideUp 0.18s ease;
}

.modal-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 15px; font-weight: 600; }

.modal-close {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }

.modal-body { padding: 24px; }

.modal-foot {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Тосты ===== */
#toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: 0 4px 16px rgba(31, 42, 55, 0.25);
  animation: slideIn 0.2s ease;
  max-width: 360px;
}

.toast.ok { background: #0E9B5D; }
.toast.err { background: var(--err); }
.toast.warn { background: #B85708; }

@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Тумблер ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(31, 42, 55, 0.2);
}

.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ===== Логин ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(1200px 400px at 50% -100px, #E8EFFD 0%, transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 40px 32px 32px;
}

.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.auth-brand .brand-mark { width: 32px; height: 32px; font-size: 16px; border-radius: 7px; }
.auth-brand span { font-size: 20px; font-weight: 600; }

.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }

/* ===== Утилиты ===== */
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

.empty-state .big { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }

/* ===== Файлы ===== */
.file-list { list-style: none; font-size: 13px; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 4px;
}
.file-list li:hover { background: var(--bg); }
.file-list .f-path { font-family: var(--mono); font-size: 12.5px; flex: 1; word-break: break-all; }
.file-list .f-size { color: var(--muted); font-variant-numeric: tabular-nums; }
.file-icon { width: 16px; height: 16px; color: var(--faint); flex-shrink: 0; }
.file-list li > span:first-child { display: inline-flex; }

/* ===== Инфо-лист ===== */
.info-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.info-item { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.info-item:nth-last-child(-n+2) { border-bottom: none; }
.info-label { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.info-value { font-size: 13.5px; font-weight: 500; word-break: break-all; }

/* ===== Канавас-чарты ===== */
.chart-box { position: relative; }
.chart-box canvas { width: 100%; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 8px; flex-wrap: wrap; }
.chart-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ===== Скелетон ===== */
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 32px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Фильтр-бар ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.filter-bar .input { width: 240px; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .info-list, .grid-2 { grid-template-columns: 1fr; }
  .info-item:nth-last-child(-n+2) { border-bottom: 1px solid var(--border); }
  .info-item:last-child { border-bottom: none; }
}

/* ===== Тёмная тема ===== */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1420;
  --surface: #1A2231;
  --ink: #E6EAF2;
  --ink-soft: #C3CBD8;
  --muted: #8A94A6;
  --faint: #5C6676;
  --accent: #6B9BFF;
  --accent-hover: #82AFFF;
  --accent-soft: #233452;
  --ok: #35D07F;
  --ok-soft: #123324;
  --warn: #F5A852;
  --warn-soft: #36260F;
  --err: #F26D63;
  --err-soft: #3C1E1D;
  --border: #293244;
  --border-strong: #3A465C;
  --sidebar-bg: #1A2231;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .table th { background: #141B29; }
[data-theme="dark"] .table tbody tr:hover { background: #141B29; }
[data-theme="dark"] .progress { background: #293244; }
[data-theme="dark"] .code-block { background: #10161F; }
[data-theme="dark"] .code-head { background: #1B2434; }
[data-theme="dark"] .badge-neutral { background: #293244; }
[data-theme="dark"] .toast { background: #232E42; }
[data-theme="dark"] .spinner { border-color: #3A465C; border-top-color: var(--accent); }
[data-theme="dark"] .modal { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
[data-theme="dark"] .modal-overlay { background: rgba(4, 8, 15, 0.55); }
[data-theme="dark"] .auth-wrap { background: radial-gradient(1200px 400px at 50% -100px, #182742 0%, transparent 60%), var(--bg); }
[data-theme="dark"] .file-list li:hover { background: #141B29; }
[data-theme="dark"] .slider::before { background: #E6EAF2; }