:root {
  --primary-color: #2563eb;
  --secondary-color: #1e293b;
  --accent-color: #06b6d4;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --sidebar-width: 260px;
  --topbar-height: 70px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: 'Inter', sans-serif;
  background-color: #f8fafc;
  color: #334155;
  overflow-x: hidden;
  margin-bottom: 0;
}

/* Sidebar Styles */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--secondary-color) 0%, #0f172a 100%);
  color: white;
  z-index: 1000;
  transition: all 0.3s ease;
  box-shadow: 4px 0 15px rgba(0,0,0,0.1);
}

.sidebar-brand {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: center;
}

.sidebar-brand h4 {
  margin-bottom: 0.5rem;
  font-weight: 700;
  font-size: 1.5rem;
}

.sidebar-brand small {
  color: #94a3b8;
  font-size: 0.85rem;
}

.sidebar-nav {
  padding: 1rem 0;
  height: calc(100vh - 120px);
  overflow-y: auto;
}

.nav-section-title {
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 1.5rem 1rem 0.5rem 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.nav-item {
  margin: 0.25rem 1rem;
}

.nav-link {
  color: #cbd5e1 !important;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  font-weight: 500;
  position: relative;
}

.nav-link:hover {
  color: white !important;
  background-color: rgba(255,255,255,0.1);
  transform: translateX(4px);
}

.nav-link.active {
  color: white !important;
  background-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-link i {
  width: 20px;
  text-align: center;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 999;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-left h5 {
  margin: 0;
  font-weight: 600;
  color: var(--secondary-color);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.notification-btn {
  position: relative;
  background: none;
  border: none;
  color: #6b7280;
  font-size: 1.25rem;
  padding: 0.5rem;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
}

.notification-btn:hover {
  background: #f3f4f6;
  color: var(--primary-color);
}

.notification-badge {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  background: var(--danger-color);
  color: white;
  border-radius: 50%;
  width: 8px;
  height: 8px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s ease;
}

.user-menu:hover {
  background: #e2e8f0;
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: var(--primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.875rem;
}

/* Content Area */
.content-area {
  padding: 1.5rem;
  min-height: calc(100vh - var(--topbar-height));
  max-width: 1400px;
  margin: 0 auto;
  /* Ensure content doesn't overlap with sticky topbar */
  position: relative;
}

.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--secondary-color);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-subtitle {
  color: #64748b;
  font-size: 0.95rem;
  margin-bottom: 0;
}

.page-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Dashboard Cards */
.dashboard-card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
  margin-bottom: 1.5rem;
  height: 140px;
  display: flex;
  align-items: center;
}

.dashboard-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.card-header-modern {
  padding: 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title-modern {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--secondary-color);
  margin: 0;
}

.card-body-modern {
  padding: 1.5rem;
}

/* Enhanced Button System */
.btn {
  border-radius: 6px;
  font-weight: 500;
  padding: 0.625rem 1.25rem;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.25;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.btn:active {
  transform: translateY(0);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: white;
}

.btn-success {
  background: var(--success-color);
  color: white;
  border-color: var(--success-color);
}

.btn-success:hover {
  background: #059669;
  border-color: #059669;
  color: white;
}

.btn-warning {
  background: var(--warning-color);
  color: white;
  border-color: var(--warning-color);
}

.btn-warning:hover {
  background: #d97706;
  border-color: #d97706;
  color: white;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
  border-color: var(--danger-color);
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: white;
}

.btn-outline-primary {
  background: transparent;
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-outline-primary:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.btn-outline-secondary {
  background: transparent;
  color: #6c757d;
  border-color: #6c757d;
}

.btn-outline-secondary:hover {
  background: #6c757d;
  color: white;
  border-color: #6c757d;
}

.btn-group {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn-modern {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
}

.btn-primary-modern {
  background: var(--primary-color);
  color: white;
}

.btn-primary-modern:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-outline-modern {
  background: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

.btn-outline-modern:hover {
  background: var(--primary-color);
  color: white;
}

/* Tables */
.table-modern {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border: 1px solid #e2e8f0;
}

.table-modern table {
  width: 100%;
  margin: 0;
}

.table-modern thead {
  background: #f8fafc;
}

.table-modern th {
  padding: 1rem 1.5rem;
  font-weight: 600;
  color: var(--secondary-color);
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table-modern td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.table-modern tbody tr:hover {
  background: #f8fafc;
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* Loading States */
.loading {
  position: relative;
  color: transparent !important;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  margin-left: -10px;
  border: 2px solid #f3f4f6;
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.btn.loading {
  pointer-events: none;
}

/* Status Badges */
.badge {
  padding: 0.35em 0.65em;
  font-size: 0.75em;
  font-weight: 500;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.badge-success {
  background-color: #dcfce7;
  color: #166534;
}

.badge-danger {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-info {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-secondary {
  background-color: #f1f5f9;
  color: #475569;
}

.status-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-active {
  background-color: #dcfce7;
  color: #166534;
}

.status-inactive {
  background-color: #fee2e2;
  color: #991b1b;
}

.status-pending {
  background-color: #fef3c7;
  color: #92400e;
}

/* Responsive Design */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--secondary-color);
  font-size: 1.25rem;
  padding: 0.5rem;
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .main-content {
    margin-left: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: block;
  }
}

@media (max-width: 768px) {
  .content-area {
    padding: 1rem;
  }

  .page-title {
    font-size: 1.5rem;
  }

  .topbar {
    padding: 0 1rem;
  }
}

/* Enhanced Form Styling */
.form-control {
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.1);
  outline: none;
}

.form-label {
  font-weight: 500;
  color: var(--secondary-color);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-text {
  color: #64748b;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

/* Legacy Bootstrap overrides for existing components */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.btn-primary {
  color: #fff;
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
  color: #fff;
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.border-top {
  border-top: 1px solid #e5e5e5;
}

.border-bottom {
  border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
  box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

/* Enhanced Alert System */
.alert {
  border-radius: 12px;
  border: none;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.alert-success {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  color: #166534;
  border-left: 4px solid var(--success-color);
}

.alert-danger {
  background: linear-gradient(135deg, #fef2f2, #fee2e2);
  color: #991b1b;
  border-left: 4px solid var(--danger-color);
}

.alert-warning {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  color: #92400e;
  border-left: 4px solid var(--warning-color);
}

.alert-info {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  color: #1e40af;
  border-left: 4px solid var(--primary-color);
}

.alert i {
  font-size: 1.25rem;
  margin-top: 0.125rem;
}

.alert-dismissible .btn-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
}

/* Notification Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
}

.toast {
  border-radius: 8px;
  border: none;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  backdrop-filter: blur(10px);
}

/* Form styling compatibility */
.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Admin Company Selector Styles */
.admin-company-selector {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-company-selector .form-select {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(255, 255, 255, 0.9);
  color: #334155;
  font-size: 0.875rem;
}

.admin-company-selector .form-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.25);
}

.admin-company-selector .badge {
  font-size: 0.75rem;
  padding: 0.35em 0.65em;
}

.admin-company-selector i.fas {
  color: rgba(255, 255, 255, 0.7);
}

/* Responsive design for smaller screens */
@media (max-width: 768px) {
  .admin-company-selector {
    display: none;
  }
}