:root {
  --bg-main: #f4f6fa;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --primary: #3b82f6;
  --primary-light: #eff6ff;
  --primary-dark: #2563eb;
  --success: #10b981;
  --success-light: #ecfdf5;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --orange: #f97316;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --sidebar-width: 250px;
  --header-height: 70px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  --primary-light: rgba(59, 130, 246, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Layout Architecture */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  overflow-y: auto;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: 1.35rem;
  font-weight: 700;
  color: #2563eb;
  letter-spacing: -0.5px;
}

.brand-logo .logo-icon {
  font-size: 1.5rem;
  color: #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-menu {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-category-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 14px 12px 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  text-align: left;
}

.menu-item:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}

.menu-item.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-color: rgba(59, 130, 246, 0.2);
}

.menu-item-group {
  display: flex;
  flex-direction: column;
}

.menu-item-group.open > .menu-item {
  color: var(--primary);
  background-color: rgba(59, 130, 246, 0.06);
}

.menu-arrow {
  font-size: 0.72rem;
  color: var(--text-muted);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
}

.menu-item-group.open > .menu-item .menu-arrow {
  transform: rotate(90deg);
  color: var(--primary);
}

.menu-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-item-left i {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
}

.submenu {
  display: flex;
  flex-direction: column;
  padding-left: 24px;
  margin-top: 2px;
  gap: 2px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin 0.2s ease;
}

.menu-item-group.open > .submenu {
  max-height: 500px;
  opacity: 1;
  margin-top: 4px;
  margin-bottom: 4px;
}

.submenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.84rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.submenu-item:hover {
  color: var(--primary);
  background-color: rgba(59, 130, 246, 0.07);
  padding-left: 16px;
}

.submenu-item.active {
  color: var(--primary);
  font-weight: 600;
  background-color: rgba(59, 130, 246, 0.08);
}

.submenu-bullet {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  display: inline-block;
  transition: all 0.2s ease;
}

.submenu-item:hover .submenu-bullet {
  border-color: var(--primary);
  background-color: var(--primary);
}

.submenu-item.active .submenu-bullet {
  border-color: var(--primary);
  background-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Main Area */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: var(--transition);
}

.main-wrapper.expanded {
  margin-left: 0;
}

/* Header */
.top-header {
  height: var(--header-height);
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 18px;
}

.toggle-sidebar-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle-sidebar-btn:hover {
  background-color: var(--bg-main);
  color: var(--text-primary);
}

.search-box {
  display: flex;
  align-items: center;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 7px 16px;
  width: 260px;
  transition: var(--transition);
}

.search-box:focus-within {
  width: 320px;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-box i {
  color: var(--text-muted);
  margin-right: 8px;
  font-size: 0.9rem;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 100%;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}

.header-icon-btn:hover {
  background-color: var(--bg-main);
  color: var(--primary);
}

.header-icon-btn .badge-pill {
  position: absolute;
  top: 4px;
  right: 4px;
  background-color: #ef4444;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 700;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
}

.country-flag {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  position: relative;
}

.user-profile-btn:hover {
  background-color: var(--bg-main);
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-color);
}

.user-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.user-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Floating Quick Settings widget */
.floating-settings-tab {
  position: fixed;
  right: 0;
  top: 45%;
  background-color: #3b82f6;
  color: white;
  width: 32px;
  height: 34px;
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 0 10px rgba(59, 130, 246, 0.4);
  cursor: pointer;
  z-index: 1000;
  transition: var(--transition);
}

.floating-settings-tab:hover {
  width: 38px;
  background-color: #2563eb;
}

/* Content Container */
.page-content {
  padding: 24px;
  flex: 1;
}

/* Dashboard Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-badge {
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
}

.stat-badge.trend-up {
  color: #10b981;
}

.stat-badge.trend-down {
  color: #ef4444;
}

.stat-card-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-sparkline {
  width: 100px;
  height: 40px;
}

/* Middle Row Grid */
.charts-grid-middle {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 20px;
  margin-bottom: 24px;
}

/* Bottom Row Grid */
.charts-grid-bottom {
  display: grid;
  grid-template-columns: 4fr 3fr 5fr;
  gap: 20px;
}

/* Card Widget Common */
.card-widget {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.widget-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

.widget-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.widget-menu-btn:hover {
  background-color: var(--bg-main);
  color: var(--text-primary);
}

/* By Device Donut Widget */
.donut-widget-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  position: relative;
}

.donut-chart-container {
  width: 170px;
  height: 170px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-center-label {
  position: absolute;
  text-align: center;
  pointer-events: none;
}

.donut-center-pct {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.donut-center-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 130px;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
}

.legend-dot-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.legend-color-box {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-val {
  font-weight: 600;
  color: var(--text-primary);
}

/* Traffic Source Widget */
.traffic-gauge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  position: relative;
}

.gauge-canvas-box {
  width: 180px;
  height: 180px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gauge-center-text {
  position: absolute;
  text-align: center;
}

.gauge-title {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gauge-val {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Messages and Posts Stack */
.stacked-mini-widgets {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.mini-stat-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.mini-stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mini-stat-title {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.mini-stat-num {
  font-size: 1.45rem;
  font-weight: 700;
  margin-top: 4px;
}

/* Dropdown Menu styling */
.dropdown-menu-custom {
  position: absolute;
  top: 110%;
  right: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px 0;
  min-width: 180px;
  z-index: 100;
  display: none;
}

.dropdown-menu-custom.show {
  display: block;
}

.dropdown-item-custom {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.dropdown-item-custom:hover {
  background-color: var(--bg-main);
  color: var(--primary);
}

.dropdown-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 4px 0;
}

/* Footer */
.app-footer {
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid-middle {
    grid-template-columns: 1fr;
  }
  .charts-grid-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .search-box {
    display: none;
  }
}
