:root {
  --brand:       #1c3f6e;
  --brand-2:     #2f6fb0;
  --brand-dark:  #13294a;
  --brand-ink:   #0d1f39;
  --accent:      #22b8a6;
  --bg:          #eef2f7;
  --card:        #ffffff;
  --ink:         #1f2b3d;
  --muted:       #6b7a90;
  --line:        #e6ecf3;
  --header-h:    62px;
  --sidebar-w:   256px;
  --radius:      14px;
  --shadow-sm:   0 1px 3px rgba(18,38,63,.06), 0 1px 2px rgba(18,38,63,.04);
  --shadow-md:   0 6px 24px rgba(18,38,63,.10);
  --shadow-lg:   0 18px 50px rgba(13,31,57,.28);
}

* { box-sizing: border-box; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-top: 62px;
  padding-top: var(--header-h);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Fixed header ---------------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 62px; height: var(--header-h);
  display: flex; align-items: center; gap: .5rem; padding: 0 1rem;
  background: linear-gradient(100deg, var(--brand-ink), var(--brand));
  color: #fff; z-index: 1040;
  box-shadow: 0 2px 14px rgba(13,31,57,.25);
}
.hamburger {
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.10); color: #fff; font-size: 1.2rem;
  display: grid; place-items: center; cursor: pointer; transition: background .15s, transform .15s;
}
.hamburger:hover { background: rgba(255,255,255,.20); }
.hamburger:active { transform: scale(.92); }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; margin-left: .25rem; }
.brand-badge {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 800; font-size: .85rem; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), #1a8f82); color: #fff;
  box-shadow: 0 3px 10px rgba(34,184,166,.4);
}
.brand-name { font-weight: 600; font-size: 1.05rem; letter-spacing: .2px; white-space: nowrap; }
.brand-name b { font-weight: 800; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.user-chip-btn {
  display: flex; align-items: center; gap: .55rem; border: 0; cursor: pointer;
  background: rgba(255,255,255,.08); color: #fff; padding: .3rem .6rem .3rem .3rem; border-radius: 999px;
  transition: background .15s;
}
.user-chip-btn:hover { background: rgba(255,255,255,.18); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: .8rem; color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.user-meta { flex-direction: column; align-items: flex-start; line-height: 1.05; }
.user-name { font-size: .82rem; font-weight: 600; }
.user-role { font-size: .68rem; color: rgba(255,255,255,.7); }

/* ---------------- Sidebar (slide-in / pop-up) ---------------- */
.sidebar {
  position: fixed; top: 62px; top: var(--header-h); left: 0; bottom: 0; width: 256px; width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--brand-ink), var(--brand-dark));
  z-index: 1035; overflow-y: auto; padding: .85rem .6rem 1.5rem;
  transform: translateX(0); transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.sidebar .nav { gap: 2px; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: .7rem;
  color: rgba(255,255,255,.78); padding: .62rem .8rem; border-radius: 10px;
  font-size: .9rem; font-weight: 500; position: relative; transition: background .15s, color .15s;
}
.sidebar .nav-ico {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: rgba(255,255,255,.06); font-size: 1rem; flex-shrink: 0; transition: background .15s;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link:hover .nav-ico { background: rgba(255,255,255,.14); }
.sidebar .nav-link.active {
  background: linear-gradient(90deg, rgba(47,111,176,.35), rgba(47,111,176,.10));
  color: #fff; font-weight: 600;
}
.sidebar .nav-link.active .nav-ico { background: var(--accent); color: #fff; }
.sidebar .nav-link.active::before {
  content: ""; position: absolute; left: -6px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 4px; background: var(--accent);
}
.sidebar-foot { margin-top: auto; padding-top: .5rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 10px; }

/* Collapsible group */
.nav-group-toggle .nav-caret { margin-left: auto; font-size: .75rem; transition: transform .2s ease; opacity: .7; }
.nav-group-toggle[aria-expanded="true"] .nav-caret { transform: rotate(180deg); }
.nav-group .collapse .nav-link.nav-sub,
.nav-group .collapsing .nav-link.nav-sub {
  padding: .5rem .8rem .5rem 1rem; margin: 2px 0 2px .35rem; font-size: .85rem;
  color: rgba(255,255,255,.72); border-left: 2px solid rgba(255,255,255,.12);
}
.nav-sub .nav-ico { width: 26px; height: 26px; font-size: .85rem; background: rgba(255,255,255,.05); }
.nav-sub:hover { color: #fff; }
.nav-sub.active { color: #fff; background: rgba(47,111,176,.28); border-left-color: var(--accent); font-weight: 600; }
.nav-sub.active .nav-ico { background: var(--accent); }

/* ---------------- Content ---------------- */
.main-content {
  display: block;
  margin-left: 256px; margin-left: var(--sidebar-w); padding: 1.5rem;
  min-height: calc(100vh - 62px); min-height: calc(100vh - var(--header-h));
  transition: margin-left .28s cubic-bezier(.4,0,.2,1); min-width: 0;
}
.page-head { margin-bottom: 1.1rem; }
.page-title { font-size: 1.35rem; font-weight: 700; margin: 0; color: var(--brand-ink); }

/* Backdrop for mobile pop-up */
.backdrop {
  position: fixed; inset: 62px 0 0 0; inset: var(--header-h) 0 0 0; background: rgba(13,31,57,.5);
  backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: opacity .28s, visibility .28s;
  z-index: 1034;
}

/* Desktop collapse (toggle hides the sidebar, content expands) */
body.sidebar-hidden .sidebar { transform: translateX(-100%); }
body.sidebar-hidden .main-content { margin-left: 0; }

/* Mobile: sidebar hidden by default, pops up over content with backdrop */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); width: 84%; max-width: 300px; }
  .main-content { margin-left: 0; padding: 1rem; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .backdrop { opacity: 1; visibility: visible; }
  .brand-name { font-size: .98rem; }
  .page-title { font-size: 1.15rem; }
}

/* ---------------- Cards / UI polish ---------------- */
.card, .stat-card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow-sm);
}
.stat-card { transition: transform .18s ease, box-shadow .18s ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -.5px; }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; }

/* Tables */
.table { --bs-table-hover-bg: #f4f8fd; color: var(--ink); margin: 0; }
.table > :not(caption) > * > * { padding: .7rem .85rem; }
.table thead th {
  background: #f6f9fc; color: var(--muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line);
}
.table-responsive { border-radius: var(--radius); }
.table a { color: var(--brand-2); text-decoration: none; font-weight: 600; }
.table a:hover { text-decoration: underline; }

/* Buttons */
.btn { border-radius: 9px; font-weight: 600; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); }
.btn-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn-success { background: var(--accent); border-color: var(--accent); }
.btn-success:hover { filter: brightness(.94); }
.btn-sm { border-radius: 8px; }

/* Badges */
.badge { font-weight: 600; border-radius: 7px; padding: .38em .6em; letter-spacing: .01em; }

/* Forms */
.form-control, .form-select { border-radius: 9px; border-color: #dbe4ef; }
.form-control:focus, .form-select:focus {
  border-color: var(--brand-2); box-shadow: 0 0 0 .2rem rgba(47,111,176,.15);
}
.form-label.small { font-weight: 600; color: var(--muted); }

/* Nav pills (access control tabs etc.) */
.nav-pills .nav-link { border-radius: 999px; }
.nav-pills .nav-link.active { background: var(--brand-2); }

.alert { border-radius: 11px; border: 0; }

/* ---------------- Login ---------------- */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: radial-gradient(1200px 600px at 20% -10%, #2f6fb0 0, transparent 60%),
              linear-gradient(135deg, var(--brand-ink), var(--brand));
}
.login-card {
  max-width: 400px; width: 100%; border: 0; border-radius: 18px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
body.login-page { padding-top: 0; }
