@import url('vars.css');

/* ============================================
   MODERN BASE (2026 Design)
   ============================================ */
body {
  font-family: var(--font-sans);
  background: var(--bg-light);
  min-height: 100vh;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-dark);
  overflow-x: hidden;
}

::selection {
  background: var(--brand-blue);
  color: var(--text-light);
}

/* ============================================
   HEADER
   ============================================ */
.header {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--gray-200);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-fixed);
  padding: 0 var(--space-md);
  box-shadow: var(--shadow-sm);
  height: 70px;
  display: flex;
  align-items: center;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: var(--space-md);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--brand-blue);
  text-decoration: none;
  transition: color var(--transition-normal);
}
.logo:hover { color: var(--brand-dark); }
.logo i { font-size: var(--text-2xl); }

/* ============================================
   SIDEBAR (Modern)
   ============================================ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 260px;
  background: var(--bg-white);
  border-right: 1px solid var(--gray-200);
  padding: var(--space-lg) var(--space-md);
  transition: transform var(--transition-normal), width var(--transition-normal);
  z-index: var(--z-modal);
  box-shadow: var(--shadow-md);
  overflow-y: auto;
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--gray-100);
  margin-bottom: var(--space-md);
  min-height: 60px;
}

.sidebar-header h3 {
  color: var(--text-dark);
  font-size: var(--text-lg);
  font-weight: 700;
  background: linear-gradient(135deg, var(--brand-blue), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-menu { list-style: none; }
.sidebar-menu li { margin-bottom: 2px; }

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px var(--space-md);
  color: var(--gray-600);
  text-decoration: none;
  border-radius: var(--border-radius);
  transition: all var(--transition-fast);
  font-weight: 500;
  position: relative;
}

.sidebar-menu a i {
  width: 20px;
  text-align: center;
  font-size: 1rem;
}

.sidebar-menu a:hover {
  background: var(--gray-50);
  color: var(--brand-blue);
}

.sidebar-menu a.active {
  background: linear-gradient(135deg, rgba(37,99,235,0.08), rgba(124,58,237,0.08));
  color: var(--brand-blue);
  font-weight: 600;
}

.sidebar-menu a.active::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: linear-gradient(135deg, var(--brand-blue), var(--accent));
  border-radius: 0 3px 3px 0;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  margin-left: 260px;
  padding: var(--space-lg);
  padding-top: 90px;
  min-height: 100vh;
  transition: margin-left var(--transition-normal);
  width: calc(100% - 260px);
}

/* ============================================
   CARDS (Modern)
   ============================================ */
.card {
  background: var(--bg-white);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: all var(--transition-normal);
  overflow: hidden;
  width: 100%;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--gray-300);
}

.card-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--gray-100);
  background: var(--bg-white);
}

.card-header h4, .card-header h5 {
  font-weight: 600;
  color: var(--text-dark);
}

.card-body { padding: var(--space-lg); }
.card-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

/* Glass Card */
.card-glass {
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
}

/* ============================================
   STATS CARDS (Modern)
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--bg-white);
  border: 1px solid var(--gray-200);
  color: var(--text-dark);
  padding: var(--space-lg);
  border-radius: var(--border-radius-lg);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-blue), var(--accent));
  opacity: 0.6;
}

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

.stat-number {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: var(--space-xs);
  color: var(--brand-blue);
}

.stat-label {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

.stat-icon {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 1.75rem;
  opacity: 0.12;
  color: var(--brand-blue);
}

/* Gradient stat variants */
.stat-card-gradient {
  color: white;
  border: none;
}
.stat-card-gradient .stat-number { color: white; }
.stat-card-gradient .stat-label { color: rgba(255,255,255,0.8); }
.stat-card-gradient .stat-icon { color: white; opacity: 0.2; }

/* ============================================
   FORMS (Modern)
   ============================================ */
.form-group { margin-bottom: var(--space-lg); }

.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--gray-700);
  font-size: var(--text-sm);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: var(--text-base);
  transition: all var(--transition-fast);
  background: var(--bg-white);
  color: var(--text-dark);
  font-family: var(--font-sans);
  min-height: 48px;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.form-control::placeholder { color: var(--gray-400); }
.form-control:disabled {
  background: var(--gray-50);
  color: var(--gray-500);
  cursor: not-allowed;
}

.form-control.is-valid { border-color: var(--success); }
.form-control.is-invalid { border-color: var(--danger); }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 14px center;
  background-repeat: no-repeat;
  background-size: 16px 12px;
  padding-right: 44px;
}

/* ============================================
   TABLES (Modern)
   ============================================ */
.table-container {
  overflow-x: auto;
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--gray-200);
  background: var(--bg-white);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.table th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-700);
  font-size: var(--text-sm);
  position: sticky;
  top: 0;
}

.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-success { background: rgba(5,150,105,0.1); color: var(--success); }
.badge-warning { background: rgba(217,119,6,0.1); color: var(--warning); }
.badge-danger { background: rgba(220,38,38,0.1); color: var(--danger); }
.badge-info { background: rgba(37,99,235,0.1); color: var(--brand-blue); }

/* ============================================
   MODALS (Modern)
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
  padding: var(--space-md);
}

.modal.show { opacity: 1; visibility: visible; }

.modal-content {
  background: var(--bg-white);
  border-radius: var(--border-radius-xl);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  max-width: min(500px, 95vw);
  width: 100%;
  max-height: min(85vh, 600px);
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-normal);
}

.modal.show .modal-content { transform: scale(1) translateY(0); }

.modal-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: var(--text-xl); font-weight: 600; }
.modal-body { padding: var(--space-lg); }
.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--gray-100);
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--text-xl);
  color: var(--gray-400);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--border-radius);
  transition: all var(--transition-fast);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: min(400px, 90vw);
}

.toast {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px -5px rgba(0,0,0,0.15);
  border-left: 4px solid var(--success);
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 400px;
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.toast.show { transform: translateX(0); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }

/* ============================================
   BUTTONS (Modern)
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
  min-height: 44px;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--brand-blue);
  color: var(--text-light);
  box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }

.btn-outline { background: transparent; color: var(--brand-blue); border: 2px solid var(--brand-blue); }
.btn-outline:hover:not(:disabled) { background: var(--brand-blue); color: var(--text-light); }

.btn-success { background: var(--success); color: white; box-shadow: 0 2px 8px rgba(5,150,105,0.25); }
.btn-danger { background: var(--danger); color: white; }

.btn-sm { padding: 6px 12px; font-size: var(--text-xs); min-height: 36px; }
.btn-lg { padding: 14px 28px; font-size: var(--text-base); min-height: 52px; }
.btn-full { width: 100%; }

/* ============================================
   ANIMATIONS
   ============================================ */
.fade-in {
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn { to { opacity: 1; } }

.slide-up {
  opacity: 0;
  transform: translateY(20px);
  animation: slideUp 0.5s ease forwards;
}

@keyframes slideUp {
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   LOADER
   ============================================ */
#text-loader {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-sans);
  background: var(--bg-white);
  color: var(--brand-blue);
  z-index: calc(var(--z-toast) + 1);
  flex-direction: column;
  gap: var(--space-md);
}

.loader-title {
  background: linear-gradient(135deg, var(--brand-blue), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--gray-200);
  border-left-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.spinner-sm { width: 20px; height: 20px; border-width: 2px; }
.spinner-lg { width: 60px; height: 60px; border-width: 6px; }

/* ============================================
   UTILITY
   ============================================ */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--brand-blue); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

.d-flex { display: flex; }
.d-grid { display: grid; }
.d-none { display: none; }
.d-block { display: block; }
.d-inline-block { display: inline-block; }

.flex-column { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

.align-center { align-items: center; }
.align-start { align-items: flex-start; }
.align-end { align-items: flex-end; }

.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }

.w-100 { width: 100%; }
.h-100 { height: 100%; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }

.m-0 { margin: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0 { padding: 0; }
.p-1 { padding: 4px; }
.p-2 { padding: 8px; }
.p-3 { padding: 16px; }
.p-4 { padding: 24px; }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.container-fluid {
  width: 100%;
  padding: 0 var(--space-md);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
  .sidebar { width: 80px; }
  .sidebar-header h3, .sidebar-menu a span { display: none; }
  .sidebar-menu a { justify-content: center; padding: 12px; }
  .sidebar-menu a.active::before { display: none; }
  .main-content { margin-left: 80px; width: calc(100% - 80px); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-header h3, .sidebar-menu a span { display: block; }
  .sidebar-menu a { justify-content: flex-start; padding: 12px var(--space-md); }
  .sidebar-menu a.active::before { display: block; }
  .main-content { margin-left: 0; padding: var(--space-md); padding-top: 80px; width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
  .table th, .table td { padding: 10px 12px; font-size: var(--text-sm); }
  .modal-content { max-width: 95vw; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }
  .toast-container { right: var(--space-sm); left: var(--space-sm); max-width: none; }
  .header { height: 60px; padding: 0 var(--space-sm); }
  .card-header, .card-body, .card-footer { padding: var(--space-md); }
  .d-flex.gap-4 { gap: var(--space-md); }
}

@media (max-width: 480px) {
  .header { height: 56px; padding: 0 12px; }
  .main-content { padding: 12px; padding-top: 70px; }
  .stat-card { padding: var(--space-md); }
  .stat-number { font-size: var(--text-xl); }
  .container { padding: 0 12px; }
}

/* ============================================
   SIDEBAR OVERLAY
   ============================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: calc(var(--z-modal) - 1);
}
.sidebar-overlay.active { display: block; }

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
  .sidebar, .header, .btn, .toast-container, #text-loader { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; width: 100% !important; }
  .card { box-shadow: none !important; border: 1px solid var(--gray-300) !important; }
}

/* ============================================
   PLAN SELECTORS (for purchase.php)
   ============================================ */
.plan-type-selector, .device-count-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.plan-type-btn, .device-count-btn {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--border-radius);
  background: var(--bg-white);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  min-width: 120px;
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--gray-700);
}

.plan-type-btn:hover, .device-count-btn:hover {
  border-color: var(--brand-blue);
  background: var(--gray-50);
}

.plan-type-btn.active, .device-count-btn.active {
  border-color: var(--brand-blue);
  background: var(--brand-blue);
  color: white;
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

@media (max-width: 768px) {
  .plan-type-selector, .device-count-selector { flex-direction: column; }
  .plan-type-btn, .device-count-btn { min-width: auto; }
}

/* ============================================
   ADMIN STATS
   ============================================ */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.admin-stat-card {
  background: var(--bg-white);
  padding: var(--space-lg);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  position: relative;
  transition: all var(--transition-normal);
}

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

.admin-stat-number {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.admin-stat-label {
  color: var(--gray-600);
  font-size: var(--text-sm);
  font-weight: 500;
}

/* ============================================
   MOBILE TEXT FIX
   ============================================ */
.mobile-text-fix {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--brand-blue);
    font-size: var(--text-lg);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius);
    min-width: 44px;
    min-height: 44px;
  }
}

.mobile-menu-btn { display: none; }
@media (max-width: 768px) { .mobile-menu-btn { display: flex; } }
