:root {
  color-scheme: light;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --primary: #00a28a;
  --primary-hover: #008f7a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent-blue: #605bff;
  --accent-orange: #ff9f43;
  --accent-red: #ff5c5c;
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  --header-height: 80px;
  --sidebar-width: 260px;
}

.dark {
  color-scheme: dark;
  --bg-main: #15161d;
  --bg-card: #1c1f26;
  --bg-sidebar: #1c1f26;
  --primary: #00a28a;
  --primary-hover: #00bfa3;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

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

html {
  font-size: 15px;
}

body {
  font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  font-size: 1rem;
}

.app-bg {
  min-height: 100vh;
  position: relative;
}

/* Layout */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.app-sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 2000; /* Higher than fixed elements */
  overflow-y: auto; /* Enable internal scroll */
  -webkit-overflow-scrolling: touch;
}

.app-main {
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
  padding: 32px;
}

/* Sidebar Components */
.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.app-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-subtitle {
  display: none;
}

.app-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-pill:hover {
  color: var(--text-main);
  background: rgba(148, 163, 184, 0.1);
}

.nav-pill.active {
  background: var(--primary);
  color: #fff;
}

.nav-pill__icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}

/* Topbar */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.app-page {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.app-page-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Cards & Content */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.card h1, .card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tr:hover td {
  background: rgba(128, 128, 128, 0.02);
}

/* User Profile Sidebar Item */
.app-user {
  background: rgba(128, 128, 128, 0.05);
  padding: 16px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-user__avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: #eee;
  overflow: hidden;
}

.app-user__info {
  display: flex;
  flex-direction: column;
}

.app-user__email {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

.app-content {
  animation: fadeIn 0.4s ease-out;
}

/* Floating Action Button (FAB) - Desktop Default */
.fab-desktop {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--primary);
  color: white;
  display: flex !important;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 30px rgba(0, 162, 138, 0.4);
  z-index: 80;
  cursor: pointer;
  transition: transform 0.2s;
  text-decoration: none;
}

.fab-desktop:hover {
  transform: scale(1.1);
}

/* Responsive & Mobile Menu */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr !important;
  }
  
  .app-sidebar {
    display: flex !important;
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 100;
    transition: left 0.3s ease;
    box-shadow: 20px 0 50px rgba(0,0,0,0.5);
  }
  
  .app-sidebar.active {
    left: 0;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 90;
  }
  
  .sidebar-overlay.active {
    display: block;
  }

  /* NO GLOBAL SCROLL ON MOBILE - Content scrolls inside app-main */
  body {
    overflow: hidden !important;
    height: 100%;
    position: fixed;
    width: 100%;
  }

  .app-bg {
    height: 100dvh;
    overflow: hidden;
  }

  /* Fixed Top Header on Mobile */
  .app-topbar {
    position: fixed;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1500 !important;
    padding: 12px 16px;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border);
    height: 64px;
  }
  
  .app-main {
    position: absolute;
    top: 64px;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px;
    padding-bottom: 110px; /* Space for mobile nav */
    overflow-y: auto !important;
    overflow-x: hidden !important; /* Force NO horizontal scroll */
    -webkit-overflow-scrolling: touch;
    height: calc(100dvh - 64px);
    width: 100vw !important; /* Exact width */
    max-width: 100vw !important;
  }

  .scroll-horizontal-mobile {
    overflow-x: auto !important;
    width: 100% !important;
    max-width: calc(100vw - 20px); /* Slightly less than parent */
    -webkit-overflow-scrolling: touch;
  }

  .scroll-horizontal-mobile table {
    min-width: 650px !important; /* Slightly smaller for stability */
  }

  /* Compact spacing for cards on mobile */
  .card {
     padding: 10px !important;
     border-radius: 12px !important;
     max-width: 100% !important;
     overflow-x: hidden !important;
     margin-bottom: 12px;
  }

  .app-bg {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  /* Toolbar Items in fixed header */
  .app-topbar .flex-1 .app-page { display: none; }
  .app-topbar .flex-1 .app-page-sub { display: none; }
  .app-topbar .flex-1 { display: none; }
  
  .menu-btn {
    display: flex !important;
  }

  .app-content {
    animation: none !important; /* Avoid stacking context issues */
  }

  /* Mobile Centered FAB (+) */
  .fab-center {
    position: fixed !important;
    bottom: 35px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 162, 138, 0.45);
    z-index: 1800 !important; 
    border: 5px solid var(--bg-card);
  }

  .mobile-nav {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 12px !important;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 35px;
    display: flex !important;
    justify-content: space-around;
    align-items: center;
    padding: 0 5px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 1700 !important;
    height: 70px;
  }

  .mobile-nav__fab-space {
    width: 70px;
    flex-shrink: 0;
  }

  .mobile-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    flex: 1;
    padding-top: 4px;
  }

  .mobile-nav__item.active {
    color: var(--primary);
  }
}

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-main);
  background: var(--bg-card);
  cursor: pointer;
}

@media (min-width: 1025px) {
  .mobile-nav, .fab-center, .menu-btn {
    display: none !important;
  }
}

.mobile-nav__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.mobile-nav__item:active .mobile-nav__icon {
  transform: scale(0.9);
}

/* Theme Switcher Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--border);
  padding: 4px;
  border-radius: 999px;
  cursor: pointer;
}

.theme-toggle-item {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle-item.active {
  background: var(--bg-card);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
