:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #eff4ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Экран входа ---------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; }

/* ---------- Форменные элементы ---------- */
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field { margin-bottom: 16px; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 10px 16px; border: 1px solid transparent; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: filter .15s;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: var(--panel); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.ok-msg { color: var(--ok); font-size: 13px; margin-top: 8px; }

/* ---------- Оболочка портала ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 16px; }
.brand .logo { font-size: 24px; }
.brand .name { font-weight: 800; font-size: 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.nav a .ic { font-size: 17px; width: 22px; text-align: center; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }

/* Группы меню и подвкладки */
.nav-group { margin: 2px 0; }
.nav-group-title {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
}
.nav-group-title .ic { font-size: 15px; width: 22px; text-align: center; }
.nav-group-items { display: flex; flex-direction: column; gap: 2px; }
.nav a.nav-sub { padding-left: 30px; }
.nav a.nav-sub .ic { font-size: 15px; }

.userbox { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.userbox .u-name { font-weight: 700; }
.userbox .u-role { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

.main { padding: 24px 28px; overflow: auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .sub { color: var(--muted); }

/* ---------- Карточки / таблицы ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 14px; font-size: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-off { background: #f1f5f9; color: #64748b; }
.badge-admin { background: #fef3c7; color: #b45309; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--brand-soft); color: var(--brand); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* Подвкладки */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.subtab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 16px; font-weight: 600; cursor: pointer;
}
.subtab:hover { color: var(--text); filter: none; }
.subtab.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }

/* Переключатель (тумблер) */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ''; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(18px); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Модальное окно ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.4); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--panel); border-radius: 16px; padding: 24px; width: 100%; max-width: 480px; box-shadow: 0 20px 40px rgba(0,0,0,.2); max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.rule-row { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--panel-2); }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  .nav { flex-direction: row; }
}
