/* Modern Glassmorphic Design System */
:root {
  --bg: #090d16;
  --bg-gradient: radial-gradient(circle at 50% 0%, rgba(30, 58, 138, 0.4), transparent 45%),
                 radial-gradient(circle at 0% 100%, rgba(15, 23, 42, 0.8), transparent 50%),
                 linear-gradient(180deg, #070a13 0%, #030509 100%);
  --surface: rgba(15, 23, 42, 0.65);
  --surface-hover: rgba(30, 41, 59, 0.7);
  --surface-active: rgba(51, 65, 85, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(59, 130, 246, 0.6);
  
  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.45);
  --accent-soft: rgba(37, 99, 235, 0.15);
  
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-success: #10b981;
  --text-danger: #ef4444;
  --text-warning: #f59e0b;
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.3);
  --warning: #f59e0b;
  
  --font: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --glow: 0 0 15px var(--accent-glow);
}

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

body {
  min-height: 100vh;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  line-height: 1.5;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Glassmorphism General */
.glass {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* Landing Page (Auth) Layout */
.hero-panel {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 3rem;
  align-items: center;
  justify-content: center;
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 2rem;
}

.brand-card {
  padding: 3rem;
  animation: float 6s ease-in-out infinite;
}

.brand-card h1 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-card p {
  font-size: 1.1rem;
  color: var(--text-muted);
  line-height: 1.8;
  margin-bottom: 2rem;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-badges span {
  padding: 0.5rem 1.25rem;
  border-radius: 99px;
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  font-size: 0.9rem;
  font-weight: 500;
}

.auth-card {
  padding: 2.5rem;
}

.tab-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 2rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.25rem;
  border-radius: 12px;
}

.tab-selector button {
  padding: 0.75rem;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.tab-selector button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--glow);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.auth-form.hidden {
  display: none;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

.input-field {
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  color: #fff;
  outline: none;
  font-family: var(--font);
  transition: var(--transition);
}

.input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

.submit-btn {
  padding: 0.9rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border: none;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--glow);
  transition: var(--transition);
}

.submit-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* Shell Layout for Admin Dashboard */
.dashboard-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(8, 12, 22, 0.9);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-container img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
}

.logo-container span {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  flex-grow: 1;
  overflow-y: auto;
}

.nav-item button {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  text-align: left;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: var(--transition);
}

.nav-item button:hover,
.nav-item button.active {
  background: var(--accent-soft);
  color: #fff;
  border-left: 3px solid var(--accent);
}

.logout-container {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

/* Dashboard Panel Content Area */
.content-area {
  padding: 2.5rem;
  overflow-y: auto;
  max-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
}

.page-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* Metric / Quick-grid Cards */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.metric-card {
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%);
  border-radius: 50%;
}

.metric-card span {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.metric-card strong {
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
}

/* Panel Sections & Forms layout */
.dashboard-tab-panel {
  display: none;
}

.dashboard-tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  animation: fadeIn 0.4s ease;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 2rem;
}

.panel-card {
  padding: 2rem;
}

/* Input lists and Forms inside Panels */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.button-row {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  box-shadow: var(--glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  box-shadow: 0 0 15px var(--danger-glow);
}

/* User Management Tables & Search */
.search-container {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: center;
}

.multi-filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.table-container {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}

.table th,
.table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.table th {
  background: rgba(15, 23, 42, 0.9);
  font-weight: 600;
  color: var(--text-muted);
}

.table tbody tr {
  transition: var(--transition);
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Status switch toggles */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .4s;
  border-radius: 34px;
  border: 1px solid var(--border);
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

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

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

/* Status Pill Indicators */
.status-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-pill.active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--text-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-pill.pending {
  background: rgba(245, 158, 11, 0.15);
  color: var(--text-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-pill.inactive {
  background: rgba(239, 68, 68, 0.15);
  color: var(--text-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Collapsible Tree Explorer Visuals */
.tree-container {
  overflow: auto;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid var(--border);
  min-height: 400px;
}

.tree-node {
  margin-left: 2rem;
  position: relative;
  padding-left: 1rem;
}

.tree-node::before {
  content: '';
  position: absolute;
  left: 0;
  top: 15px;
  width: 15px;
  height: 1px;
  background: var(--border);
}

.tree-node::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
}

.tree-node:last-child::after {
  height: 15px;
}

.node-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  width: max-content;
  transition: var(--transition);
  margin-bottom: 0.5rem;
}

.node-item:hover {
  border-color: var(--border-focus);
  transform: translateX(3px);
  background: rgba(30, 41, 59, 0.9);
}

.node-toggle-btn {
  font-weight: 700;
  color: var(--accent);
}

.node-name {
  font-weight: 600;
}

.node-id {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.node-level {
  background: var(--accent-soft);
  color: #93c5fd;
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  font-weight: 600;
}

/* Charts and distribution lists */
.histogram-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.histogram-row {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  align-items: center;
  gap: 1rem;
}

.histogram-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

.histogram-bar-wrapper {
  background: rgba(255, 255, 255, 0.05);
  height: 16px;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.histogram-bar-fill {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  height: 100%;
  border-radius: 99px;
  width: 0;
  transition: width 1s ease-out;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.histogram-value {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: right;
}

/* Animations */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

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

/* Responsive Overrides & Mobile Layout elements */

/* Prevent horizontal overflow issues across components */
html, body { 
  width: 100%;
}

* {
  min-width: 0;
}

/* Tables and generic containers should be allowed to shrink */
.table-container, .content-area, .panel-card, .section-grid, .quick-grid, .tree-container {
  max-width: 100%;
}

/* Improve default focus/selection on touch */
:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.7);
  outline-offset: 2px;
}

.mobile-top-bar {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  position: sticky;
  top: 0.5rem;
  z-index: 98;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

.mobile-menu-trigger {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: var(--transition);
}

.mobile-menu-trigger:hover {
  background: rgba(255,255,255,0.05);
}

.mobile-logo-text {
  font-size: 1.15rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mobile-bell {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: #fff;
}

.mobile-overlay-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.mobile-overlay-backdrop.show {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 900px) {
  /* Make charts/scroll areas fit smaller laptops/tablets */
  canvas { max-width: 100%; }

  .table th,
  .table td {
    padding: 0.75rem;
    font-size: 0.92rem;
  }

  .table-container {
    border-radius: 10px;
  }

  .tree-container {
    padding: 1rem;
  }

  .node-item {
    padding: 0.45rem 0.7rem;
    gap: 0.55rem;
    flex-wrap: wrap;
  }
  .hero-panel {
    grid-template-columns: 1fr;
    padding: 1.5rem;
    gap: 2rem;
  }
  
  .brand-card {
    padding: 1.5rem;
    text-align: center;
  }
  
  .brand-card h1 {
    font-size: 2.2rem;
  }
  
  .auth-card {
    padding: 1.5rem;
  }
  
  .dashboard-shell {
    grid-template-columns: 1fr;
    display: block;
  }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 260px;
    height: 100vh;
    z-index: 100;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    background: #080c16;
  }
  
  .sidebar.show {
    left: 0;
  }
  
  .mobile-top-bar {
    display: flex;
  }
  
  .content-area {
    padding: 1rem 1.25rem;
    max-height: none;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  
  .page-header h1 {
    font-size: 1.75rem;
  }
  
  .quick-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  
  .metric-card {
    padding: 1.25rem;
  }
  
  .metric-card strong {
    font-size: 1.5rem;
  }
  
  .section-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem;
  }
  
  .panel-card {
    padding: 1.25rem;
  }
  
  .multi-filter-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  
  .search-container {
    grid-template-columns: 1fr;
  }
  
  /* Ensure tree explorer wraps */
  .tree-node {
    margin-left: 0.75rem;
    padding-left: 0;
  }

  .tree-container {
    padding: 0.75rem;
    min-height: 320px;
  }

  /* Small phones */
  @media (max-width: 480px) {
    .brand-card h1 {
      font-size: 1.9rem;
    }

    .auth-card {
      padding: 1rem;
    }

    .page-header h1 {
      font-size: 1.5rem;
    }

    .panel-card {
      padding: 1rem;
    }

    .table th,
    .table td {
      padding: 0.55rem;
      font-size: 0.88rem;
    }

    .content-area {
      padding: 1rem 0.85rem;
    }

    .mobile-top-bar {
      padding: 0.5rem 0.85rem;
    }

    .node-item {
      margin-bottom: 0.35rem;
      width: 100%;
    }

    .children-container::after {
      display: none;
    }
  }
  
  /* Ensure button stack works on small mobile screens */
  .button-row {
    flex-direction: column;
    width: 100%;
  }
  
  .button-row .btn {
    width: 100%;
    text-align: center;
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
