@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #1967d2;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --secondary: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #6366f1;
  --dark: #0f172a;
  --sidebar-bg: #111827;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1967d2;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  min-height: 100vh;
  direction: rtl;
  text-align: right;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-logo .logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.sidebar-logo h1 {
  font-size: 14px;
  color: #fff;
  font-weight: 600;
  line-height: 1.3;
}

.sidebar-logo p {
  font-size: 11px;
  color: var(--sidebar-text);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(148, 163, 184, 0.5);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px 0 0 8px;
  margin: 2px 0 2px 8px;
  transition: all 0.2s ease;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 500;
}

.nav-item.active::before {
  display: none;
}

.nav-item .icon {
  font-size: 18px;
  min-width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--sidebar-text);
}

.logout-btn {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 18px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s;
  display: flex;
  align-items: center;
}

.logout-btn:hover {
  color: var(--danger);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  gap: 16px;
}

.page-title h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-title p {
  font-size: 12px;
  color: var(--text-secondary);
}

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

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-primary);
}

/* ===== PAGE CONTENT ===== */
.page-content {
  padding: 28px;
  flex: 1;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

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

.alert-success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.alert-danger {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-card.blue::before {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.stat-card.green::before {
  background: linear-gradient(90deg, var(--success), #34d399);
}

.stat-card.orange::before {
  background: linear-gradient(90deg, var(--warning), #fbbf24);
}

.stat-card.red::before {
  background: linear-gradient(90deg, var(--danger), #f87171);
}

.stat-card.purple::before {
  background: linear-gradient(90deg, var(--info), #818cf8);
}

.stat-card.teal::before {
  background: linear-gradient(90deg, #14b8a6, #2dd4bf);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 14px;
}

.stat-card.blue .stat-icon {
  background: var(--primary-light);
}

.stat-card.green .stat-icon {
  background: #d1fae5;
}

.stat-card.orange .stat-icon {
  background: #fef3c7;
}

.stat-card.red .stat-icon {
  background: #fee2e2;
}

.stat-card.purple .stat-icon {
  background: #ede9fe;
}

.stat-card.teal .stat-icon {
  background: #ccfbf1;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: 22px;
}

/* ===== TABLES ===== */
.table-responsive {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  background: #f8fafc;
  padding: 12px 14px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #e0f2fe;
  color: #075985;
}

.badge-secondary {
  background: #f1f5f9;
  color: #475569;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:hover {
  background: #d97706;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
  color: var(--text-primary);
  box-shadow: none;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-outline {
  background: transparent;
  border: 1px solid;
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  color: white;
}

.btn-icon {
  padding: 6px;
  width: 32px;
  height: 32px;
  justify-content: center;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

.form-control::placeholder {
  color: #94a3b8;
}

select.form-control {
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== MODALS ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: modalIn 0.25s ease;
}

.modal-lg {
  max-width: 720px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  color: var(--text-secondary);
  line-height: 1;
  padding: 2px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== SEARCH + FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar .form-control {
  min-width: 120px;
  max-width: 200px;
  padding: 7px 10px;
}

/* ===== CHARTS ===== */
.chart-container {
  position: relative;
  height: 260px;
}

/* ===== PAGINATION / EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 14px;
}

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dashboard-grid .full-width {
  grid-column: 1 / -1;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-right: 0;
  }

  .mobile-menu-btn {
    display: block;
  }

  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .overlay.active {
    display: block;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {

  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .page-content {
    padding: 16px;
  }

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

  .card-header .btn {
    width: 100%;
    justify-content: center;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar .form-control {
    max-width: 100%;
  }

  .filter-bar .btn {
    width: 100%;
    justify-content: center;
  }

  .top-header {
    padding: 0 16px;
    gap: 8px;
  }

  .page-title h2 {
    font-size: 16px;
  }

  /* Force tables to be horizontally scrollable on small screens */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
  }

  .data-table {
    min-width: 600px;
    /* Minimum width to avoid squishing table columns on mobile */
  }

  .modal-body,
  .modal-footer {
    padding: 16px;
  }
}

/* ===== UTILITIES ===== */
.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-secondary);
  font-size: 13px;
}

.fw-bold {
  font-weight: 700;
}

.mt-1 {
  margin-top: 8px;
}

.mt-2 {
  margin-top: 16px;
}

.mt-3 {
  margin-top: 24px;
}

.mb-1 {
  margin-bottom: 8px;
}

.mb-2 {
  margin-bottom: 16px;
}

.mb-3 {
  margin-bottom: 24px;
}

.d-flex {
  display: flex;
}

.align-center {
  align-items: center;
}

.gap-1 {
  gap: 8px;
}

.gap-2 {
  gap: 16px;
}

.flex-1 {
  flex: 1;
}

/* ===== PRINT ===== */
@media print {

  .no-print,
  .sidebar,
  .top-header,
  .overlay,
  .actions-bar,
  .btn-print {
    display: none !important;
  }

  body {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }

  .page-content {
    padding: 0 !important;
  }

  .card {
    box-shadow: none !important;
    border: none !important;
    /* Often cleaner to remove borders on print if they are subtle */
  }
}

/* ===== LOADING SPINNER ===== */
.spinner {
  border: 3px solid rgba(14, 165, 233, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 0.8s linear infinite;
}

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

/* ===== CONSUMPTION METER ===== */
.consumption-bar {
  height: 6px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 4px;
}

.consumption-bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.5s ease;
}

/* Modern Ergonomic Modal */
.modern-alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modern-alert-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modern-alert-container {
  background: #ffffff;
  width: 90%;
  max-width: 440px;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
  text-align: center;
  padding: 32px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.modern-alert-overlay.active .modern-alert-container {
  transform: translateY(0) scale(1);
}

.modern-alert-icon {
  width: 72px;
  height: 72px;
  background: hsl(210, 100%, 96%);
  color: #1967d2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 20px;
}

.modern-alert-title {
  font-size: 20px;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 12px;
  font-family: 'Tajawal', sans-serif;
}

.modern-alert-message {
  font-size: 16px;
  color: #64748b;
  line-height: 1.6;
  margin-bottom: 28px;
  font-family: 'Tajawal', sans-serif;
}

.modern-alert-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modern-alert-btn {
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-family: 'Tajawal', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 15px;
  flex: 1;
}

.modern-alert-btn-confirm {
  background: #1967d2;
  color: #ffffff;
}

.modern-alert-btn-confirm:hover {
  background: #1557b0;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(25, 103, 210, 0.25);
}

.modern-alert-btn-cancel {
  background: #f1f5f9;
  color: #64748b;
}

.modern-alert-btn-cancel:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.modern-alert-overlay[data-type="danger"] .modern-alert-icon {
  background: #fee2e2;
  color: #ef4444;
}

.modern-alert-overlay[data-type="danger"] .modern-alert-btn-confirm {
  background: #ef4444;
}

.modern-alert-overlay[data-type="danger"] .modern-alert-btn-confirm:hover {
  background: #dc2626;
}

.modern-alert-overlay[data-type="warning"] .modern-alert-icon {
  background: #fefce8;
  color: #ca8a04;
}

.modern-alert-overlay[data-type="warning"] .modern-alert-btn-confirm {
  background: #ca8a04;
}

.modern-alert-overlay[data-type="warning"] .modern-alert-btn-confirm:hover {
  background: #a16207;
}