/* ===== Design tokens ===== */
:root {
  --bg-deep: #0a0d1a;
  --bg-panel: #12172b;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.05);

  --violet: #8b5cf6;
  --pink: #ec4899;
  --cyan: #22d3ee;
  --gold: #d4af37;

  --aurora: linear-gradient(120deg, var(--violet), var(--pink) 50%, var(--cyan));

  --text-hi: #f3f2fb;
  --text-mid: #a8a9c4;
  --text-low: #6c6d8a;

  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --font-ui: 'Vazirmatn', sans-serif;
  --font-data: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-deep);
  color: var(--text-hi);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* محیط پس‌زمینه با هاله‌های نور اورورا */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(600px circle at 85% -5%, rgba(139, 92, 246, 0.16), transparent 60%),
    radial-gradient(500px circle at 5% 15%, rgba(236, 72, 153, 0.12), transparent 60%),
    radial-gradient(700px circle at 50% 110%, rgba(34, 211, 238, 0.08), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

::selection {
  background: rgba(139, 92, 246, 0.35);
}

/* ===== Glass primitives ===== */
.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.data {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
}

/* ===== Login page ===== */
.login-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  text-align: center;
}

.orb {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--aurora);
  background-size: 200% 200%;
  animation: aurora-shift 6s ease infinite, pulse-ring 2.4s ease-in-out infinite;
  box-shadow: 0 0 40px rgba(139, 92, 246, 0.5);
}

@keyframes aurora-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 30px rgba(139, 92, 246, 0.4); }
  50% { box-shadow: 0 0 50px rgba(236, 72, 153, 0.55); }
}

.login-card h1 {
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 6px;
}

.login-card p.sub {
  color: var(--text-mid);
  font-size: 13.5px;
  margin: 0 0 28px;
}

.field {
  text-align: right;
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-mid);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-hi);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s, opacity 0.12s, box-shadow 0.12s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  width: 100%;
  color: #fff;
  background: var(--aurora);
  background-size: 200% 200%;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.28);
}

.btn-primary:hover {
  background-position: 100% 50%;
}

.btn-ghost {
  background: var(--glass-strong);
  color: var(--text-hi);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  border-color: var(--violet);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.2);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: 8px;
}

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

/* ===== App shell ===== */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-left: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.brand .orb {
  width: 34px;
  height: 34px;
  margin: 0;
  animation: aurora-shift 6s ease infinite, pulse-ring 2.4s ease-in-out infinite;
}

.brand-name {
  font-weight: 800;
  font-size: 15px;
  line-height: 1.3;
}

.brand-name span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-low);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-mid);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--glass);
  color: var(--text-hi);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.18), rgba(236, 72, 153, 0.08));
  border-color: rgba(139, 92, 246, 0.3);
  color: var(--text-hi);
}

.nav-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-low);
}

.nav-item.active .dot {
  background: var(--pink);
  box-shadow: 0 0 8px var(--pink);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius-md);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-mid);
}

.status-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-low);
  flex-shrink: 0;
}

.status-led.online {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
  animation: led-pulse 2s ease-in-out infinite;
}

.status-led.offline {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
}

@keyframes led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Main content ===== */
.main {
  flex: 1;
  padding: 28px 36px 60px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}

.topbar h2 {
  font-size: 20px;
  font-weight: 800;
  margin: 0;
}

.topbar .breadcrumb {
  font-size: 12.5px;
  color: var(--text-low);
  margin-top: 4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-mid);
}

.section {
  display: none;
  animation: fade-in 0.25s ease;
}

.section.active {
  display: block;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Stat cards ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card .label {
  font-size: 12.5px;
  color: var(--text-mid);
  margin-bottom: 10px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
}

.stat-card .accent-bar {
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--aurora);
}

.card {
  padding: 22px;
  margin-bottom: 18px;
}

.card-title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-wrap {
  height: 260px;
}

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
}

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

th, td {
  text-align: right;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

th {
  color: var(--text-mid);
  font-weight: 600;
  font-size: 12.5px;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge.ok { background: rgba(52, 211, 153, 0.14); color: var(--success); }
.badge.bad { background: rgba(248, 113, 113, 0.14); color: var(--danger); }

/* ===== Forms ===== */
.form-row {
  margin-bottom: 16px;
}

.form-row label {
  display: block;
  font-size: 13px;
  color: var(--text-mid);
  margin-bottom: 7px;
}

.form-row input[type="text"],
.form-row textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-hi);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  resize: vertical;
}

.form-row input:focus,
.form-row textarea:focus {
  border-color: var(--violet);
}

.hint {
  font-size: 11.5px;
  color: var(--text-low);
  margin-top: 6px;
}

/* toggle switch */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}

.switch-row:last-child { border-bottom: none; }

.switch-label .t { font-size: 13.5px; font-weight: 600; }
.switch-label .d { font-size: 12px; color: var(--text-low); margin-top: 2px; }

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  transition: 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  right: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

input:checked + .slider {
  background: var(--aurora);
}

input:checked + .slider::before {
  transform: translateX(-20px);
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-hi);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease;
}

.toast-item.ok { border-color: rgba(52, 211, 153, 0.4); }
.toast-item.err { border-color: rgba(248, 113, 113, 0.4); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* pagination */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-mid);
}

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.search-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-hi);
  font-family: inherit;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-low);
  font-size: 13.5px;
}

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; border-left: none; border-bottom: 1px solid var(--border-soft); }
  .main { padding: 20px; }
}
