:root {
  --white-static: #FFFFFF;
  /* Brand Colors (Static) */
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: rgba(79, 70, 229, 0.1);
  --secondary: #10B981;
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --warning: #F59E0B;

  /* Theme Colors (Dynamic - Light Mode Default) */
  --bg-color: #F3F4F6;
  --surface-color: #FFFFFF;
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-muted: #6B7280;
  --border-color: #E5E7EB;
  --input-bg: #FFFFFF;
  --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);

  /* Typography & Spacing */
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-width: 260px;
  --sidebar-mobile-width: 80%;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --transition-speed: 0.3s;
}

[data-theme="dark"] {
  --bg-color: #0F172A;
  --surface-color: #1E293B;
  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --border-color: #334155;
  --input-bg: #0F172A;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  
  /* Adjust static colors for dark contrast if needed */
  --primary-light: rgba(79, 70, 229, 0.2);
}

.logo-img {
  max-height: 40px;
  width: auto;
  display: block;
  object-fit: contain;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* Base Elements */
h1, h2, h3, h4 { color: var(--text-primary); font-weight: 600; }
h1 { font-size: 1.8rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
a { text-decoration: none; color: inherit; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  border: none;
  font-size: 0.95rem;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--white-static);
  box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-danger {
  background-color: var(--danger);
  color: var(--white-static);
}
.btn-danger:hover {
  background-color: var(--danger-hover);
}

/* Forms */
.form-group {
  margin-bottom: 1.2rem;
}
.form-group label {
  display: block;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.form-control {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family);
  font-size: 0.95rem;
  transition: all 0.2s ease;
  background-color: var(--input-bg);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none; /* Reset for iOS */
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236B7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-position: right 1rem center;
  background-repeat: no-repeat;
  background-size: 1.2em;
  padding-right: 2.5rem;
}

/* Cards (Glassmorphism inspired) */
.card {
  background: var(--surface-color);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  transition: box-shadow var(--transition-speed), background var(--transition-speed), border var(--transition-speed);
}
.card:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Layout */
.app-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--surface-color);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 40;
  transition: transform var(--transition-speed) ease, background-color var(--transition-speed);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  padding: 1.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.sidebar-close {
  display: none;
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--gray);
  cursor: pointer;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1.5rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition-speed);
  position: relative;
}
.nav-item:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}
.nav-item.active {
  color: var(--primary);
  background-color: rgba(79, 70, 229, 0.05);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background-color: var(--primary);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Mobile Toggle */
.mobile-toggle {
  display: none;
  font-size: 1.5rem;
  background: none;
  border: none;
  color: var(--dark);
  cursor: pointer;
  padding: 0.5rem;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 30;
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.show {
  opacity: 1;
}

/* Top bar for mobile */
.topbar {
  display: none;
  background: var(--surface-color);
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Alert/Popup System */
.alert-popup {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-left: 6px solid var(--primary);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 1.2rem 2rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  gap: 1.2rem;
  z-index: 9999;
  min-width: 320px;
  max-width: 90%;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.alert-popup.show {
  top: 2rem;
}
.alert-popup.danger {
  border-left-color: var(--danger);
  background-color: var(--surface-color);
  border-color: var(--danger);
}
.alert-popup.success {
  border-left-color: var(--secondary);
}

/* Grid Layouts */
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); gap: 1.5rem; }

/* Dashboard Cards */
.stat-card {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.stat-content h3 {
  font-size: 0.9rem;
  color: var(--gray);
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-content .value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--dark);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* Responsive Variables */
@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-mobile-width);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: 0;
    width: 100%;
  }

  .app-container {
    flex-direction: column;
  }
  
  .topbar {
    display: flex;
    box-shadow: var(--shadow-sm);
  }

  .sidebar-close {
    display: block;
  }

  .nav-item {
    padding: 1rem 1.5rem; /* Larger touch targets */
    font-size: 1.05rem;
  }
  
  .sidebar-header {
    padding: 2rem 1.5rem;
  }
  
  .sidebar-overlay {
    display: block;
    pointer-events: none;
  }
  .sidebar-overlay.show {
    pointer-events: auto;
    opacity: 1;
  }
  
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }
  
  .grid-cols-4 {
    grid-template-columns: 1fr;
  }

  /* Responsive Table Wrapper */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
  }

  /* Search Container Refinement */
  .search-container {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }
  .search-container .form-control {
    max-width: none !important;
  }
  .search-container button {
    width: 100%;
    margin-left: 0 !important;
    justify-content: center;
  }

  /* Typography for mobile */
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }
  
  .form-control {
    font-size: 16px; /* Prevents auto-zoom on iOS */
  }

  td, th {
    padding: 0.8rem 0.5rem !important; /* Slightly more compact but still touch-friendly */
    font-size: 0.9rem;
  }
}

/* Ensure images and videos are responsive */
img, video {
  max-width: 100%;
  height: auto;
}

/* Link Boxes (Responsive URLs and Buttons) */
.link-box {
  background: rgba(255, 255, 255, 0.1);
  padding: 1rem;
  border-radius: 8px;
  font-family: monospace;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  transition: all 0.3s ease;
}

.link-box span {
  word-break: break-all;
  font-size: 0.9rem;
  line-height: 1.4;
}

.link-box .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .link-box {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .link-box .btn {
    width: 100%;
    margin-top: 0.5rem;
    text-align: center;
    justify-content: center;
  }
}
