/* ═══════════════════════════════════════════════════════
   CHEMOGLO — MAIN STYLESHEET
   Global reset, CSS custom properties, animated background,
   particles, layout shell, sidebar navbar, footer
   ═══════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Design Tokens ──────────────────────────────────────── */
:root {
  /* Palette */
  --clr-bg:           #0a0a0a;
  --clr-surface:      rgba(255, 255, 255, 0.05);
  --clr-surface-md:   rgba(255, 255, 255, 0.09);
  --clr-surface-hi:   rgba(255, 255, 255, 0.14);
  --clr-border:       rgba(255, 255, 255, 0.12);
  --clr-border-hi:    rgba(255, 255, 255, 0.22);

  --clr-red:          #e63946;
  --clr-red-glow:     rgba(230, 57, 70, 0.45);
  --clr-red-dim:      rgba(230, 57, 70, 0.18);
  --clr-red-light:    #ff6b6b;

  --clr-white:        #ffffff;
  --clr-white-95:     rgba(255, 255, 255, 0.95);
  --clr-white-75:     rgba(255, 255, 255, 0.75);
  --clr-white-50:     rgba(255, 255, 255, 0.50);
  --clr-white-25:     rgba(255, 255, 255, 0.25);

  --clr-text:         rgba(255, 255, 255, 0.92);
  --clr-text-muted:   rgba(255, 255, 255, 0.55);
  --clr-text-dim:     rgba(255, 255, 255, 0.35);

  --clr-success:      #22c55e;
  --clr-success-dim:  rgba(34, 197, 94, 0.18);
  --clr-error:        #f87171;
  --clr-error-dim:    rgba(248, 113, 113, 0.18);
  --clr-warning:      #fbbf24;

  /* Typography */
  --font:             'Segoe UI', system-ui, -apple-system, sans-serif;

  /* Layout */
  --sidebar-w:        220px;
  --sidebar-w-collapsed: 60px;
  --topbar-h:         0px;

  /* Radii */
  --r-sm:  8px;
  --r-md:  14px;
  --r-lg:  22px;
  --r-xl:  30px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:   0 6px 24px rgba(0,0,0,0.55);
  --shadow-lg:   0 14px 48px rgba(0,0,0,0.7);
  --shadow-red:  0 0 24px var(--clr-red-glow);

  /* Transitions */
  --ease: 0.22s ease;
}

/* ── Base ────────────────────────────────────────────────── */
html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Animated Background ─────────────────────────────────── */
.animated-background {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(230,57,70,0.18) 0%, transparent 65%),
    radial-gradient(ellipse 60% 50% at 85% 80%, rgba(180,20,30,0.14) 0%, transparent 60%),
    radial-gradient(ellipse 90% 70% at 50% 50%, rgba(30,0,0,0.5) 0%, transparent 100%),
    #0a0a0a;
  animation: bgPulse 12s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.85; }
  100% { opacity: 1; }
}

/* ── Particles ──────────────────────────────────────────── */
.particle {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
  animation: particleFloat 22s ease-in-out infinite;
  background: radial-gradient(circle, rgba(230,57,70,0.35) 0%, transparent 70%);
}

.particle:nth-child(1) { width: 240px; height: 240px; top: 5%;  left: 8%;  animation-delay: 0s;  animation-duration: 20s; }
.particle:nth-child(2) { width: 180px; height: 180px; top: 60%; left: 78%; animation-delay: 5s;  animation-duration: 26s; }
.particle:nth-child(3) { width: 300px; height: 300px; top: 78%; left: 5%;  animation-delay: 10s; animation-duration: 30s; }
.particle:nth-child(4) { width: 120px; height: 120px; top: 28%; left: 65%; animation-delay: 3s;  animation-duration: 18s; }

@keyframes particleFloat {
  0%, 100% { transform: translate(0, 0)    scale(1);    opacity: 0.6; }
  33%       { transform: translate(25px, -40px) scale(1.08); opacity: 0.3; }
  66%       { transform: translate(-18px, 20px) scale(0.94); opacity: 0.5; }
}

/* ── Layout Shell ────────────────────────────────────────── */
body.layout {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: margin-left var(--ease);
}

.main-content--centered {
  justify-content: center;
  align-items: center;
}

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 4px;
}

.page-header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--clr-white-95);
  letter-spacing: -0.5px;
  text-shadow: 0 0 20px var(--clr-red-glow);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  z-index: 200;

  background: rgba(10, 0, 0, 0.75);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid rgba(230, 57, 70, 0.2);
  box-shadow: 4px 0 32px rgba(0,0,0,0.6), inset -1px 0 0 rgba(230,57,70,0.08);

  transition: width var(--ease);
  overflow: hidden;
}

/* Header row inside sidebar */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 20px 18px;
  border-bottom: 1px solid rgba(230, 57, 70, 0.15);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #ffffff 0%, var(--clr-red-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--clr-white-50);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: color var(--ease), background var(--ease);
  line-height: 1;
}

.sidebar-toggle:hover {
  color: var(--clr-white);
  background: var(--clr-surface-md);
}

/* Nav list */
.sidebar-nav {
  list-style: none;
  padding: 14px 10px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(230,57,70,0.3);
  border-radius: var(--r-pill);
}

.sidebar-item {
  margin-bottom: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--clr-white-75);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease);
  position: relative;
  overflow: hidden;
}

.sidebar-link::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--clr-red);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  opacity: 0;
  transition: opacity var(--ease);
}

.sidebar-link:hover {
  background: var(--clr-surface-md);
  color: var(--clr-white);
}

.sidebar-link.active {
  background: var(--clr-red-dim);
  color: var(--clr-white);
  box-shadow: inset 0 0 12px rgba(230,57,70,0.12);
}

.sidebar-link.active::before {
  opacity: 1;
}

.sidebar-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* User block at bottom of sidebar */
.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid rgba(230, 57, 70, 0.15);
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--clr-white-75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

/* ── Dev Pill ─────────────────────────────────────────────── */
.dev-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--clr-warning);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ── Footer ──────────────────────────────────────────────── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  font-size: 0.78rem;
  color: var(--clr-text-dim);
  border-top: 1px solid var(--clr-border);
  background: rgba(10, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-shrink: 0;
  margin-top: auto;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    width: var(--sidebar-w-collapsed);
  }
  .sidebar-logo,
  .sidebar-label,
  .sidebar-user-name {
    display: none;
  }
  .sidebar-header {
    justify-content: center;
    padding: 20px 0;
  }
  .main-content {
    margin-left: var(--sidebar-w-collapsed);
    padding: 20px 16px;
  }
}

@media (max-width: 600px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid rgba(230,57,70,0.2);
  }
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    padding: 8px;
  }
  .main-content {
    margin-left: 0;
  }
}

/* ── DB Status Indicator ─────────────────────────────────── */
.sidebar-db-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 14px;
  font-size: 11px;
  color: var(--clr-text-dim);
  border-top: 1px solid rgba(230, 57, 70, 0.15);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
}

.db-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15);
  transition: background var(--ease), box-shadow var(--ease);
}

.db-status-dot.awake  {
  background: var(--clr-success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}
.db-status-dot.asleep {
  background: var(--clr-warning);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.6);
}
.db-status-dot.error  {
  background: var(--clr-error);
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.6);
}

/* Hide label text when sidebar is collapsed */
@media (max-width: 900px) {
  .db-status-label {
    display: none;
  }
  .sidebar-db-status {
    justify-content: center;
    padding: 10px 0 14px;
  }
}