:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-success: #059669;
  --accent-warning: #d97706;
  --accent-danger: #dc2626;
  --accent-info: #2563eb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Mobile Header Bar */
.mobile-header {
  display: none;
  height: 60px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-brand-title {
  font-weight: 800;
  font-size: 18px;
  color: var(--text-main);
}

.mobile-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0;
  transition: var(--transition);
}

.sidebar-overlay.mobile-active {
  display: block;
  opacity: 1;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 101;
  transition: transform 0.3s ease-in-out;
  box-shadow: var(--shadow-sm);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.brand-text h2 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-text span {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
}

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

.nav-item.active {
  background-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.user-profile {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.user-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 4px;
  width: fit-content;
}

.role-superadmin {
  background-color: rgba(220, 38, 38, 0.1);
  color: var(--accent-danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
}

.role-admin {
  background-color: rgba(217, 119, 6, 0.1);
  color: var(--accent-warning);
  border: 1px solid rgba(217, 119, 6, 0.2);
}

.role-user {
  background-color: rgba(37, 99, 235, 0.1);
  color: var(--accent-info);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-logout:hover {
  background-color: rgba(220, 38, 38, 0.1);
  color: var(--accent-danger);
}

/* Main Content Area */
.main-content {
  margin-left: 260px;
  flex: 1;
  padding: 32px;
  width: calc(100% - 260px);
  min-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.page-title p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* Cards & Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(79, 70, 229, 0.3);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-icon.purple { background: rgba(79, 70, 229, 0.1); color: var(--accent-primary); }
.stat-icon.green { background: rgba(5, 150, 105, 0.1); color: var(--accent-success); }
.stat-icon.amber { background: rgba(217, 119, 6, 0.1); color: var(--accent-warning); }
.stat-icon.blue { background: rgba(37, 99, 235, 0.1); color: var(--accent-info); }

.stat-data .value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main);
}

.stat-data .label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

.card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 15px; /* Mobile browser focus zoom prevention */
  transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  justify-content: center;
  min-height: 44px; /* Touch friendly hit area */
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-primary-hover);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background-color: var(--bg-primary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #edf2f7;
}

.btn-danger {
  background-color: var(--accent-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #b91c1c;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  min-height: 36px;
  border-radius: var(--radius-sm);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  min-width: 650px;
}

th {
  background-color: var(--bg-primary);
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  letter-spacing: 0.5px;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  vertical-align: middle;
}

tr:hover td {
  background-color: #f8fafc;
}

code {
  background-color: #f1f5f9;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 13px;
  color: #4338ca;
  border: 1px solid var(--border-color);
}

/* Alerts */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
}

.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: var(--transition);
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

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

.modal-title {
  font-size: 20px;
  font-weight: 800;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--text-main);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transform: translateY(20px);
  transition: var(--transition);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Auth Pages */
.auth-wrapper {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: var(--bg-primary);
}

.auth-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 36px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  text-align: center;
  margin-bottom: 28px;
}

.auth-brand .brand-icon {
  margin: 0 auto 16px auto;
  width: 54px;
  height: 54px;
  font-size: 28px;
}

.auth-brand h1 {
  font-size: 24px;
  font-weight: 800;
}

.auth-brand p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

/* -------------------------------------------------------------
 * MOBILE RESPONSIVE MEDIA QUERIES (Width < 992px)
 * ------------------------------------------------------------- */
@media (max-width: 991px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-active {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: block;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 20px 16px;
  }

  .page-header {
    margin-bottom: 20px;
    flex-direction: column;
    align-items: flex-start;
  }

  .page-header > div {
    width: 100%;
  }

  .page-header .btn {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .card {
    padding: 18px;
    border-radius: var(--radius-md);
  }

  .modal-card {
    padding: 20px;
    border-radius: var(--radius-md);
  }
}

@media (max-width: 576px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 24px 18px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-header form {
    width: 100%;
  }

  .card-header input[type="text"] {
    width: 100% !important;
  }
}
