:root {
  --brand: #6E4FC9;
  --brand-dark: #5B3FB0;
  --brand-light: #F3EFFB;
  --brand-lighter: #FAF8FE;
  --ink: #1F2430;
  --ink-muted: #6B7280;
  --border: #E7E5F0;
  --bg: #F5F5FA;
  --surface: #FFFFFF;
  --danger: #E5484D;
  --success: #2FAE5C;
  --warning: #E8A83A;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 36, 48, 0.04), 0 4px 16px rgba(31, 36, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14.5px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* ---------- App shell / sidebar ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #241B3D 0%, #1B1430 100%);
  color: #E4DEF7;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1030;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  letter-spacing: 0.2px;
}

.sidebar-brand .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  color: #C7BFE6;
  font-weight: 500;
  font-size: 0.92rem;
  margin-bottom: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--brand);
  color: #fff;
}

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

.sidebar-footer .user-name {
  color: #fff;
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
}

.sidebar-footer a {
  color: #B8AEDD;
}
.sidebar-footer a:hover { color: #fff; }

.app-main {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-content {
  padding: 28px 32px 60px;
  max-width: 1400px;
  width: 100%;
}

.sidebar-toggle {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--ink);
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-topbar { display: flex; }
  .app-content { padding: 20px 16px 48px; }
}

/* ---------- Page heading ---------- */

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

.page-header h3 {
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0;
  color: var(--ink);
}

.page-header .text-muted-sub {
  color: var(--ink-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

/* ---------- Cards ---------- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.stat-card {
  border-radius: var(--radius);
  padding: 20px 22px;
  color: #fff;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card .stat-icon {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 2.1rem;
  opacity: 0.28;
}

.stat-card .stat-label {
  font-size: 0.82rem;
  opacity: 0.9;
  font-weight: 500;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 1.9rem;
  font-weight: 700;
}

.stat-card.stat-purple { background: linear-gradient(135deg, #7C5CDB, #5B3FB0); }
.stat-card.stat-amber  { background: linear-gradient(135deg, #F1B34E, #DB9421); }
.stat-card.stat-rose   { background: linear-gradient(135deg, #F0696D, #D63F45); }
.stat-card.stat-teal   { background: linear-gradient(135deg, #4FBFA8, #2E9683); }

/* ---------- Buttons ---------- */

.btn { border-radius: 8px; font-weight: 500; font-size: 0.88rem; }

.btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.btn-outline-secondary { color: var(--ink-muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--bg); color: var(--ink); border-color: var(--border); }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table { margin-bottom: 0; }

.table thead th {
  background: var(--brand-lighter);
  color: var(--ink-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.table tbody td {
  padding: 13px 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--brand-lighter); }

/* ---------- Badges ---------- */

.badge { font-weight: 600; font-size: 0.72rem; padding: 5px 10px; border-radius: 999px; }
.badge.bg-secondary { background: #EDEBF5 !important; color: #5B5470 !important; }
.badge.bg-success { background: #E4F7EA !important; color: #1E8A44 !important; }
.badge.bg-danger { background: #FDEAEA !important; color: #C6363B !important; }
.badge.bg-warning { background: #FDF3DE !important; color: #A97113 !important; }

/* ---------- Forms ---------- */

.form-label { font-weight: 600; font-size: 0.82rem; color: var(--ink); margin-bottom: 5px; }
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  font-size: 0.9rem;
  padding: 8px 12px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(110, 79, 201, 0.12);
}

/* ---------- Select2 brand theme ---------- */

.select2-container--bootstrap-5 .select2-selection {
  border-radius: 8px !important;
  border-color: var(--border) !important;
  min-height: 38px !important;
}
.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px rgba(110, 79, 201, 0.12) !important;
}
.select2-container--bootstrap-5 .select2-results__option--highlighted[aria-selected] {
  background-color: var(--brand) !important;
}
.select2-container--bootstrap-5 .select2-selection__choice {
  background-color: var(--brand-light) !important;
  border-color: var(--brand) !important;
  color: var(--brand-dark) !important;
}

/* ---------- Modals ---------- */

.modal-content { border-radius: var(--radius); border: none; }
.modal-header { border-bottom: 1px solid var(--border); padding: 18px 22px; }
.modal-title { font-weight: 700; font-size: 1.05rem; }
.modal-body { padding: 20px 22px; }
.modal-footer { border-top: 1px solid var(--border); padding: 14px 22px; }

/* ---------- Nav tabs ---------- */

.nav-tabs { border-bottom: 1px solid var(--border); gap: 4px; }
.nav-tabs .nav-link {
  border: none;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 4px;
  margin-right: 20px;
  border-bottom: 2px solid transparent;
}
.nav-tabs .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #241B3D 0%, #4A3480 60%, #6E4FC9 100%);
}
