:root {
  /* Default Pure Black Variables */
  --bg-color: #000000;
  --text-color: #ffffff;
  --text-secondary: #8a8a8e;
  --card-bg: #0a0a0a;
  --border-color: #1a1a1a;
  --accent-color: #c9a050;
  --button-bg: #ffffff;
  --button-text: #000000;
  --muted-text: #8a8a8e;
  
  --primary: var(--accent-color);
  --shadow: 0 10px 30px rgba(0,0,0,.08);
  --radius: 16px;
  --radius-sm: 10px;
}

/* Specificity Boost: Use html[data-theme] to ensure it overrides other definitions */

html[data-theme="pure-black"] {
  --bg-color: #000000;
  --text-color: #ffffff;
  --text-secondary: #8a8a8e;
  --card-bg: #0a0a0a;
  --border-color: #1a1a1a;
  --accent-color: #c9a050;
  --button-bg: #ffffff;
  --button-text: #000000;
}

html[data-theme="alabaster"] {
  --bg-color: #f5f5f7;
  --text-color: #000000;
  --text-secondary: #666666;
  --card-bg: #ffffff;
  --border-color: #e5e5e5;
  --accent-color: #000000;
  --button-bg: #000000;
  --button-text: #ffffff;
  --muted-text: #666666;
}

html[data-theme="terminal"] {
  --bg-color: #000b00;
  --text-color: #00ff88;
  --text-secondary: rgba(0, 255, 136, 0.6);
  --card-bg: #001500;
  --border-color: rgba(0, 255, 136, 0.2);
  --accent-color: #00ff88;
  --button-bg: #00ff88;
  --button-text: #000000;
  --muted-text: rgba(0, 255, 136, 0.5);
}

html[data-theme="royal-lux"] {
  --bg-color: #0a0c10;
  --text-color: #f8f0e3;
  --text-secondary: #94a3b8;
  --card-bg: #111827;
  --border-color: rgba(201, 160, 80, 0.2);
  --accent-color: #c9a050;
  --button-bg: #c9a050;
  --button-text: #000000;
  --muted-text: #94a3b8;
}

html[data-theme="nordic-frost"] {
  --bg-color: #0f172a;
  --text-color: #f1f5f9;
  --text-secondary: #94a3b8;
  --card-bg: #1e293b;
  --border-color: #334155;
  --accent-color: #38bdf8;
  --button-bg: #38bdf8;
  --button-text: #000000;
  --muted-text: #94a3b8;
}

html[data-theme="midnight-emerald"] {
  --bg-color: #00120d;
  --text-color: #e0f2f1;
  --text-secondary: #4db6ac;
  --card-bg: #001a14;
  --border-color: rgba(0, 255, 180, 0.15);
  --accent-color: #00ffa2;
  --button-bg: #00ffa2;
  --button-text: #00120d;
  --muted-text: #4db6ac;
}

html[data-theme="solaris-gold"] {
  --bg-color: #050810;
  --text-color: #fefefe;
  --text-secondary: #607d8b;
  --card-bg: #0a0f1e;
  --border-color: rgba(255, 170, 0, 0.15);
  --accent-color: #ffaa00;
  --button-bg: #ffaa00;
  --button-text: #050810;
  --muted-text: #607d8b;
}

html[data-theme="carbon-fiber"] {
  --bg-color: #0f0f0f;
  --text-color: #e0e0e0;
  --text-secondary: #757575;
  --card-bg: #151515;
  --border-color: #222222;
  --accent-color: #ffffff;
  --button-bg: #eeeeee;
  --button-text: #000000;
  --muted-text: #757575;
}

html[data-theme="cyber-neon"] {
  --bg-color: #05010d;
  --text-color: #00f2ff;
  --text-secondary: #5a189a;
  --card-bg: #0d0221;
  --border-color: rgba(188, 0, 255, 0.2);
  --accent-color: #bc00ff;
  --button-bg: #bc00ff;
  --button-text: #05010d;
  --muted-text: #5a189a;
}

html[data-theme="classic-paper"] {
  --bg-color: #f4f1ea;
  --text-color: #1a1a1a;
  --text-secondary: #7c7667;
  --card-bg: #ffffff;
  --border-color: #dcd7ca;
  --accent-color: #8b0000;
  --button-bg: #1a1a1a;
  --button-text: #f4f1ea;
  --muted-text: #7c7667;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; width: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  transition: background 0.4s ease, color 0.4s ease;
}

/* Sidebar Structure - UNTOUCHED (Only Colors Themed) */
.sidebar {
  background: var(--card-bg) !important;
  border-right: 1px solid var(--border-color);
  width: 280px;
  display: flex;
  flex-direction: column;
  padding: 24px;
  min-height: 100vh;
  min-height: 100dvh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 200;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: nowrap;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease, background 0.4s ease;
  -webkit-overflow-scrolling: touch;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 35px;
  color: var(--text-color);
  white-space: nowrap;
}

.sidebar-logo span {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.2px;
  color: var(--text-color);
}

.sidebar-logo-img {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 15px rgba(255,255,255,0.1);
  border: 1px solid var(--border-color);
  transition: transform 0.3s ease;
}

.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;
}

.sidebar-menu li {
  margin-bottom: 4px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
  line-height: normal;
  transition: all 0.2s ease;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
  background: var(--border-color) !important;
  color: var(--text-color) !important;
}

.sidebar-menu a svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  fill: currentColor;
  opacity: 0.7;
}

.sidebar-menu a:hover svg,
.sidebar-menu a.active svg {
  opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer-nav {
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footer-btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.footer-tile {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 16px 4px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  text-decoration: none;
  transition: all 0.2s ease;
}

.footer-tile:hover {
  border-color: var(--text-color);
  color: var(--text-color);
}

.footer-tile svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: currentColor;
}

.logout-btn-full {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  font-size: 14px;
  width: 100%;
}

.logout-btn-full:hover {
  background: rgba(255, 68, 68, 0.05);
  border-color: rgba(255, 68, 68, 0.2);
  color: #ff4444;
}

/* Folding Logic - PRESERVED */
@media (min-width: 861px) {
  .sidebar {
    width: 86px;
    padding: 24px 16px;
  }
  .sidebar:hover {
    width: 280px;
    padding: 24px;
  }
  
  .sidebar-logo span,
  .sidebar-menu a span,
  .footer-btn-grid .footer-tile span,
  .logout-btn-full span {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
  }

  .sidebar:hover .sidebar-logo span,
  .sidebar:hover .sidebar-menu a span,
  .sidebar:hover .footer-btn-grid .footer-tile span,
  .sidebar:hover .logout-btn-full span {
    opacity: 1;
    pointer-events: auto;
    transition-delay: 0.1s;
  }

  .footer-btn-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .sidebar:hover .footer-btn-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
}

.main-wrapper {
  margin-left: 86px;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 100vh;
  min-height: 100dvh;
}

@media (min-width: 861px) {
  .sidebar:hover ~ .main-wrapper {
    margin-left: 280px;
  }
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-110%);
    position: fixed;
    width: 280px !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    padding-top: calc(24px + env(safe-area-inset-top));
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0 !important;
  }
  .sidebar-menu {
    overflow-y: auto;
    flex-shrink: 1;
    min-height: 0;
  }
  .sidebar-footer-nav {
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .logout-btn-full {
    margin-bottom: 8px;
  }
}

/* Header Restoration */
header {
  background: var(--card-bg) !important;
  border-bottom: 1px solid var(--border-color) !important;
  transition: background 0.4s ease, border 0.4s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }

/* Ensure scrollbar is visible on mobile in the theme selector */
.custom-scrollbar::-webkit-scrollbar {
  width: 4px;
  display: block !important;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  opacity: 0.5;
}