:root {
  --bg: #04050a;
  --bg-elevated: #0a0c14;
  --sidebar: rgba(10, 12, 20, 0.72);
  --surface: rgba(18, 22, 34, 0.78);
  --surface-hover: rgba(26, 31, 48, 0.9);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f4f6fc;
  --muted: #8b93a8;
  --accent: #7c6cff;
  --accent-2: #5eead4;
  --accent-glow: rgba(124, 108, 255, 0.35);
  --green: #34d399;
  --red: #fb7185;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 0.42s;
  --sidebar-w: 260px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

html { scroll-behavior: smooth; }

body {
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
a { color: #a5b4ff; text-decoration: none; }
.hidden { display: none !important; }

/* Ambient background */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.ambient::before,
.ambient::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: floatOrb 18s var(--ease) infinite alternate;
}

.ambient::before {
  width: 520px;
  height: 520px;
  left: -120px;
  top: -160px;
  background: radial-gradient(circle, rgba(124, 108, 255, 0.35), transparent 70%);
}

.ambient::after {
  width: 420px;
  height: 420px;
  right: -80px;
  bottom: -120px;
  background: radial-gradient(circle, rgba(94, 234, 212, 0.18), transparent 70%);
  animation-delay: -6s;
}

@keyframes floatOrb {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(30px, 20px) scale(1.08); }
}

/* Login */
.login-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(440px, 100%);
  padding: 40px 36px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(22, 27, 42, 0.92), rgba(14, 17, 28, 0.88));
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  animation: loginIn 0.7s var(--ease) both;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(124, 108, 255, 0.5), transparent 40%, rgba(94, 234, 212, 0.25));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

@keyframes loginIn {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #7c6cff, #5eead4);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 12px 32px var(--accent-glow);
}

.login-brand h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-brand p { font-size: 13px; color: var(--muted); margin-top: 4px; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.field input {
  width: 100%;
  padding: 13px 15px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(6, 8, 14, 0.65);
  color: var(--text);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), transform 0.2s var(--ease);
}

.field input:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(124, 108, 255, 0.12);
}

.pw-wrap { position: relative; }
.pw-wrap button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}

.pw-wrap button:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #7c6cff, #6d5ef8);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.25s var(--ease), filter 0.2s;
  box-shadow: 0 10px 28px rgba(124, 108, 255, 0.25);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 36px rgba(124, 108, 255, 0.32);
  filter: brightness(1.05);
}

.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.block { width: 100%; }
.btn.ghost {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}
.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
  box-shadow: none;
}
.btn.danger { background: linear-gradient(135deg, #fb7185, #f43f5e); box-shadow: 0 10px 28px rgba(251, 113, 133, 0.22); }
.btn.sm { padding: 7px 12px; font-size: 12px; border-radius: 9px; }
.btn .ico { width: 16px; height: 16px; opacity: 0.9; }

.err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }
.ok { color: var(--green); font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; }

/* App shell */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
  animation: appIn 0.55s var(--ease) both;
}

@keyframes appIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff, #c4b5fd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-brand .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.nav {
  padding: 14px 12px;
  flex: 1;
  overflow: auto;
  position: relative;
}

.nav-group { margin-bottom: 20px; }

.nav-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 14px 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.25s var(--ease), background 0.25s var(--ease), transform 0.2s var(--ease);
  margin-bottom: 4px;
  position: relative;
  user-select: none;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  transform: translateX(2px);
}

.nav-item.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(124, 108, 255, 0.2), rgba(124, 108, 255, 0.04));
  border: 1px solid rgba(124, 108, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.nav-item .icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  font-size: 13px;
  transition: transform 0.3s var(--ease-spring);
}

.nav-item.active .icon {
  background: rgba(124, 108, 255, 0.22);
  transform: scale(1.05);
}

.sidebar-foot {
  padding: 16px 12px 18px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c6cff, #5eead4);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
}

.user-chip .name { font-size: 13px; font-weight: 700; }
.user-chip .role { font-size: 11px; color: var(--muted); margin-top: 2px; }
.logout { margin-top: 10px; width: 100%; }

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

.topbar {
  height: 72px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(4, 5, 10, 0.55);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}

.topbar .desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
  transition: opacity 0.3s var(--ease);
}

.content {
  padding: 28px 32px 48px;
  overflow: auto;
}

.page-stage {
  animation: pageIn var(--dur) var(--ease) both;
}

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

.page-stage.leaving {
  animation: pageOut 0.22s var(--ease) forwards;
}

@keyframes pageOut {
  to { opacity: 0; transform: translateY(-8px); }
}

/* Cards & stats */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
  backdrop-filter: blur(12px);
  transition: border-color 0.25s var(--ease), transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.card-head h3 { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  animation: statIn 0.55s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 0.07s);
}

.stat::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0.7;
}

@keyframes statIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.stat .val {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 8px; font-weight: 500; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Skeleton */
.skeleton-wrap { display: grid; gap: 14px; }
.skeleton {
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.09) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton.stats-row { height: 96px; }
.skeleton.card-block { height: 280px; }

/* Tables */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar input,
.toolbar select,
.form-grid input,
.form-grid select,
.form-grid textarea,
.field input {
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.toolbar input,
.toolbar select {
  max-width: 280px;
  padding: 10px 13px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(6, 8, 14, 0.55);
  color: var(--text);
}

.toolbar input:focus,
.toolbar select:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(124, 108, 255, 0.1);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(4, 6, 12, 0.35);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.02);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}

tbody tr:hover td {
  background: rgba(124, 108, 255, 0.06);
}

tbody tr:last-child td { border-bottom: none; }

.mono {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(124, 108, 255, 0.14);
  color: #c4b5fd;
  border: 1px solid rgba(124, 108, 255, 0.22);
}

.badge.green { background: rgba(52, 211, 153, 0.12); color: var(--green); border-color: rgba(52, 211, 153, 0.25); }
.badge.red { background: rgba(251, 113, 133, 0.12); color: var(--red); border-color: rgba(251, 113, 133, 0.25); }
.badge.warn { background: rgba(251, 191, 36, 0.12); color: var(--warn); border-color: rgba(251, 191, 36, 0.25); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Drawer */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(2, 3, 8, 0.55);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  animation: maskIn 0.32s var(--ease) both;
}

.drawer-mask.closing { animation: maskOut 0.28s var(--ease) forwards; }

@keyframes maskIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes maskOut { to { opacity: 0; } }

.drawer {
  width: min(540px, 100vw);
  height: 100%;
  background: linear-gradient(180deg, rgba(20, 24, 38, 0.98), rgba(12, 15, 24, 0.98));
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  animation: drawerIn 0.42s var(--ease-spring) both;
}

.drawer-mask.closing .drawer { animation: drawerOut 0.3s var(--ease) forwards; }

@keyframes drawerIn {
  from { transform: translateX(100%); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes drawerOut {
  to { transform: translateX(100%); opacity: 0.5; }
}

.drawer-head {
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.drawer-body { padding: 22px 24px; overflow: auto; flex: 1; }
.drawer-foot {
  padding: 18px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: rgba(0,0,0,0.12);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(6, 8, 14, 0.55);
  color: var(--text);
}
.form-grid textarea { min-height: 80px; resize: vertical; }

.chk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.chk-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}

.chk-grid label:hover { background: rgba(255,255,255,0.03); border-color: var(--border); }

.code-box {
  padding: 14px;
  background: rgba(6, 8, 14, 0.65);
  border-radius: 12px;
  border: 1px solid var(--border);
  word-break: break-all;
  line-height: 1.7;
}

/* Toast */
.toast-wrap {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 13px 16px;
  border-radius: 12px;
  background: rgba(18, 22, 34, 0.95);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(12px);
  animation: toastIn 0.38s var(--ease-spring) both;
  max-width: 380px;
}

.toast.leaving { animation: toastOut 0.28s var(--ease) forwards; }
.toast.ok { border-color: rgba(52, 211, 153, 0.35); }
.toast.err { border-color: rgba(251, 113, 133, 0.35); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px) scale(0.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(16px) scale(0.96); }
}

.loading {
  padding: 48px;
  text-align: center;
  color: var(--muted);
}

.chart-box {
  position: relative;
  height: 320px;
  margin-top: 10px;
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.mobile-menu {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 3, 8, 0.5);
  backdrop-filter: blur(4px);
  z-index: 35;
  animation: maskIn 0.32s var(--ease) both;
}

.sidebar-backdrop.show { display: block; }

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.38s var(--ease);
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .mobile-menu {
    display: inline-flex;
    margin-right: 10px;
  }

  .grid2 { grid-template-columns: 1fr; }
  .content { padding: 20px 18px 36px; }
  .topbar { padding: 0 18px; }
}
