:root {
  --primary: #5af1c6;
  --primary-hover: #37d4ad;
  --bg-dark: #071233;
  --bg-radial: radial-gradient(circle at top left, rgba(29, 78, 216, 0.24), transparent 36%), radial-gradient(circle at top right, rgba(90, 241, 198, 0.12), transparent 30%), linear-gradient(180deg, #071433 0%, #05102a 52%, #030a1d 100%);
  --card-bg: #1e293b;
  --card-bg-strong: rgba(11, 24, 52, 0.9);
  --text-main: #f8fafc;
  --text-muted: #9eb0ce;
  --accent: #5af1c6;
  --danger: #ef4444;
  --glass-border: rgba(148, 163, 184, 0.16);
  --shadow-lg: 0 18px 45px rgba(0, 0, 0, 0.28);
}

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

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg-radial);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 42%);
  opacity: 0.65;
}

a {
  color: inherit;
}

.glass-panel {
  background: var(--card-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease;
}

.glass-panel:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.34);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1.15rem;
  position: sticky;
  top: 0;
  z-index: 80;
  background: rgba(10, 16, 32, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--glass-border);
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #dbeafe;
  padding: 0.55rem 0.85rem;
  border-radius: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 2.5rem;
}

.nav-toggle i {
  font-size: 1.1rem;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--glass-border);
}

.navbar-brand {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(to right, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.navbar .nav-links {
  display: flex;
  gap: 1.5rem;
}

.navbar .nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
  padding: 0;
  border: 0;
  border-radius: 0;
}

.navbar .nav-links a:hover,
.navbar .nav-links a.active {
  color: var(--text-main);
  background: transparent;
  border-color: transparent;
  transform: none;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-mark {
  width: 2.45rem;
  height: 2.45rem;
  border-radius: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.24), rgba(16, 185, 129, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand-mark i {
  font-size: 1.25rem;
}

.brand-text {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, #e2e8f0 0%, #8ac8ff 48%, #5af1c6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-left: auto;
}

.nav-links a,
.nav-more summary {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 0.8rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  list-style: none;
}

.nav-links a i,
.nav-more summary i {
  font-size: 1.15rem;
}

.nav-more summary::-webkit-details-marker {
  display: none;
}

.nav-links a:hover,
.nav-more summary:hover,
.nav-more[open] > summary {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-links a.active,
.nav-more summary.active {
  color: #5af1c6;
  background: rgba(90, 241, 198, 0.1);
}

.nav-links a.nav-logout {
  color: var(--danger);
  opacity: 0.8;
}

.nav-links a.nav-logout:hover {
  color: var(--danger);
  opacity: 1;
  background: rgba(239, 68, 68, 0.1);
}

.nav-more {
  position: relative;
}

.nav-more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 180px;
  padding: 0.45rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 16, 32, 0.98);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3);
  display: none;
  flex-direction: column;
  gap: 0.3rem;
}

.nav-more[open] .nav-more-panel {
  display: flex;
}

.nav-backdrop {
  display: none;
}

.app-footer {
  margin-top: 4rem;
  padding: 1.5rem 1rem 2rem;
  text-align: center;
}

.app-footer a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: color 0.3s, transform 0.3s;
}

.app-footer a:hover {
  color: var(--text-main);
  transform: translateY(-1px);
}

.app-footer img {
  width: 120px;
  opacity: 0.55;
  transition: opacity 0.3s;
  filter: grayscale(1) brightness(200%);
}

.app-footer a:hover img {
  opacity: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 0.875rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.6);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

.btn-card {
  background: #28354c;
  border: none;
  padding: 1rem;
  border-radius: 0.75rem;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.5px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.3s;
  cursor: pointer;
  text-decoration: none;
}

.btn-card:hover {
  background: #3b4d6e;
}

.btn-action-on {
  background: rgba(59, 130, 246, 0.2) !important;
  color: #3b82f6 !important;
}

.btn-action-on:hover {
  background: rgba(59, 130, 246, 0.3) !important;
}

.btn-action-off {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #ef4444 !important;
}

.btn-action-off:hover {
  background: rgba(239, 68, 68, 0.3) !important;
}

.main-content {
  padding: 2rem;
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.footer {
  margin-top: 5rem;
  margin-bottom: 2rem;
  text-align: center;
}

.footer a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: color 0.3s;
}

.footer a:hover {
  color: var(--text-main);
}

.footer img {
  width: 120px;
  margin-top: 0.75rem;
  opacity: 0.5;
  transition: opacity 0.3s;
  filter: grayscale(1) brightness(200%);
}

.footer a:hover img {
  opacity: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.04em;
  margin-bottom: 0.35rem;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.icon-box {
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-value {
  font-size: 3rem;
  font-weight: 800;
  margin: 1rem 0;
  display: flex;
  align-items: center;
}

.stat-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.875rem;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.form-hint {
  display: block;
  margin-top: 0.4rem;
  color: #7dd3fc;
  font-size: 0.8rem;
  line-height: 1.5;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.5rem;
  color: white;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); }

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-on { background: rgba(16, 185, 129, 0.2); color: var(--accent); }
.status-off { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

.alert-success,
.alert-error {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-radius: 0.95rem;
  border: 1px solid transparent;
}

.alert-success {
  background: rgba(16, 185, 129, 0.12);
  color: #86efac;
  border-color: rgba(16, 185, 129, 0.18);
}

.alert-error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.18);
}

/* Table styles */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

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

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
}

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

.login-container {
  max-width: 400px;
  margin: 10vh auto;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  .topbar {
    padding: 0.8rem;
  }

  .brand-text {
    font-size: 1.15rem;
  }

  .nav-toggle {
    display: inline-flex;
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.5);
    z-index: 65;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .nav-links {
    position: fixed;
    top: 4.2rem;
    left: 0.8rem;
    right: 0.8rem;
    z-index: 70;
    margin-left: 0;
    padding: 0.65rem;
    border-radius: 1rem;
    background: rgba(10, 16, 32, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  body.nav-open .nav-links {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .nav-links a,
  .nav-more summary {
    width: 100%;
    justify-content: flex-start;
    padding: 0.7rem 0.8rem;
  }

  .nav-more {
    width: 100%;
  }

  .nav-more-panel {
    position: static;
    margin-top: 0.3rem;
    min-width: 0;
    box-shadow: none;
    border-radius: 0.75rem;
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
  }

  .nav-links a.nav-logout {
    margin-top: 0.2rem;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .glass-panel {
    padding: 1.5rem;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

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

  .page-header {
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.35rem;
  }

  /* Make the header text fit better on mobile */
  header h1 {
    font-size: 1.5rem !important;
  }

  /* Make sure the pill buttons row wraps correctly under titles */
  .title-and-pills {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 1rem !important;
  }

  .app-footer {
    margin-top: 2.5rem;
  }
}
