:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #4f7cff;
  --primary-d: #3a63d8;
  --danger: #e5484d;
  --ok: #2e9e5b;
  --warn: #d9822b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

#app { display: flex; min-height: 100vh; }

/* ---------- Сайдбар ---------- */
#sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #141a24;
  color: #c9d1dc;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font-size: 20px;
  font-weight: 700;
  padding: 20px 20px 16px;
  color: #fff;
}
.brand span { color: var(--primary); font-weight: 500; }
#nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #c9d1dc;
  text-decoration: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-foot { padding: 12px 20px; font-size: 12px; color: #6b7684; border-top: 1px solid #232b38; }

/* ---------- Контент ---------- */
#main { flex: 1; min-width: 0; }
#content { padding: 24px 28px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-actions { display: flex; gap: 8px; }
.loading, .empty { color: var(--muted); padding: 24px 0; text-align: center; }
.empty { padding: 16px; }

/* ---------- Панели / карточки ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 14px; font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { color: var(--muted); margin-top: 4px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 24px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.kv-key { color: var(--muted); }
.kv-val { text-align: right; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover { background: #f5f8ff; }
td.empty { text-align: center; color: var(--muted); }
.row-actions { display: flex; gap: 4px; }

code { background: #eef1f5; padding: 1px 6px; border-radius: 5px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Бейджи ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: #eef1f5; color: var(--text); }
.badge.ok { background: #e5f5ec; color: var(--ok); }
.badge.muted { background: #eef1f5; color: var(--muted); }
.badge.warn { background: #fbeede; color: var(--warn); }

/* ---------- Кнопки ---------- */
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn:hover { background: #f5f6f8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdecec; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f5; }
.btn.disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Тулбар / фильтры ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.input { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13px; background: #fff; min-width: 180px; }
.input:focus { outline: none; border-color: var(--primary); }

/* ---------- Пагинация ---------- */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; justify-content: flex-end; }
.pager-info { color: var(--muted); font-size: 13px; }

/* ---------- Модалка ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-card { background: #fff; border-radius: 12px; padding: 22px 24px; width: 460px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.modal-card h3 { margin: 0 0 16px; }
.modal-form .field { margin-bottom: 14px; }
.modal-form label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 13px; }
.modal-form input, .modal-form select, .modal-form textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; font-family: inherit; }
.modal-form input[type="checkbox"] { width: auto; }
.modal-form textarea { font-family: ui-monospace, Menlo, monospace; resize: vertical; }
.field-help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- Тосты ---------- */
#toast-root { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #141a24; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transform: translateY(-8px); transition: all 0.25s; max-width: 340px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Адаптив ---------- */
@media (max-width: 720px) {
  #sidebar { width: 64px; flex-basis: 64px; }
  .brand { font-size: 0; padding: 16px 0; text-align: center; }
  .brand span { display: none; }
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; }
  .sidebar-foot { display: none; }
  #content { padding: 16px; }
}
