/* ════════════════════════════════════════════════════════
   SIDEBAR.CSS — Unified Sidebar System for SANTET V3
   Used by: dashboard.html, admin.html, and all authenticated pages
   Classes: .sidebar, .topbar, .mob-overlay
   Dependencies: design tokens from style.css (--sw, --sw-icon, --r3, etc.)
════════════════════════════════════════════════════════ */

/* ── Sidebar container (floating) ───────────────────── */
.sidebar {
  position: fixed;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--sw);
  background: rgba(15,15,20,.85);
  border: 1px solid rgba(255,184,0,.12);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 300;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: width .3s cubic-bezier(.4,0,.2,1), transform .3s cubic-bezier(.4,0,.2,1);
  will-change: width;
}

/* Top shimmer accent line */
.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--r3), transparent);
  background-size: 200% auto;
  animation: shimmer 4s linear infinite;
  box-shadow: 0 0 12px rgba(255,184,0,.3);
  pointer-events: none;
  border-radius: 16px 16px 0 0;
}

/* Collapsed (minimized) state */
.sidebar.collapsed {
  width: 56px;
}

/* ── Sidebar scrollbar ───────────────────────────────── */
.sidebar-nav::-webkit-scrollbar {
  width: 3px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 3px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: var(--r3);
}

/* ── Brand / logo section ────────────────────────────── */
.sidebar-logo {
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.sidebar-logo-texts {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-logo-texts {
  opacity: 0;
  pointer-events: none;
  width: 0;
}

.logo-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--r3), var(--orange, #f97316));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-sub {
  font-size: 10px;
  color: var(--tx3);
  margin-top: 1px;
}

/* ── Shield icon ─────────────────────────────────────── */
.security-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--r3);
  background: linear-gradient(135deg, rgba(231, 76, 60, .18), rgba(139, 0, 0, .08));
  border: 1px solid var(--border-r);
  border-radius: var(--radius-sm);
  box-shadow:
    0 0 16px rgba(231, 76, 60, .25),
    inset 0 1px 0 rgba(255, 255, 255, .08);
  position: relative;
  overflow: hidden;
  transition:
    box-shadow var(--transition),
    transform var(--transition);
}

.security-logo::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(231, 76, 60, .25), transparent 65%);
  pointer-events: none;
}

.security-logo svg {
  display: block;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 0 4px rgba(231, 76, 60, .6));
}

.security-logo:hover {
  box-shadow:
    0 0 24px rgba(231, 76, 60, .45),
    inset 0 1px 0 rgba(255, 255, 255, .1);
  transform: scale(1.04);
}

.security-logo--lg {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}
.security-logo--lg svg {
  width: 20px;
  height: 20px;
}

.security-logo--sm {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}
.security-logo--sm svg {
  width: 17px;
  height: 17px;
}

.security-logo--xs {
  width: 18px;
  height: 18px;
  border-radius: 5px;
}
.security-logo--xs svg {
  width: 10px;
  height: 10px;
}

/* ── Sidebar nav ─────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  font-size: 9px;
  font-weight: 700;
  color: var(--tx3);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 14px 10px 5px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition);
}

.sidebar.collapsed .nav-section {
  opacity: 0;
  height: 0;
  padding: 0;
}

/* ── Nav items ───────────────────────────────────────── */
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--tx2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: all var(--transition);
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

/* Left glow bar (default hidden) */
.nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--r3);
  border-radius: 0 2px 2px 0;
  transform: scaleY(0);
  transform-origin: center;
  transition: transform var(--transition);
  box-shadow: 0 0 8px var(--r3);
}

.nav-item:hover {
  background: rgba(255, 255, 255, .04);
  color: var(--tx);
  border-color: var(--border);
}

.nav-item:hover::before {
  transform: scaleY(1);
}

/* Active state — orange/gold glow */
.nav-item.active {
  background: linear-gradient(90deg, rgba(231, 76, 60, .12), rgba(231, 76, 60, .05));
  color: var(--r3);
  border-color: var(--border-r);
  border-left-color: var(--r3);
  font-weight: 600;
}

.nav-item.active::before {
  transform: scaleY(1);
  box-shadow: 0 0 12px var(--r3);
}

.nav-item.active .nav-icon {
  color: var(--r3);
}

/* Nav icon */
.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  color: var(--tx3);
  flex-shrink: 0;
  transition: color var(--transition);
}

.nav-icon--logo {
  width: auto;
  display: inline-flex;
  align-items: center;
}

/* Nav label text */
.nav-label {
  transition: opacity var(--transition);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-label {
  opacity: 0;
  width: 0;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 9px 0;
  border-left-color: transparent;
}

.sidebar.collapsed .nav-item::before {
  display: none;
}

/* Nav badge / dot */
.nav-dot {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 5px;
  background: var(--yellow-bg);
  color: var(--yellow);
}

.nav-dot.green {
  background: var(--green-bg);
  color: var(--green);
}

.nav-dot.red {
  background: var(--r-bg);
  color: var(--r4);
}

.sidebar.collapsed .nav-dot {
  display: none;
}

/* ── Sidebar status block ────────────────────────────── */
.sidebar-status-block {
  padding: 8px 12px 6px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-status-block {
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--tx3);
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
}

.status-badge.on {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.status-badge.off {
  background: rgba(255, 255, 255, .05);
  color: var(--tx3);
  border: 1px solid var(--border);
}

/* ── Sidebar footer ──────────────────────────────────── */
.sidebar-footer {
  padding: 10px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

/* User chip */
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  background: rgba(231, 76, 60, .07);
  border: 1px solid var(--border-r);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-r);
  transition: box-shadow var(--transition);
  overflow: hidden;
}

.user-chip:hover {
  box-shadow: var(--shadow-r2);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--r1), var(--r2));
  box-shadow: 0 0 10px rgba(192, 57, 43, .4);
  animation: pulse-ring 3.5s ease-in-out infinite;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  transition: opacity var(--transition);
}

.sidebar.collapsed .user-info {
  opacity: 0;
  width: 0;
}

.user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--tx);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 10px;
  color: var(--r3);
  font-weight: 500;
}

/* Logout button */
.logout-btn {
  color: var(--tx3);
  font-size: 13px;
  text-decoration: none;
  padding: 3px 5px;
  border-radius: 4px;
  transition: all var(--transition);
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.logout-btn:hover {
  color: var(--r4);
}

/* Brand footer text */
.sc-brand {
  text-align: center;
  font-size: 9px;
  color: var(--tx3);
  letter-spacing: .4px;
  transition: opacity var(--transition);
}

.sc-brand span {
  color: var(--tx);
  font-weight: 700;
  opacity: .75;
}

.sidebar.collapsed .sc-brand {
  opacity: 0;
  height: 0;
  overflow: hidden;
}

/* ── Sidebar collapse toggle ─────────────────────────── */
.sidebar-toggle-btn {
  position: fixed;
  top: 28px;
  left: calc(var(--sw) + 12px + 2px);
  z-index: 310;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--card);
  border: 1px solid var(--border-r);
  border-radius: 50%;
  cursor: pointer;
  color: var(--r3);
  font-size: 12px;
  transition: all .2s;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.sidebar-toggle-btn:hover {
  background: rgba(255,184,0,.15);
  border-color: var(--r3);
  transform: scale(1.1);
}

.sidebar.collapsed ~ .sidebar-toggle-btn {
  left: calc(60px + 12px + 2px);
}
  box-shadow: var(--shadow);
  z-index: 10;
  transition: all var(--transition);
  color: var(--tx3);
  font-size: 10px;
}

.sidebar-toggle-btn:hover {
  background: var(--surface2);
  color: var(--tx);
  border-color: var(--border2);
}

.sidebar.collapsed .sidebar-toggle-btn {
  transform: translateY(-50%) rotate(180deg);
}

/* ════════════════════════════════════════════════════════
   TOPBAR (mobile / tablet)
════════════════════════════════════════════════════════ */
.topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  z-index: 250;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, .3);
}

.topbar-menu {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--tx2);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.topbar-menu:hover {
  background: var(--surface);
  color: var(--tx);
}

.topbar-title {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
  background: linear-gradient(135deg, var(--r3), var(--orange, #f97316));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-user {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--r1), var(--r2));
  flex-shrink: 0;
}

/* ── Mobile overlay ──────────────────────────────────── */
.mob-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 290;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(4px);
}

.mob-overlay.open {
  display: block;
  animation: fade-in .2s;
}

/* ════════════════════════════════════════════════════════
   MAIN WRAP (push content right of sidebar)
════════════════════════════════════════════════════════ */
.main-wrap {
  margin-left: calc(var(--sw) + 24px);
  min-height: 100vh;
  padding: 32px 28px 48px;
  transition: margin-left .3s cubic-bezier(.4,0,.2,1);
}

body.sidebar-collapsed .main-wrap,
.sidebar.collapsed ~ .main-wrap {
  margin-left: 80px;
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE — TABLET / MOBILE
════════════════════════════════════════════════════════ */
/* ── Collapsed state details ─────────────────────── */
.sidebar.collapsed .sidebar-logo-texts,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .sidebar-status-block,
.sidebar.collapsed .user-info,
.sidebar.collapsed .sc-brand,
.sidebar.collapsed .logout-btn {
  display: none;
}
.sidebar.collapsed .sidebar-logo {
  padding: 12px 8px;
  justify-content: center;
}
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px 0;
}
.sidebar.collapsed .user-chip {
  justify-content: center;
  padding: 8px;
}
.sidebar.collapsed .sidebar-toggle-btn {
  right: 50%;
  transform: translateX(50%);
}

@media (max-width: 768px) {
  :root {
    --sw: 260px;
    --sw-icon: 0px;
  }

  .sidebar {
    display: none;
  }

  .sidebar.open {
    display: flex;
    width: 260px;
    animation: slide-in-left .3s cubic-bezier(.22, .68, 0, 1.2);
  }

  /* When open, show all collapsed text */
  .sidebar.open .sidebar-logo-texts,
  .sidebar.open .nav-label,
  .sidebar.open .nav-section,
  .sidebar.open .sidebar-status-block,
  .sidebar.open .user-info,
  .sidebar.open .sc-brand {
    display: block;
    opacity: 1;
    width: auto;
    pointer-events: auto;
    height: auto;
    padding: revert;
    overflow: visible;
  }

  .sidebar.open .nav-item {
    justify-content: flex-start;
    padding: 7px 10px;
    border-left-width: 3px;
  }

  .sidebar.open .nav-item::before {
    display: block;
  }

  .sidebar.open .user-chip {
    justify-content: flex-start;
    padding: 9px 10px;
  }

  .sidebar.open .logout-btn {
    display: inline-block;
  }

  /* Topbar visible on mobile */
  .topbar {
    display: flex;
  }

  /* Main wraps below topbar */
  .main-wrap {
    margin-left: 0;
    padding: 70px 16px 40px;
  }
}

@media (max-width: 520px) {
  .main-wrap {
    padding: 65px 12px 36px;
  }
}

/* ════════════════════════════════════════════════════════
   KEYFRAMES (sidebar-specific, needs to exist locally)
════════════════════════════════════════════════════════ */
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(192, 57, 43, .5); }
  70%  { box-shadow: 0 0 0 8px rgba(192, 57, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0); }
}


/* ── SIDEBAR POLISH ────────────────────────────────── */

/* Brand section — better alignment */
.sidebar-logo-row {
  align-items: center;
}

.logo-text {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.logo-sub {
  font-size: 10px;
  color: var(--tx3);
  margin-top: 2px;
}

/* Nav items — better spacing */
.nav-item {
  padding: 8px 12px;
  margin: 1px 0;
}

.nav-item:hover {
  background: rgba(255, 184, 0, .06);
}

.nav-item.active {
  background: rgba(255, 184, 0, .1);
  border-left: 3px solid var(--r3);
}

/* Status block — cleaner look */
.sidebar-status-block {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.sidebar-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--tx3);
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.status-badge.on {
  background: rgba(34, 197, 94, .15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, .3);
}

.status-badge.off {
  background: rgba(231, 76, 60, .15);
  color: #e74c3c;
  border: 1px solid rgba(231, 76, 60, .3);
}

/* User chip — better visual */
.user-chip {
  background: rgba(255, 184, 0, .06);
  border: 1px solid rgba(255, 184, 0, .15);
  border-radius: 10px;
  padding: 10px 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  font-size: 13px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--r3), var(--orange, #f97316));
  box-shadow: 0 0 12px rgba(255, 184, 0, .3);
  animation: none;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--tx);
}

.user-role {
  font-size: 10px;
  color: var(--r3);
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* Logout button */
.logout-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--tx3);
  transition: all 0.2s;
}

.logout-btn:hover {
  background: rgba(231, 76, 60, .15);
  color: #e74c3c;
}

/* Brand footer */
.sc-brand {
  font-size: 10px;
  color: var(--tx3);
  text-align: center;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.sc-brand span {
  color: var(--r3);
  font-weight: 600;
}
