:root {
  --bg: #0c0e14;
  --bg-elevated: #131722;
  --bg-hover: #1a2030;
  --bg-subtle: #0f131c;
  --border: #252d3d;
  --border-soft: rgba(255, 255, 255, 0.06);
  --text: #eef1f7;
  --text-muted: #8b95aa;
  --text-faint: #5c667a;
  --primary: #5b8def;
  --primary-hover: #7aa3f5;
  --primary-glow: rgba(91, 141, 239, 0.22);
  --accent: #6ee7c7;
  --warn: #f0b429;
  --danger: #f07178;
  --success: #4ade80;
  --radius: 10px;
  --radius-lg: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --sidebar-w: 252px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ─── Login ─────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 70% 55% at 15% 10%, rgba(91, 141, 239, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 45% at 85% 90%, rgba(110, 231, 199, 0.08), transparent 50%),
    linear-gradient(160deg, #0a0c12 0%, #0e121a 50%, #0c0e14 100%);
}

.login-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  opacity: 0.35;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 36px 32px;
  background: rgba(19, 23, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.login-brand h1 {
  margin: 14px 0 6px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.brand-mark {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 20px var(--primary-glow);
}

/* ─── Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  background: linear-gradient(180deg, #121722 0%, #0f131c 100%);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px 28px;
}

.sidebar-head strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-head small {
  color: var(--text-faint);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.72;
}

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

.nav-item:hover .nav-icon {
  opacity: 1;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(91, 141, 239, 0.18), rgba(91, 141, 239, 0.06));
  color: var(--primary-hover);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-item.active .nav-icon {
  opacity: 1;
  color: var(--primary);
}

.sidebar-logout {
  margin-top: auto;
}

.main {
  padding: 28px 32px 40px;
  overflow-x: auto;
  background:
    radial-gradient(ellipse 80% 40% at 100% 0%, rgba(91, 141, 239, 0.05), transparent),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  min-width: 0;
}

.btn-menu {
  display: none;
}

.sidebar-overlay {
  display: none;
}

/* ─── Stats ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  padding: 18px 18px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent, var(--border));
  opacity: 0.85;
}

.stat-card:hover {
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.stat-accent-blue { --stat-accent: var(--primary); }
.stat-accent-green { --stat-accent: var(--success); }
.stat-accent-red { --stat-accent: var(--danger); }
.stat-accent-amber { --stat-accent: var(--warn); }
.stat-accent-teal { --stat-accent: var(--accent); }

.stat-card .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.stat-card .value {
  font-size: 1.85rem;
  font-weight: 600;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-card .value-sm {
  font-size: 1.05rem;
  font-weight: 600;
}

/* ─── Panels ────────────────────────────────────────────────────────────── */
.panel {
  padding: 22px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
}

.panel h3 {
  margin: 0 0 8px;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.alert-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-list li {
  padding: 10px 14px;
  background: rgba(240, 180, 41, 0.08);
  border: 1px solid rgba(240, 180, 41, 0.22);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: #fcd34d;
}

.alert-ok {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--success);
  font-size: 0.9rem;
}

.alert-ok::before {
  content: "✓";
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.15);
  font-size: 0.75rem;
}

.provisioning-url {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.provisioning-url span {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.provisioning-url code {
  display: block;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.88rem;
  word-break: break-all;
  color: var(--accent);
}

.provisioning-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

.panel-desc-muted {
  margin-top: 0.85rem;
  margin-bottom: 0;
  font-size: 0.85rem;
}

.panel-desc {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 72ch;
}

.panel-danger {
  border-color: rgba(240, 113, 120, 0.28);
  background: linear-gradient(180deg, rgba(240, 113, 120, 0.04), var(--bg-elevated));
}

.panel-danger h3 {
  color: #fca5a5;
}

.code-block {
  margin: 0;
  padding: 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.78rem;
  overflow-x: auto;
  color: var(--text-muted);
  line-height: 1.6;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
}

th {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.15);
}

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

tbody tr {
  transition: background 0.12s;
}

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

.mac-cell {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
}

/* ─── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-active {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.badge-inactive {
  background: rgba(139, 149, 168, 0.12);
  color: var(--text-muted);
}

.badge-warn {
  background: rgba(240, 180, 41, 0.12);
  color: #fcd34d;
  border: 1px solid rgba(240, 180, 41, 0.28);
}

.badge-off {
  background: rgba(240, 113, 120, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(240, 113, 120, 0.25);
}

.badge-live {
  background: rgba(240, 113, 120, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(240, 113, 120, 0.35);
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.panel-head-row h3 {
  margin: 0;
}

.panel-meta {
  font-size: 0.78rem;
  color: var(--text-faint);
  font-family: var(--mono);
}

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.field input,
.field select,
.field textarea,
.input-search,
.select {
  width: 100%;
  padding: 10px 13px;
  font: inherit;
  color: var(--text);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.input-search:focus,
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.field textarea {
  min-height: 88px;
  font-family: var(--mono);
  font-size: 0.8rem;
  resize: vertical;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-check input {
  width: auto;
  accent-color: var(--primary);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary-hover), var(--primary));
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #222a3a;
  border-color: rgba(255, 255, 255, 0.12);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.btn-warn {
  background: rgba(240, 180, 41, 0.12);
  color: #fcd34d;
  border: 1px solid rgba(240, 180, 41, 0.35);
}

.btn-danger {
  background: rgba(240, 113, 120, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(240, 113, 120, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(240, 113, 120, 0.2);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.78rem;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-wrap .input-search {
  flex: 1;
  min-width: 200px;
}

.toolbar-wrap .select {
  width: auto;
  min-width: 160px;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

.pagination span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── Toast & Modal ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 380px;
  font-size: 0.9rem;
  animation: toast-in 0.25s ease;
}

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

.toast.success {
  border-color: rgba(74, 222, 128, 0.4);
}

.toast.error {
  border-color: rgba(240, 113, 120, 0.4);
}

.modal {
  padding: 0;
  border: none;
  background: transparent;
  max-width: 540px;
  width: calc(100% - 32px);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-inner {
  margin: 0;
  padding: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  box-shadow: var(--shadow);
}

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

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 22px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.modal-foot #modal-delete {
  margin-right: auto;
}

.modal-delete-zone {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.url-truncate {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  body.sidebar-locked {
    overflow: hidden;
  }

  .btn-menu {
    display: inline-flex;
    flex-shrink: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: min(288px, 88vw);
    height: 100vh;
    height: 100dvh;
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
  }

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

  .main {
    padding: 16px;
    min-width: 0;
  }

  .topbar h2 {
    font-size: 1.1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card .value {
    font-size: 1.4rem;
  }

  .panel {
    padding: 18px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-wrap .input-search,
  .toolbar-wrap .select,
  .toolbar .btn {
    width: 100%;
    min-width: 0;
  }

  .provisioning-actions .btn {
    flex: 1 1 100%;
  }

  .switch-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 640px;
  }

  th, td {
    padding: 10px 12px;
  }

  .modal {
    width: calc(100% - 16px);
    max-width: none;
    margin: auto 8px;
  }

  .modal-foot {
    flex-wrap: wrap;
  }

  .modal-foot #modal-delete {
    margin-right: 0;
    width: 100%;
  }

  .modal-foot .btn-ghost,
  .modal-foot .btn-primary {
    flex: 1;
    min-width: 0;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
  }

  .btn, .nav-item {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 36px;
  }
}

@media (max-width: 480px) {
  .login-card {
    padding: 28px 22px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}
