/* ─── THEME: DARK (default) ─── */
:root,
[data-theme="dark"] {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --input-bg: rgba(255, 255, 255, 0.05);
  --input-bg-modal: rgba(255, 255, 255, 0.06);
  --bg-header: rgba(15, 23, 42, 0.92);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* ─── THEME: BLACK (Charcoal / Graphite) ─── */
[data-theme="black"] {
  --bg-app: #141414;
  --bg-card: #1c1c1e;
  --bg-sidebar: #111111;
  --bg-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);

  --text-primary: #f0f0f0;
  --text-secondary: #a0a8b8;
  --text-muted: #5a6478;
  --input-bg: rgba(255, 255, 255, 0.07);
  --input-bg-modal: rgba(255, 255, 255, 0.08);
  --bg-header: rgba(20, 20, 20, 0.97);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}

/* ─── THEME: LIGHT ─── */
[data-theme="light"] {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #6366f1;
  --accent: #0891b2;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;

  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: rgba(79, 70, 229, 0.06);
  --border: rgba(0, 0, 0, 0.08);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --input-bg: #f8fafc;
  --input-bg-modal: #f8fafc;
  --bg-header: rgba(255, 255, 255, 0.92);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.12);
}

/* Shared layout / sizing vars */
:root {
  --sidebar-w: 260px;
  --header-h: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.25s ease;
}

/* Smooth theme transition */
body,
.sidebar,
.main-header,
.card,
.modal,
.stat-card,
.toast {
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

/* ─── SCROLLBAR ─────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 99px;
}

/* ─── LOGIN PAGE ────────────────────── */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 20%, #1e1b4b 0%, #0f172a 70%);
  position: relative;
  overflow: hidden;
}

.login-wrapper::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, .15) 0%, transparent 70%);
  top: -100px;
  right: -100px;
  border-radius: 50%;
}

.login-card {
  background: rgba(30, 41, 59, .85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .brand-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 12px;
  box-shadow: 0 8px 32px rgba(79, 70, 229, .4);
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.login-logo p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-wrap {
  position: relative;
}

.input-wrap i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
  width: 16px;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}

.input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 46px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}

.input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(79, 70, 229, .08);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  width: 100%;
  justify-content: center;
  padding: 13px;
  font-size: 15px;
  box-shadow: 0 4px 15px rgba(79, 70, 229, .35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(79, 70, 229, .5);
}

.btn-primary:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-info {
  background: var(--info);
  color: #fff;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-secondary {
  background: rgba(255, 255, 255, .08);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, .14);
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.alert-error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-info {
  background: rgba(59, 130, 246, .12);
  border: 1px solid rgba(59, 130, 246, .3);
  color: #93c5fd;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── LAYOUT ─────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease, width 0.3s ease;
  overflow: hidden;
}

.sidebar-closed .sidebar {
    width: 64px !important;
}

.sidebar-brand {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-brand span {
  font-weight: 700;
  font-size: 16px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 20px 4px;
  margin-top: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 8px;
  margin: 2px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 400;
  transition: var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(79, 70, 229, .2);
  color: var(--primary-light);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  height: 60%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}

.nav-item i.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 14px;
}

.nav-item .nav-arrow {
  margin-left: auto;
  font-size: 11px;
  transition: transform 0.2s;
}

.nav-item.expanded .nav-arrow {
  transform: rotate(90deg);
}

.nav-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.nav-children.open {
  max-height: 500px;
}

.nav-child-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 8px 44px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: 6px;
  margin: 1px 8px;
  transition: var(--transition);
}

.nav-child-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.nav-child-item.active {
  color: var(--primary-light);
  background: rgba(79, 70, 229, .1);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-user:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-info .user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-info .user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-user i.logout-icon {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 13px;
}

/* HEADER */
.main-header {
  height: var(--header-h);
  background: var(--bg-header);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  z-index: 90;
  transition: left 0.3s ease;
}

.sidebar-closed .main-header {
    left: 64px;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.header-breadcrumb {
  color: var(--text-muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn {
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}

.header-btn:hover {
  background: rgba(255, 255, 255, .12);
  color: var(--text-primary);
}

/* MAIN CONTENT */
.main-content {
  margin-left: var(--sidebar-w);
  padding-top: var(--header-h);
  min-height: 100vh;
  flex: 1;
}

.page-container {
  padding: 28px;
}

/* ─── CARDS ──────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title i {
  color: var(--primary-light);
}

/* ─── STATS GRID ─────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: rgba(79, 70, 229, .15);
  color: var(--primary-light);
}

.stat-icon.cyan {
  background: rgba(6, 182, 212, .15);
  color: var(--accent);
}

.stat-icon.green {
  background: rgba(16, 185, 129, .15);
  color: var(--success);
}

.stat-icon.amber {
  background: rgba(245, 158, 11, .15);
  color: var(--warning);
}

.stat-icon.red {
  background: rgba(239, 68, 68, .15);
  color: var(--danger);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

/* ─── TABLE ──────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(255, 255, 255, .03);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ─── BADGES ─────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.badge-blue {
  background: rgba(79, 70, 229, .15);
  color: #a5b4fc;
}

.badge-cyan {
  background: rgba(6, 182, 212, .15);
  color: #67e8f9;
}

.badge-green {
  background: rgba(16, 185, 129, .15);
  color: #6ee7b7;
}

.badge-amber {
  background: rgba(245, 158, 11, .15);
  color: #fcd34d;
}

.badge-red {
  background: rgba(239, 68, 68, .15);
  color: #fca5a5;
}

.badge-purple {
  background: rgba(139, 92, 246, .15);
  color: #c4b5fd;
}

.badge-gray {
  background: rgba(100, 116, 139, .15);
  color: #94a3b8;
}

.badge-orange {
  background: rgba(249, 115, 22, .15);
  color: #fdba74;
}

.badge-dark {
  background: rgba(15, 23, 42, .4);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ─── IMAGE PLACEHOLDERS ─────────────── */
.no-image-placeholder {
  width: 32px;
  height: 32px;
  background: var(--input-bg);
  border: 1px dashed var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 8px;
  text-transform: uppercase;
  font-weight: 700;
  text-align: center;
  line-height: normal;
  user-select: none;
}

.no-image-placeholder::after {
  content: 'NO IMAGE';
}

.no-image-placeholder.lg {
  width: 120px;
  height: 120px;
  font-size: 12px;
  border-radius: 16px;
}

/* ─── MODAL ──────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
}

.modal-wide {
  max-width: 900px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, .06);
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-family: inherit;
}

.modal-close:hover {
  background: rgba(255, 255, 255, .12);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* FORM INSIDE MODAL */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  transition: var(--transition);
}

/* Correct override: .form-group wraps .input-wrap which contains input.
   !important ensures this always beats the generic .form-group input rule */
.form-group .input-wrap input {
  padding-left: 46px !important;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(79, 70, 229, .08);
}

.form-group select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ─── LIGHT THEME OVERRIDES ─── */
[data-theme="light"] .login-wrapper {
  background: radial-gradient(ellipse at 60% 20%, #ddd6fe 0%, #f1f5f9 70%);
}

[data-theme="light"] .login-card {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .sidebar {
  border-right-color: rgba(0, 0, 0, 0.08);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .main-header {
  background: rgba(255, 255, 255, 0.92);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .nav-item:hover {
  background: rgba(79, 70, 229, 0.08);
}

[data-theme="light"] .stat-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.12);
}

[data-theme="light"] thead th {
  background: #f8fafc;
}

[data-theme="light"] tbody tr:hover {
  background: rgba(79, 70, 229, 0.04);
}

[data-theme="light"] .toast {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .search-bar input {
  background: #fff;
}

[data-theme="light"] .header-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
  color: #475569;
}

[data-theme="light"] .header-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #0f172a;
}

/* ─── PERMISSION MATRIX ──────────────── */
.perm-table-wrap {
  overflow-x: auto;
}

.perm-table {
  width: 100%;
  border-collapse: collapse;
}

.perm-table thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

.perm-table thead th:first-child {
  text-align: left;
  min-width: 160px;
}

.perm-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  text-align: center;
}

.perm-table tbody td:first-child {
  text-align: left;
}

.perm-table tbody tr:hover {
  background: rgba(255, 255, 255, .03);
}

.perm-table tbody tr.child {
  background: rgba(255, 255, 255, .015);
}

.perm-table td .child-label {
  padding-left: 20px;
  color: var(--text-secondary);
  font-size: 13px;
}

.perm-table td .parent-label {
  font-weight: 600;
  font-size: 13px;
}

/* Checkbox styling */
.perm-check {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.perm-group-header {
  padding: 6px 12px;
  background: rgba(79, 70, 229, .08);
  border-bottom: 1px solid var(--border);
}

.perm-group-header td {
  font-weight: 600;
  font-size: 12px;
  color: var(--primary-light);
  letter-spacing: .04em;
}

/* ─── SEARCH BAR ─────────────────────── */
.search-bar {
  position: relative;
}

.search-bar i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-bar input {
  padding: 9px 14px 9px 36px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  width: 240px;
  font-family: inherit;
  transition: var(--transition);
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  width: 280px;
}

/* ─── LOADING ─────────────────────────── */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, .1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

.loading-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  flex-direction: column;
  gap: 12px;
  color: var(--text-muted);
}

/* ─── EMPTY STATE ────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: .4;
}

.empty-state p {
  font-size: 14px;
}

/* ─── ROLE BADGE COLORS ──────────────── */
.role-1 {
  background: rgba(239, 68, 68, .15);
  color: #fca5a5;
}

/* admin */
.role-2 {
  background: rgba(245, 158, 11, .15);
  color: #fcd34d;
}

/* pendiri */
.role-3 {
  background: rgba(139, 92, 246, .15);
  color: #c4b5fd;
}

/* pembina */
.role-4 {
  background: rgba(6, 182, 212, .15);
  color: #67e8f9;
}

/* ketua */
.role-5 {
  background: rgba(16, 185, 129, .15);
  color: #6ee7b7;
}

/* pengurus pusat */
.role-6 {
  background: rgba(59, 130, 246, .15);
  color: #93c5fd;
}

/* pengurus cabang */
.role-7 {
  background: rgba(20, 184, 166, .15);
  color: #5eead4;
}

/* cabang */
.role-8 {
  background: rgba(100, 116, 139, .15);
  color: #94a3b8;
}

/* member */
.role-9 {
  background: rgba(71, 85, 105, .15);
  color: #64748b;
}

/* calon member */

/* ─── ACTIONS ROW ─────────────────────── */
.action-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ─── TOAST ──────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  box-shadow: var(--shadow-lg);
  animation: slideLeft .3s ease;
  font-size: 13.5px;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--info);
}

.toast i {
  font-size: 16px;
}

.toast.success i {
  color: var(--success);
}

.toast.error i {
  color: var(--danger);
}

.toast.info i {
  color: var(--info);
}

/* ─── KEYFRAMES ──────────────────────── */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideLeft {
  from {
    transform: translateX(30px);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ─── RESPONSIVE ─────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.3);
    z-index: 1000 !important;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .main-header {
    left: 0 !important;
    padding: 0 16px;
  }

  .header-actions .theme-btn span {
    display: none;
  }

  .main-content {
    margin-left: 0 !important;
    padding-top: var(--header-h);
  }

  .page-container {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-card {
    padding: 12px;
    gap: 10px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .stat-value {
    font-size: 18px;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .modal {
    width: 95%;
    max-height: 85vh;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }

  /* Overlay sidebar mobile */
  .sidebar-mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
  }

  .sidebar-open .sidebar-mobile-overlay {
    opacity: 1;
    visibility: visible;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .card-header .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .search-bar input {
    width: 100%;
  }

  .grid-2-1, .grid-3-1, .grid-4-1 {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
  
  .membership-stats-grid { 
    grid-template-columns: 1fr !important;
  }

  .mobile-stack {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

/* ─── UTILITIES ─────────────────────── */
.grid-2-1 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  .grid-2-1 {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

.stack-on-mobile {
    display: flex;
    gap: 12px;
    align-items: center;
}

@media (max-width: 768px) {
    .stack-on-mobile {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .stack-on-mobile > div, 
    .stack-on-mobile > .export-buttons {
        width: 100% !important;
        justify-content: space-between;
    }
}

.responsive-modal-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 24px;
}

@media (max-width: 768px) {
    .responsive-modal-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
}

.chart-container {
    height: 300px;
    position: relative;
    width: 100%;
    overflow: hidden;
}

@media (max-width: 576px) {
    .chart-container {
        height: 250px;
    }
}

/* --- PRINT STYLES --- */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  .sidebar,
  .main-header,
  .export-buttons,
  .column-picker-container,
  .search-bar,
  .modal-overlay,
  .pagination,
  .page-header-desc,
  .btn,
  .action-row,
  .card-header .card-title,
  .card-header,
  h2:not(.print-only-header h2),
  p:not(.print-only-header p) {
    display: none !important;
  }

  body,
  .main-content,
  .card,
  .table-wrap {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    border: none !important;
    overflow: visible !important;
  }

  .main-content {
    margin-left: 0 !important;
    padding-top: 0 !important;
  }

  table {
    border-collapse: collapse;
    width: 100%;
    font-size: 9pt;
  }

  th, td {
    border: 1px solid #000;
    padding: 4px 6px;
    color: black !important;
    vertical-align: middle;
  }

  th {
    background: #f3f3f3 !important;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
  }

  .print-only-header,
  .print-only-footer {
    display: block !important;
  }

  .print-only-header {
    margin-bottom: 16px;
    text-align: center;
    border-bottom: 2px solid #000;
    padding-bottom: 10px;
  }

  .print-only-header h2 {
    font-size: 16pt !important;
    margin: 0;
    font-weight: bold;
    text-transform: uppercase;
    color: black !important;
    display: block !important;
  }

  .print-only-header p {
    font-size: 10pt !important;
    margin: 4px 0 0;
    color: #444 !important;
    display: block !important;
  }

  tr {
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }
}

/* ─── TOGGLE SWITCH ─────────────────── */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

/* ─── TOGGLE SWITCH ─────────────────── */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .4s;
  border: 1px solid var(--border);
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
}

input:checked+.slider {
  background-color: var(--success);
  border-color: var(--success);
}

input:focus+.slider {
  box-shadow: 0 0 1px var(--success);
}

input:checked+.slider:before {
  transform: translateX(18px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

[data-theme="light"] .slider {
  background-color: #e2e8f0;
}

/* Agenda Terdekat Highlight */
.nearest-agenda-row {
    animation: flashRow 3s infinite;
}
.nearest-agenda-row td:first-child {
    border-left: 4px solid var(--primary);
}
@keyframes flashRow {
    0% { background-color: rgba(79, 70, 229, 0.05); }
    50% { background-color: rgba(79, 70, 229, 0.15); }
    100% { background-color: rgba(79, 70, 229, 0.05); }
}