:root {
  --bg: #181A20;
  --sidebar: #20232B;
  --card: #262B35;
  --hover: #303745;
  --border: #323847;
  --accent: #3B82F6;
  --accent-hover: #5B93F7;
  --success: #22C55E;
  --error: #EF4444;
  --warning: #F59E0B;
  --text: #F5F5F5;
  --text2: #B7BCC7;
  --muted: #7C8394;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- утилиты ---------- */
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
.secondary { color: var(--text2); font-size: 13px; }
.err { color: var(--error); }
.ok { color: var(--success); }
.warn { color: var(--warning); }

/* ---------- кнопки ---------- */
.btn {
  background: var(--hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { color: var(--muted); cursor: default; background: var(--card); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.success { background: var(--success); border-color: transparent; color: #fff; font-weight: 600; }
.btn.success:hover { background: #34D874; }
.btn.danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn.danger:hover { background: var(--error); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.flat { background: transparent; border-color: transparent; color: var(--text2); }
.btn.flat:hover { background: var(--hover); color: var(--text); }

/* ---------- поля ---------- */
input, textarea, select {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label.field { display: block; margin-bottom: 5px; color: var(--text2); font-size: 12px; }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

/* ---------- вход ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 34px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--text2); font-size: 13px; margin-bottom: 22px; }
.auth-card .field-group { margin-bottom: 14px; }
.auth-card .btn { width: 100%; }
.auth-msg { margin-top: 14px; font-size: 13px; min-height: 18px; }

/* ---------- каркас приложения ---------- */
#app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 22px 14px; display: flex; flex-direction: column; flex-shrink: 0;
}
.brand { font-size: 16px; font-weight: 700; line-height: 1.3; margin-bottom: 26px; padding: 0 6px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px 14px; border-radius: var(--radius-sm); border: none; background: transparent;
  color: var(--text2); font-size: 14px; margin-bottom: 3px; transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--hover); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-btn .ic { width: 18px; text-align: center; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 62px; background: var(--sidebar); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 22px; flex-shrink: 0;
}
.topbar .title { font-size: 15px; font-weight: 700; }
.topbar select { width: auto; min-width: 200px; }
.status-dot { font-weight: 600; font-size: 13px; }

.content { flex: 1; overflow-y: auto; padding: 24px 28px; }
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 18px; }

.statusbar {
  height: 30px; background: var(--sidebar); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 26px; padding: 0 22px; font-size: 12px; color: var(--text2);
  flex-shrink: 0;
}

/* ---------- карточки ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 18px; }
.cards-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.stat-card { display: flex; align-items: center; justify-content: space-between; }
.stat-card .label { color: var(--text2); font-size: 13px; margin-bottom: 4px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .ic { font-size: 30px; opacity: .9; }

.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.card .id { color: var(--text2); font-size: 12px; word-break: break-all; }
.badge { font-size: 12px; font-weight: 600; }
.card-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- дашборд ---------- */
.dash-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) { .dash-cols { grid-template-columns: 1fr; } }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 200px; padding-top: 10px; }
.chart .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.chart .bar:hover { opacity: 1; }
.events { display: flex; flex-direction: column; gap: 10px; max-height: 340px; overflow-y: auto; }
.event { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.event .t { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }

/* ---------- таблица ---------- */
table { width: 100%; border-collapse: collapse; }
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th { background: var(--sidebar); color: var(--text2); text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--sidebar); }

/* ---------- модальные окна ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  padding: 26px; width: 100%; max-width: 460px; box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal .field-group { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-msg { margin-top: 10px; font-size: 13px; min-height: 18px; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.toolbar .search { min-width: 220px; }

/* progress */
.progress { height: 6px; background: var(--sidebar); border-radius: 4px; overflow: hidden; margin: 10px 0; }
.progress .bar { height: 100%; width: 40%; background: var(--accent); border-radius: 4px; animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* toast */
#toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 100; max-width: 360px;
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.err { border-left-color: var(--error); }
#toast.ok { border-left-color: var(--success); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--hover); }
::-webkit-scrollbar-track { background: transparent; }
