/* ==========================================================================
   Enterprise SaaS ERP - Design System
   Modern, professional, enterprise-grade UI
   ========================================================================== */

/* CSS Variables - Design Tokens */
:root {
  /* Brand Colors - Indigo/Cyan (Premium Dark Mode) */
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-light: rgba(99, 102, 241, 0.15);
  --primary-dark: #4338ca;

  /* Accent */
  --accent: #06b6d4;
  --accent-hover: #22d3ee;

  /* Semantic Colors */
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --info: #3b82f6;
  --info-light: rgba(59, 130, 246, 0.15);

  /* Neutral Palette (Dark Mode) */
  --gray-50: #020617;
  --gray-100: #0f172a;
  --gray-200: #1e293b;
  --gray-300: #334155;
  --gray-400: #475569;
  --gray-500: #64748b;
  --gray-600: #94a3b8;
  --gray-700: #cbd5e1;
  --gray-800: #e2e8f0;
  --gray-900: #f1f5f9;
  --gray-950: #f8fafc;

  /* Backgrounds (Glassmorphism & Dark) */
  --bg-body: #050510; /* Deep dark background */
  --bg-card: rgba(15, 23, 42, 0.6); /* Translucent cards */
  --bg-sidebar: rgba(10, 15, 30, 0.7); /* Glass sidebar */
  --bg-sidebar-hover: rgba(255, 255, 255, 0.05);
  --bg-sidebar-active: var(--primary-light);

  /* Text */
  --text-primary: #f8fafc; /* Light text for dark mode */
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-on-dark: #ffffff;
  --text-on-primary: #ffffff;

  /* Borders */
  --border-color: rgba(255, 255, 255, 0.1);
  --border-color-dark: rgba(255, 255, 255, 0.05);

  /* Soft Light Shadows & Glows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  --glow-primary: 0 0 20px rgba(99, 102, 241, 0.4);
  --glow-accent: 0 0 20px rgba(6, 182, 212, 0.4);

  /* Glassmorphism utility filters */
  --glass-blur: blur(16px);
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Layout */
  --sidebar-width: 264px;
  --sidebar-collapsed: 72px;
  --header-height: 64px;
  --transition: all 0.2s ease;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-hover); }

/* Card Header — flex layout for heading + action buttons */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-color);
}
.card-header h3, .card-header h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}
.card-header .btn {
  flex-shrink: 0;
}

/* ============== Layout ============== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ============== Sidebar ============== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-primary);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: var(--transition);
  overflow-y: auto;
  border-right: var(--glass-border);
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color-dark);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  font-size: 28px;
  line-height: 1;
}

.sidebar-brand {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
}

.sidebar-brand .brand-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-400);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-section-title {
  padding: 8px 24px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 4px;
}

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

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  border-left-color: var(--primary);
  transform: translateX(4px);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary-hover);
  border-left-color: var(--primary);
}

.sidebar-link .icon {
  font-size: 17px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link .badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: transparent;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: var(--transition);
  cursor: pointer;
}

.sidebar-user:hover { background: var(--bg-sidebar-hover); }

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px;
  color: var(--gray-400);
  text-transform: capitalize;
}

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

/* ============== Top Header ============== */
.top-header {
  height: var(--header-height);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: var(--glass-border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-title {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.header-title h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-title .breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-title .breadcrumb a { color: var(--text-muted); }
.header-title .breadcrumb a:hover { color: var(--primary); }

.header-search {
  position: relative;
  width: 320px;
}

.header-search input {
  width: 100%;
  padding: 8px 12px 8px 38px;
  background: var(--gray-100);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  transition: var(--transition);
}

.header-search input:focus {
  outline: none;
  background: var(--bg-card);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.header-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

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

.header-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 16px;
  position: relative;
  transition: var(--transition);
}

.header-icon-btn:hover {
  background: var(--gray-100);
  color: var(--text-primary);
}

.header-icon-btn .notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: var(--radius-full);
  border: 2px solid white;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.header-user:hover { background: var(--gray-100); }

.header-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
}

.header-user-info { display: flex; flex-direction: column; }
.header-user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.header-user-role { font-size: 11px; color: var(--text-muted); }

/* ============== Page Container ============== */
.page-container {
  padding: 32px;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ============== Page Header ============== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

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

/* ============== Buttons ============== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-hover), var(--primary)); color: white; box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover { background: var(--bg-body); border-color: var(--gray-300); color: var(--text-primary); }

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--gray-100); color: var(--text-primary); box-shadow: none; transform: none; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 20px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }

/* ============== Cards ============== */
.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-header .header-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  background: var(--bg-body);
  border-top: 1px solid var(--border-color);
}

/* ============== Stat Cards / KPIs ============== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

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

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  background: var(--stat-color, var(--primary));
}

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

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: var(--icon-bg, var(--primary-light));
  color: var(--icon-color, var(--primary));
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.stat-change.up { background: var(--success-light); color: var(--success); }
.stat-change.down { background: var(--danger-light); color: var(--danger); }
.stat-change.neutral { background: var(--gray-100); color: var(--text-secondary); }

/* ============== Tables ============== */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-card);
}

table.data-table thead {
  background: var(--bg-body);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

table.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

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

table.data-table tbody tr {
  transition: var(--transition);
  border-left: 3px solid transparent;
}

table.data-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

table.data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
  border-left-color: var(--primary);
}

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

.table-cell-primary {
  font-weight: 600;
  color: var(--text-primary);
}

.table-cell-secondary {
  color: var(--text-secondary);
  font-size: 12px;
}

.table-cell-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ============== Badges & Pills ============== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-success { background: var(--success-light); color: #065f46; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-info { background: var(--info-light); color: #1e40af; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-secondary { background: var(--gray-100); color: var(--text-secondary); }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

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

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

.form-label .required { color: var(--danger); }

.form-control, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.form-control:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

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

/* ============== Filter Bar ============== */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.filter-bar .form-control,
.filter-bar .form-select {
  width: auto;
  min-width: 160px;
}

.filter-bar .search-input {
  flex: 1;
  min-width: 200px;
}

/* ============== Grid System ============== */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-main-side {
  grid-template-columns: 1fr 320px;
}
.grid-side-main {
  grid-template-columns: 320px 1fr;
}

@media (max-width: 1100px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-main-side, .grid-side-main { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============== Progress Bars ============== */
.progress {
  width: 100%;
  height: 8px;
  background: var(--gray-100);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ============== Avatars ============== */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--gray-200);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: 13px; }
.avatar-lg { width: 56px; height: 56px; font-size: 24px; }
.avatar-xl { width: 80px; height: 80px; font-size: 36px; }

.avatar-group {
  display: inline-flex;
}

.avatar-group .avatar {
  margin-right: -10px;
  border: 2px solid white;
}

/* ============== Charts (pure CSS) ============== */
.chart-container {
  position: relative;
  height: 240px;
  width: 100%;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100%;
  padding: 12px 0;
}

.bar-chart .bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.bar-chart .bar-stack {
  display: flex;
  flex-direction: column-reverse;
  width: 100%;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.bar-chart .bar {
  width: 60%;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
  transition: var(--transition);
  min-height: 4px;
  position: relative;
}

.bar-chart .bar.bar-secondary {
  background: var(--accent);
  opacity: 0.7;
}

.bar-chart .bar:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.bar-chart .bar-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.donut-chart {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0 auto;
}

.donut-chart::after {
  content: '';
  position: absolute;
  inset: 30px;
  background: var(--bg-card);
  border-radius: 50%;
}

.donut-chart .donut-center {
  position: relative;
  z-index: 1;
  text-align: center;
}

.donut-chart .donut-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.donut-chart .donut-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.line-chart {
  height: 200px;
  position: relative;
  padding: 12px 0;
}

.line-chart svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ============== Login Page ============== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(-45deg, #0f0c29, #302b63, #24243e, #06b6d4);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-page::before, .login-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
}

.login-page::before {
  width: 500px;
  height: 500px;
  top: -150px;
  right: -100px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.6), transparent 70%);
  animation: floatOrb1 8s ease-in-out infinite;
}

.login-page::after {
  width: 400px;
  height: 400px;
  bottom: -100px;
  left: -100px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.5), transparent 70%);
  animation: floatOrb2 10s ease-in-out infinite;
}

@keyframes floatOrb1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-40px, 30px) scale(1.1); }
}

@keyframes floatOrb2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -40px) scale(1.15); }
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 440px;
  padding: 40px;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.login-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-form .form-group { margin-bottom: 20px; }

.login-info {
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 24px;
  font-size: 12px;
  color: var(--primary-dark);
}

.login-info strong { display: block; margin-bottom: 6px; }
.login-info code {
  background: var(--bg-card);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ============== Alert Messages ============== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #6ee7b7; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fcd34d; }
.alert-info { background: var(--info-light); color: #1e40af; border: 1px solid #93c5fd; }

/* ============== Empty State ============== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

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

.empty-state p { font-size: 13px; max-width: 320px; margin: 0 auto; }

/* ============== Tabs ============== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============== Page Sections ============== */
section.page-section { margin-bottom: 24px; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============== Misc ============== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-sm { font-size: 12px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }

.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.w-full { width: 100%; }
.hidden { display: none; }

/* ============== Mobile ============== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .header-search { display: none; }
}

@media (max-width: 768px) {
  .page-container { padding: 16px; }
  .top-header { padding: 0 16px; }
  .stat-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ============== Print ============== */
@media print {
  .sidebar, .top-header, .page-header-actions { display: none; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ============== Animations ============== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease-out; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.pulse { animation: pulse 2s infinite; }

/* ============== Custom Scrollbar (page) ============== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ==========================================================================
   DARK MODE
   ========================================================================== */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-light: #312e81;
  --primary-dark: #c7d2fe;

  --accent: #22d3ee;
  --accent-hover: #06b6d4;

  --success: #34d399;
  --success-light: #064e3b;
  --warning: #fbbf24;
  --warning-light: #78350f;
  --danger: #f87171;
  --danger-light: #7f1d1d;
  --info: #60a5fa;
  --info-light: #1e3a5f;

  --gray-50: #111827;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-300: #4b5563;
  --gray-400: #6b7280;
  --gray-500: #9ca3af;
  --gray-600: #d1d5db;
  --gray-700: #e5e7eb;
  --gray-800: #f3f4f6;
  --gray-900: #f9fafb;
  --gray-950: #ffffff;

  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #020617;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #4f46e5;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --text-on-dark: #f8fafc;
  --text-on-primary: #ffffff;

  --border-color: #334155;
  --border-color-dark: #1e293b;

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .top-header {
  background: var(--bg-card);
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .header-search input {
  background: var(--gray-100);
  color: var(--text-primary);
}

[data-theme="dark"] .filter-bar {
  background: var(--bg-card);
  border-color: var(--border-color);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea {
  background: var(--gray-100);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .form-textarea:focus {
  background: var(--gray-200);
  border-color: var(--primary);
}

[data-theme="dark"] .btn-secondary {
  background: var(--gray-100);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .btn-secondary:hover {
  background: var(--gray-200);
}

[data-theme="dark"] .btn-ghost:hover {
  background: var(--gray-100);
}

[data-theme="dark"] .card-header {
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .card-footer {
  background: var(--bg-body);
  border-top-color: var(--border-color);
}

[data-theme="dark"] table.data-table td {
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] table.data-table tbody tr:hover {
  background: var(--gray-100);
}

[data-theme="dark"] table.data-table thead {
  background: var(--bg-body);
}

[data-theme="dark"] .alert {
  border-color: var(--border-color);
}

[data-theme="dark"] .donut-chart::after {
  background: var(--bg-card);
}

[data-theme="dark"] pre {
  background: var(--gray-100);
  color: var(--text-primary);
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--gray-100);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--gray-300);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* Dark mode toggle button */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 18px;
  transition: var(--transition);
}

.theme-toggle:hover {
  background: var(--gray-100);
  color: var(--text-primary);
}

/* ==========================================================================
   PRINT STYLES - For invoices, reports, statements
   ========================================================================== */
@media print {
    .sidebar, .top-header, .page-header-actions, .card-footer,
    .filter-bar, .btn, .header-actions, .theme-toggle, .sidebar-footer,
    .notification-dot, #searchSuggestions, .header-search {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .page-container {
        padding: 0 !important;
        max-width: 100% !important;
    }

    body {
        background: white !important;
        color: black !important;
        font-size: 11px !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        page-break-inside: avoid;
    }

    .stat-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }

    table.data-table {
        font-size: 10px !important;
    }

    table.data-table th {
        background: #f0f0f0 !important;
        color: black !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    a {
        text-decoration: none !important;
        color: black !important;
    }

    .text-success, .text-danger, .text-warning, .text-primary {
        color: black !important;
    }

    .badge {
        border: 1px solid #999 !important;
        background: white !important;
        color: black !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .grid-2, .grid-3, .grid-4 {
        display: block !important;
    }

    .grid-2 > *, .grid-3 > *, .grid-4 > * {
        margin-bottom: 10px !important;
    }
}

.print-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    cursor: pointer;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
}

.print-button:hover {
    background: var(--bg-body);
    border-color: var(--gray-300);
}

@media screen {
    .print-only {
        display: none;
    }
}

/* ==========================================================================
   MOBILE IMPROVEMENTS
   ========================================================================== */
.mobile-only {
    display: none;
}

@media (max-width: 1024px) {
    .mobile-only {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: var(--shadow-xl);
    }

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

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

    .header-search {
        display: none;
    }

    .header-user-info {
        display: none;
    }

    .page-container {
        padding: 16px;
    }

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

@media (max-width: 768px) {
    .stat-grid {
        grid-template-columns: 1fr !important;
    }

    .grid-2, .grid-3, .grid-4,
    .grid-main-side, .grid-side-main {
        grid-template-columns: 1fr !important;
    }

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

    .page-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .page-header-actions .btn {
        flex: 1;
        min-width: 120px;
    }

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

    .filter-bar .form-control,
    .filter-bar .form-select {
        width: 100% !important;
        min-width: 0 !important;
    }

    table.data-table {
        font-size: 12px;
    }

    table.data-table th,
    table.data-table td {
        padding: 8px 10px;
    }

    .stat-value {
        font-size: 22px;
    }

    .card-body {
        padding: 14px;
    }

    .hide-mobile {
        display: none !important;
    }
}

/* Backdrop for mobile sidebar */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
}

@media (max-width: 1024px) {
    .sidebar.open + .sidebar-backdrop {
        display: block;
    }
}

/* ==========================================================================
   IMPROVED SIDEBAR - Collapsible sections, search filter, collapse toggle
   ========================================================================== */
.sidebar-collapse-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--text-on-dark);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: var(--transition);
  margin-left: auto;
}

.sidebar-collapse-btn:hover {
  background: rgba(255,255,255,0.2);
}

.sidebar-section-title {
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  text-transform: uppercase;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.sidebar-section-title:hover {
  color: var(--gray-300);
}

.sidebar-section-title .section-chevron {
  font-size: 12px;
  transition: transform 0.2s;
  opacity: 0.6;
}

.sidebar-section.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-section-content {
  display: none;
}

.sidebar-section-content {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

/* Sub-links (indented children) */
.sidebar-link.sub-link {
  padding-left: 48px;
  font-size: 12.5px;
  opacity: 0.85;
}

.sidebar-link.sub-link:hover {
  opacity: 1;
}

/* Collapsed sidebar state */
.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .link-text,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .section-chevron,
.sidebar.collapsed .badge {
  display: none;
}

.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .sidebar-link .icon {
  font-size: 20px;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar.collapsed .sidebar-collapse-btn {
  margin-left: 0;
}

.main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}

/* Module search filter results */
.sidebar-link.filtered-out {
  display: none;
}

.sidebar-section.all-filtered-out {
  display: none;
}

/* Dark mode sidebar adjustments */
[data-theme="dark"] .sidebar-search input {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.05);
}

[data-theme="dark"] .sidebar-collapse-btn {
  background: rgba(255,255,255,0.05);
}

/* Notification Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 18px;
    border-radius: 10px;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    animation: slideInRight 0.3s ease;
    cursor: pointer;
    transition: var(--transition);
}

.toast:hover {
    transform: translateX(-4px);
}

.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }

.toast-icon { font-size: 20px; flex-shrink: 0; }
.toast-content { flex: 1; }
.toast-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.toast-message { font-size: 12px; color: var(--text-secondary); }

@keyframes slideInRight {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(400px); opacity: 0; }
}

.toast.removing { animation: slideOutRight 0.3s ease forwards; }

/* ==========================================================================
   UI IMPROVEMENTS: Loading, Empty States, Responsive, Forms, Charts
   ========================================================================== */

/* --- Loading Indicator --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline loading (for buttons + sections) */
.btn-loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}
.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-card { height: 120px; }

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}
.empty-state .empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.empty-state .empty-description {
    font-size: 14px;
    margin-bottom: 24px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}
.empty-state .empty-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
}
.empty-state .empty-cta:hover {
    background: var(--primary-dark, #4338ca);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* --- Form Improvements --- */
.form-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 32px;
    box-shadow: var(--shadow-sm);
    max-width: 800px;
    margin: 0 auto;
}
.form-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-label .required { color: var(--danger); }
.form-control, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 14px;
    transition: var(--transition);
    background: var(--bg-card);
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-control:invalid:not(:placeholder-shown) {
    border-color: var(--danger);
}
.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.form-error {
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
    display: none;
}
.form-control:invalid:not(:placeholder-shown) + .form-error { display: block; }
.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-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

/* --- Responsive Design --- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .header-search { display: none; }
    .mobile-only { display: block !important; }
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .grid-main-side { grid-template-columns: 1fr !important; }
    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .page-header-actions { width: 100%; }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px; }
}

@media (max-width: 640px) {
    .stat-grid { grid-template-columns: 1fr !important; }
    .card { padding: 12px; }
    .card-body { padding: 12px; }
    .btn { padding: 8px 14px; font-size: 13px; }
    .form-card { padding: 16px; }
    .header-actions { gap: 4px; }
    .header-icon-btn { width: 32px; height: 32px; font-size: 14px; }
    .header-user-info { display: none; }
    h2 { font-size: 18px; }
}

/* --- Chart Improvements --- */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
    margin: 16px 0;
}
.chart-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}
.chart-card .chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.chart-card .chart-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.chart-card .chart-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}
.chart-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.chart-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* KPI card with trend */
.stat-card .stat-trend {
    font-size: 11px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 2px;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-100);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Badge improvements */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: var(--gray-100); color: var(--text-secondary); }

/* Table improvements */
.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-body);
}
.data-table td {
    padding: 12px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}
.data-table tbody tr {
    transition: var(--transition);
}
.data-table tbody tr:hover {
    background: var(--bg-body);
}
.table-cell-primary {
    font-weight: 600;
    color: var(--text-primary);
}
.table-actions {
    display: flex;
    gap: 8px;
}
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
}

/* Card improvements */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.card-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h3 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
}
.card-body { padding: 24px; }
.card-footer {
    padding: 12px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-body);
}

/* Stat grid */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.stat-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 4px;
}
.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: var(--bg-body);
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h2 {
    font-size: 22px;
    font-weight: 800;
    margin: 0;
}
.page-header .subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}
.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Button improvements */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: #4338ca;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-secondary {
    background: var(--gray-100);
    color: var(--text-secondary);
}
.btn-secondary:hover {
    background: var(--gray-200);
}
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-success {
    background: var(--success);
    color: white;
}
.btn-warning {
    background: var(--warning);
    color: white;
}

/* Grid layout */
.grid-main-side {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* Alert improvements */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

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

/* Tooltip */
[data-tooltip] {
    position: relative;
    cursor: help;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ============================================================
   PWA OFFLINE INDICATOR (Sprint 14)
   ============================================================ */
body.offline::before {
    content: "📡 You are offline — showing cached data";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: white;
    text-align: center;
    padding: 6px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
body.offline {
    padding-top: 32px;
}

/* Fix for form elements inside page-header-actions breaking the flex gap */
.page-header-actions form {
  display: contents;
}

/* ============================================================
   PHASE 6: UI POLISH — Toast Notifications
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 500;
  min-width: 320px;
  max-width: 480px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast.toast-exit {
  animation: toastSlideOut 0.3s ease forwards;
}

.toast-success {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border-left: 4px solid var(--success);
}
.toast-error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-left: 4px solid var(--danger);
}
.toast-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border-left: 4px solid var(--warning);
}
.toast-info {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border-left: 4px solid var(--info);
}

.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-message { flex: 1; }
.toast-close {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  transition: opacity 0.2s;
}
.toast-close:hover { opacity: 1; }

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  animation: toastProgress 4s linear forwards;
}
.toast-success .toast-progress { background: var(--success); }
.toast-error .toast-progress { background: var(--danger); }
.toast-warning .toast-progress { background: var(--warning); }
.toast-info .toast-progress { background: var(--info); }

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toastSlideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(120%); opacity: 0; }
}
@keyframes toastProgress {
  from { width: 100%; }
  to { width: 0%; }
}

/* ============================================================
   PHASE 6: Staggered Card / Row Animations
   ============================================================ */
.stat-card,
.card {
  animation: staggerFadeUp 0.5s ease backwards;
}
.stat-grid > :nth-child(1) { animation-delay: 0.05s; }
.stat-grid > :nth-child(2) { animation-delay: 0.1s; }
.stat-grid > :nth-child(3) { animation-delay: 0.15s; }
.stat-grid > :nth-child(4) { animation-delay: 0.2s; }
.stat-grid > :nth-child(5) { animation-delay: 0.25s; }
.stat-grid > :nth-child(6) { animation-delay: 0.3s; }

@keyframes staggerFadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Table row stagger */
table.data-table tbody tr {
  animation: rowFadeIn 0.3s ease backwards;
}
table.data-table tbody tr:nth-child(1) { animation-delay: 0.02s; }
table.data-table tbody tr:nth-child(2) { animation-delay: 0.04s; }
table.data-table tbody tr:nth-child(3) { animation-delay: 0.06s; }
table.data-table tbody tr:nth-child(4) { animation-delay: 0.08s; }
table.data-table tbody tr:nth-child(5) { animation-delay: 0.1s; }
table.data-table tbody tr:nth-child(6) { animation-delay: 0.12s; }
table.data-table tbody tr:nth-child(7) { animation-delay: 0.14s; }
table.data-table tbody tr:nth-child(8) { animation-delay: 0.16s; }
table.data-table tbody tr:nth-child(9) { animation-delay: 0.18s; }
table.data-table tbody tr:nth-child(10) { animation-delay: 0.2s; }

@keyframes rowFadeIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   PHASE 6: Sidebar Micro-Animations
   ============================================================ */
/* Active link pulse dot */
.sidebar-link.active::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  margin-left: auto;
  flex-shrink: 0;
  animation: activePulse 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

@keyframes activePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.7); }
}

/* Smoother section expand/collapse */
.sidebar-section-content {
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
  overflow: hidden;
}

.sidebar-section-content.collapsed {
  max-height: 0 !important;
  opacity: 0;
}

/* Section title hover */
.sidebar-section-title {
  cursor: pointer;
  transition: color 0.2s ease;
}
.sidebar-section-title:hover {
  color: var(--text-primary);
}

/* Chevron rotation */
.section-chevron {
  transition: transform 0.3s ease;
  display: inline-block;
}
.sidebar-section-title.collapsed .section-chevron {
  transform: rotate(-90deg);
}

/* ============================================================
   PHASE 6: Enhanced Empty State
   ============================================================ */
.empty-state .empty-icon {
  animation: emptyBounce 3s ease-in-out infinite;
}

@keyframes emptyBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ============================================================
   PHASE 6: Page Content Transition
   ============================================================ */
.page-container {
  animation: pageEnter 0.35s ease;
}

@keyframes pageEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   PHASE 6: Login Card Glassmorphism Enhancement
   ============================================================ */
.login-card {
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Password toggle */
.password-wrapper {
  position: relative;
}
.password-wrapper .form-control {
  padding-right: 42px;
}
.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  transition: color 0.2s;
}
.password-toggle:hover {
  color: var(--text-primary);
}

/* Submit button loading state */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}

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

/* ============================================================
   PHASE 6: Skeleton Loading Placeholder
   ============================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--gray-200) 25%,
    var(--gray-300) 50%,
    var(--gray-200) 75%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}
.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }
.skeleton-heading {
  height: 22px;
  width: 50%;
  margin-bottom: 16px;
}
.skeleton-card {
  height: 120px;
  border-radius: var(--radius-lg);
}

/* ============================================================
   Aesthetic Enhancements - Premium Enterprise Glassmorphism & Animations
   ============================================================ */
.glass-panel {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.75) 0%, rgba(15, 23, 42, 0.85) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-panel:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 16px 40px 0 rgba(0, 0, 0, 0.45), 0 0 24px rgba(99, 102, 241, 0.2);
}

.stat-card {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease, border-color 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 12px 28px -6px rgba(0, 0, 0, 0.5), 0 0 20px rgba(99, 102, 241, 0.25);
  border-color: var(--primary-light);
}

.pulse-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.pulse-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.hero-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(6, 182, 212, 0.2) 50%, rgba(15, 23, 42, 0.9) 100%);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  margin-bottom: 28px;
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.4), var(--glow-primary);
  position: relative;
  overflow: hidden;
}

.hero-banner::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.18) 0%, rgba(0,0,0,0) 70%);
  pointer-events: none;
}

/* ==========================================================================
   GAP-11.2: WCAG 2.1 AA Accessibility
   ========================================================================== */

/* Skip Navigation Link (screen-reader + keyboard users) */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 10000;
  padding: var(--space-3) var(--space-6);
  background: var(--primary);
  color: var(--text-on-primary);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: var(--space-4);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Focus indicators (WCAG 2.4.7 — Focus Visible) */
*:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Remove outline for mouse users, keep for keyboard */
*:focus:not(:focus-visible) {
  outline: none;
}

/* Minimum touch target size (WCAG 2.5.5 — 44x44px) */
button, .btn, a.nav-link, .sidebar-link, input[type="checkbox"],
input[type="radio"], select, .dropdown-item {
  min-height: 44px;
  min-width: 44px;
}

/* Ensure sufficient color contrast for links */
a { text-decoration-skip-ink: auto; }
a:hover, a:focus { text-decoration: underline; }

/* Screen reader only utility */
.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;
}

/* Reduced motion (WCAG 2.3.3 — Animation from Interactions) */
@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;
  }
}

/* High contrast mode support */
@media (forced-colors: active) {
  .btn, .card, .sidebar {
    border: 1px solid ButtonText;
  }
  .btn-primary {
    background: ButtonFace;
    color: ButtonText;
    border: 2px solid ButtonText;
  }
}

/* ==========================================================================
   GAP-11.1: Mobile-Responsive Breakpoints
   ========================================================================== */

/* Mobile sidebar toggle button (hidden on desktop) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 200;
  width: 44px;
  height: 44px;
  background: var(--bg-card);
  border: var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  transition: var(--transition);
}
.sidebar-toggle:hover {
  background: var(--primary-light);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* ---------- Tablet (max-width: 1024px) ---------- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px;
  }

  .main-content {
    margin-left: var(--sidebar-width);
    padding: var(--space-4);
  }

  /* Stack card grids to 2 columns */
  .stats-grid, .module-grid, .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-4);
  }

  /* Reduce padding on cards */
  .card, .stat-card, .glass-card {
    padding: var(--space-4);
  }

  .hero-banner {
    padding: 20px 24px;
  }

  /* Table horizontal scroll */
  .table-responsive, .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---------- Mobile Landscape (max-width: 768px) ---------- */
@media (max-width: 768px) {
  /* Show mobile toggle, hide sidebar */
  .sidebar-toggle {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 200;
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    margin-left: 0 !important;
    padding: var(--space-4);
    padding-top: 60px; /* space for toggle button */
    width: 100%;
  }

  /* Stack grids to single column */
  .stats-grid, .module-grid, .dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  /* Full-width cards */
  .card, .glass-card {
    border-radius: var(--radius-md);
  }

  /* Topbar adjustments */
  .topbar {
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .topbar-search {
    order: 3;
    width: 100%;
    margin-top: var(--space-2);
  }

  .topbar-search input {
    width: 100%;
  }

  /* Stack card headers on small screens */
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  /* Make tables scrollable */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Hero banner */
  .hero-banner {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
  }

  .hero-banner h1, .hero-banner h2 {
    font-size: 1.25rem;
  }

  /* Form layouts */
  .form-row, .form-group-row {
    flex-direction: column;
    gap: var(--space-3);
  }

  .form-row > *, .form-group-row > * {
    width: 100% !important;
    flex: none;
  }

  /* Modal full-screen on mobile */
  .modal-dialog, .modal-content {
    margin: 0;
    border-radius: 0;
    max-width: 100%;
    max-height: 100vh;
  }

  /* Tabs scroll horizontally */
  .nav-tabs, .tab-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar, .tab-nav::-webkit-scrollbar {
    display: none;
  }

  /* Action buttons stack */
  .btn-group, .action-buttons {
    flex-direction: column;
    width: 100%;
  }
  .btn-group .btn, .action-buttons .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ---------- Mobile Portrait (max-width: 480px) ---------- */
@media (max-width: 480px) {
  html {
    font-size: 13px;
  }

  .main-content {
    padding: var(--space-3);
    padding-top: 56px;
  }

  /* Compact stat cards */
  .stat-card {
    padding: var(--space-3);
  }
  .stat-card .stat-value {
    font-size: 1.5rem;
  }

  /* Hide non-essential columns */
  .hide-mobile, .desktop-only {
    display: none !important;
  }

  /* Compact buttons */
  .btn {
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
  }

  .btn-lg {
    padding: var(--space-3) var(--space-4);
    font-size: 0.9rem;
  }

  /* Cards edge-to-edge */
  .card, .glass-card {
    border-radius: var(--radius-sm);
    margin-left: calc(-1 * var(--space-3));
    margin-right: calc(-1 * var(--space-3));
  }

  /* Dropdown menus full width */
  .dropdown-menu {
    position: fixed !important;
    left: var(--space-3) !important;
    right: var(--space-3) !important;
    width: auto !important;
    max-height: 60vh;
    overflow-y: auto;
  }

  /* Breadcrumbs scroll */
  .breadcrumb {
    overflow-x: auto;
    flex-wrap: nowrap;
    white-space: nowrap;
  }
}

/* ---------- Print Styles ---------- */
@media print {
  .sidebar, .topbar, .sidebar-toggle, .sidebar-overlay,
  .btn, .action-buttons, .nav-tabs, .breadcrumb,
  .pagination, .modal, footer {
    display: none !important;
  }

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

  body {
    background: white;
    color: black;
    font-size: 12pt;
  }

  .card, .glass-card {
    background: white !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    page-break-inside: avoid;
  }

  table {
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #ccc;
    padding: 4px 8px;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}
