:root {
  --bg: #0b1220;
  --bg-soft: #0e1728;
  --card: #121d31;
  --card-hover: #17253c;
  --border: #21304c;
  --border-strong: #2c3e5c;
  --text: #e2e8f0;
  --muted: #8fa3bd;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 236px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -8%, #132240 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #151a32 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0d1626 0%, #0a111e 100%);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand .logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent);
  font-weight: 800;
  box-shadow: 0 0 22px -6px var(--accent);
}
.brand .t1 { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand .t2 { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover {
  background: var(--card);
  color: var(--text);
  transform: translateX(3px);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  transition: all 0.18s var(--ease);
}
.nav-item.active .nav-badge {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 8px 0;
  border-top: 1px solid var(--border);
}
.user-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-chip .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.user-chip .uinfo { min-width: 0; }
.user-chip .uname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
  transition: all 0.18s var(--ease);
  flex-shrink: 0;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); transform: translateY(-1px); }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: rgba(11, 18, 32, 0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 26px 28px 60px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- Views ---------- */
.view { display: none; }
.view.active { display: block; animation: fadeUp 0.32s var(--ease); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.stat-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: 0 12px 28px -12px rgba(0, 0, 0, 0.6);
}
.stat-card .bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}
.stat-card .num { font-size: 32px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-top: 7px; }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.18s var(--ease);
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; transition: transform 0.18s var(--ease); }
.chip:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); }
.chip:hover .dot { transform: scale(1.25); }
.chip.active { background: var(--card-hover); color: var(--text); border-color: var(--border-strong); box-shadow: 0 4px 14px -6px rgba(0,0,0,0.5); }

/* ---------- Search ---------- */
.search {
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  width: 240px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), width 0.25s var(--ease);
}
.search::placeholder { color: var(--muted); }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); width: 280px; }

/* ---------- Printer grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 15px;
}
.printer {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.25s var(--ease), background 0.2s var(--ease);
}
.printer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(400px 120px at 50% -20%, color-mix(in srgb, var(--sc) 14%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  pointer-events: none;
}
.printer:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--sc) 55%, var(--border));
  background: var(--card-hover);
  box-shadow: 0 14px 30px -10px var(--sc);
}
.printer:hover::after { opacity: 1; }
.printer .stripe {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--sc);
  transition: height 0.2s var(--ease);
}
.printer:hover .stripe { height: 6px; }
.printer .pname {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  word-break: break-word;
  position: relative;
  z-index: 1;
}
.printer .psub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}
.printer .pstatus {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.printer .pstatus .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--sc);
  box-shadow: 0 0 8px var(--sc);
}
.printer .pstatus .dot.pulse { animation: pulse 1.8s infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sc) 55%, transparent); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 64px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Panels (users/settings) ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  max-width: 640px;
}
.panel h2 { font-size: 16px; margin-bottom: 16px; }
.panel .field, .panel .inline-form { margin-bottom: 14px; }

.inline-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.inline-form .field { flex: 1 1 150px; margin-bottom: 0; }

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.user-row:hover { border-color: var(--border-strong); transform: translateX(3px); }
.user-row .uinfo { flex: 1; }
.user-row .uinfo .uname { font-weight: 600; font-size: 14px; }
.user-row .uinfo .urole { font-size: 12px; color: var(--muted); }

.legend { display: flex; flex-direction: column; gap: 10px; }
.legend-item { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.legend-item .swatch {
  width: 14px; height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 10px -2px currentColor;
}

/* ---------- Forms ---------- */
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.18s var(--ease), box-shadow 0.18s var(--ease), opacity 0.15s;
  color: var(--text);
  background: var(--card);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #06121f; box-shadow: 0 6px 18px -8px var(--accent); }
.btn-primary:hover { background: #5cc7f8; transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--card-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--danger-soft); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.22); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 16, 0.6);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.overlay.open { display: flex; }
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
  animation: scaleIn 0.22s var(--ease);
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h2 { font-size: 19px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-actions .spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }

/* ---------- Auth (login) ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  animation: scaleIn 0.25s var(--ease);
}
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.auth-card .field { margin-bottom: 16px; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0; top: auto;
    width: 100%; height: auto;
    flex-direction: row;
    align-items: center;
    padding: 8px 10px;
    z-index: 40;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .brand, .sidebar-footer .user-chip { display: none; }
  .sidebar-footer { margin: 0; padding: 0; border: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav-item { flex-direction: column; gap: 4px; font-size: 11px; padding: 6px 10px; }
  .nav-item.active::before { display: none; }
  .nav-item:hover { transform: none; }
  .nav-badge { position: absolute; top: 2px; right: 6px; }
  .main { padding-bottom: 74px; }
  .topbar { flex-wrap: wrap; padding: 14px 16px; }
  .search, .search:focus { width: 100%; }
  .topbar-actions { width: 100%; }
  .content { padding: 18px 16px 40px; }
}

/* ====== Светлая тема ====== */
[data-theme="light"] {
  --bg: #eef2f8;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-hover: #f2f6fb;
  --border: #e2e8f0;
  --border-strong: #c6d2e1;
  --text: #0f172a;
  --muted: #5b6b83;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}
[data-theme="light"] body {
  background:
    radial-gradient(1100px 520px at 12% -8%, #dbe7f7 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #e6ecf6 0%, transparent 50%),
    var(--bg);
}
[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, #ffffff 0%, #f4f7fc 100%);
}
[data-theme="light"] .topbar {
  background: rgba(238, 242, 248, 0.8);
}

/* ====== Переключатель темы ====== */
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ====== Форма принтера (сетка) ====== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 14px;
}
.form-grid .field.full { grid-column: 1 / -1; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }

textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 72px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ====== Журнал ====== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 860px;
}
.history-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.history-item:hover { border-color: var(--border-strong); transform: translateX(3px); }
.hist-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 2px;
  min-width: 118px;
}
.hist-badge {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.hist-badge.create { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.hist-badge.update { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.hist-badge.delete { background: rgba(239, 68, 68, 0.15); color: #f87171; }
[data-theme="light"] .hist-badge.create { background: rgba(34, 197, 94, 0.15); color: #16a34a; }
[data-theme="light"] .hist-badge.update { background: rgba(2, 132, 199, 0.14); color: #0284c7; }
[data-theme="light"] .hist-badge.delete { background: rgba(220, 38, 38, 0.12); color: #dc2626; }
.hist-body { flex: 1; min-width: 0; }
.hist-printer { font-weight: 600; font-size: 14px; }
.hist-user { color: var(--muted); font-size: 12px; margin-top: 2px; }
.hist-change { font-size: 13px; margin-top: 4px; }
.hist-change .fld { color: var(--muted); }
.hist-change .old { color: var(--muted); text-decoration: line-through; }
.hist-change .new { color: var(--accent); font-weight: 600; }
.hist-empty { color: var(--muted); text-align: center; padding: 40px; }

/* ====== Поля дат ====== */
input[type="date"] {
  color-scheme: dark;
}
[data-theme="light"] input[type="date"] { color-scheme: light; }
