:root {
  --brand-900: #3f0f0f;
  --brand-800: #5c1717;
  --brand-700: #7a1f1f;
  --brand-600: #962a2a;
  --brand-100: #f6e6e6;
  --brand-50: #fbf4f4;
  --gold-600: #b9821a;
  --gold-500: #e0a526;
  --gold-100: #fdf1d6;
  --ink: #1d2125;
  --ink-muted: #5f666d;
  --surface: #ffffff;
  --canvas: #f6f4f1;
  --line: #e7e2dc;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(29, 33, 37, 0.06);
  --sidebar-width: 256px;

  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--canvas);
  --bs-border-color: var(--line);
  --bs-secondary-color: var(--ink-muted);
  --bs-primary: var(--brand-700);
  --bs-primary-rgb: 122, 31, 31;
  --bs-link-color: var(--brand-700);
  --bs-link-color-rgb: 122, 31, 31;
  --bs-link-hover-color: var(--brand-800);
  --bs-link-hover-color-rgb: 92, 23, 23;
  --bs-focus-ring-color: rgba(122, 31, 31, 0.25);
  --bs-heading-color: var(--ink);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--bs-heading-color);
}

body {
  font-size: 0.9375rem;
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

.btn-primary {
  --bs-btn-bg: var(--brand-700);
  --bs-btn-border-color: var(--brand-700);
  --bs-btn-hover-bg: var(--brand-800);
  --bs-btn-hover-border-color: var(--brand-800);
  --bs-btn-active-bg: var(--brand-900);
  --bs-btn-active-border-color: var(--brand-900);
  --bs-btn-disabled-bg: var(--brand-600);
  --bs-btn-disabled-border-color: var(--brand-600);
  --bs-btn-focus-shadow-rgb: 122, 31, 31;
  background-image: none;
}

.btn-outline-primary {
  --bs-btn-color: var(--brand-700);
  --bs-btn-border-color: var(--brand-700);
  --bs-btn-hover-bg: var(--brand-700);
  --bs-btn-hover-border-color: var(--brand-700);
  --bs-btn-active-bg: var(--brand-800);
  --bs-btn-active-border-color: var(--brand-800);
  --bs-btn-focus-shadow-rgb: 122, 31, 31;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 0.2rem var(--bs-focus-ring-color);
}

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

.app-sidebar {
  --bs-offcanvas-width: var(--sidebar-width);
  --bs-offcanvas-bg: var(--brand-800);
  --bs-offcanvas-color: #fff;
  background: linear-gradient(180deg, var(--brand-800) 0%, var(--brand-900) 100%);
  color: #fff;
}

@media (min-width: 992px) {
  .app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--gold-500);
  color: var(--brand-900);
  font-size: 1.25rem;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.brand-sub {
  font-size: 0.75rem;
  opacity: 0.7;
}

.sidebar-section {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.5);
  padding: 1rem 1.25rem 0.4rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: rgba(255, 255, 255, 0.82);
  padding: 0.6rem 1rem;
  margin: 0.1rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
}

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

.sidebar-nav .nav-link.active {
  background: rgba(224, 165, 38, 0.16);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--gold-500);
}

.sidebar-nav .nav-link .bi {
  font-size: 1.05rem;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 1.25rem;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 60px;
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

@media (min-width: 992px) {
  .app-topbar {
    padding: 0.5rem 1.75rem;
  }
}

.topbar-title {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.25rem 0.75rem 0.25rem 0.25rem;
  color: var(--ink);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-100);
  color: var(--brand-800);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8125rem;
}

.app-content {
  padding: 1.25rem 1rem 2.5rem;
  width: 100%;
  max-width: 1400px;
}

@media (min-width: 992px) {
  .app-content {
    padding: 1.75rem 1.75rem 3rem;
  }
}

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.page-subtitle {
  color: var(--ink-muted);
  margin: 0.25rem 0 0;
}

/* ---------- Cards ---------- */
.card {
  --bs-card-border-color: var(--line);
  --bs-card-border-radius: var(--radius);
  --bs-card-inner-border-radius: calc(var(--radius) - 1px);
  --bs-card-cap-bg: transparent;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-title-sm {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.stat-card .card-body {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  background: var(--brand-50);
  color: var(--brand-700);
  flex-shrink: 0;
}

.stat-icon.gold {
  background: var(--gold-100);
  color: var(--gold-600);
}

.stat-label {
  color: var(--ink-muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-hint {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

@media (max-width: 575.98px) {
  .stat-card .card-body {
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .stat-hint {
    font-size: 0.75rem;
  }
}

/* ---------- Mobile session list ---------- */
.session-item {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--line);
}

.session-item:first-child {
  border-top: 0;
}

.session-counts {
  display: flex;
  gap: 1rem;
  font-size: 0.8125rem;
  color: var(--ink-muted);
  margin-top: 0.4rem;
}

.session-counts strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Attention list ---------- */
.attention-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.7rem 1.25rem;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
}

.attention-item:first-child {
  border-top: 0;
}

.attention-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.attention-icon.danger { background: #fbe3e3; color: #a12121; }
.attention-icon.warning { background: var(--gold-100); color: #8a5c05; }
.attention-icon.info { background: #e7eef6; color: #2c5282; }

.min-w-0 {
  min-width: 0;
}

/* ---------- Tabs ---------- */
.tab-scroll {
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-scroll::-webkit-scrollbar {
  display: none;
}

.nav-pills {
  --bs-nav-pills-link-active-bg: var(--brand-700);
  gap: 0.25rem;
}

.nav-pills .nav-link {
  color: var(--ink-muted);
  font-weight: 500;
  white-space: nowrap;
  border-radius: 999px;
  padding: 0.4rem 1rem;
}

.nav-pills .nav-link:not(.active):hover {
  background: var(--brand-50);
  color: var(--brand-800);
}

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}

.table > thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  font-weight: 600;
  background: #faf9f7;
  white-space: nowrap;
  padding: 0.65rem 1rem;
}

.table > tbody td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cell-main {
  font-weight: 600;
}

.cell-sub {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

/* ---------- Attendance bar ---------- */
.att-bar {
  display: flex;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: #ece8e3;
  margin-top: 0.4rem;
  max-width: 220px;
}

.att-bar .present { background: #2e8b57; }
.att-bar .late { background: var(--gold-500); }

/* ---------- Device list ---------- */
.device-item {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--line);
}

.device-item:first-child {
  border-top: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
}

.status-dot.online { background: #2e8b57; }
.status-dot.offline { background: #9aa0a6; }

/* ---------- States ---------- */
.state-box {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--ink-muted);
}

.state-box .bi {
  font-size: 1.75rem;
  display: block;
  margin-bottom: 0.5rem;
}

.skeleton {
  background: linear-gradient(90deg, #eeeae5 25%, #f6f3ef 50%, #eeeae5 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 920px;
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(63, 15, 15, 0.08);
}

@media (min-width: 768px) {
  .login-card {
    grid-template-columns: 1.05fr 1fr;
  }
}

.login-footer {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--ink-muted);
  padding: 1rem;
}

/* ---------- Sidebar: collapse (desktop) & slide-in (mobile) ---------- */
:root {
  --sidebar-collapsed-width: 76px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

.app-sidebar {
  --bs-offcanvas-transition: transform .32s var(--ease-out);
  overflow-x: hidden;
}

.sidebar-nav .nav-link {
  transition: background-color .2s, color .2s, padding .28s var(--ease-out), gap .28s var(--ease-out);
}

.sidebar-nav .nav-link .bi {
  flex-shrink: 0;
  transition: transform .2s var(--ease-out);
}

.sidebar-nav .nav-link:hover .bi {
  transform: translateX(2px) scale(1.08);
}

.sidebar-nav .nav-link span,
.sidebar-brand > div:not(.brand-mark),
.sidebar-footer {
  white-space: nowrap;
}

.sidebar-toggle {
  width: 38px;
  height: 38px;
  padding: 0;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle .bi {
  transition: transform .3s var(--ease-out);
}

.sidebar-tooltip {
  --bs-tooltip-bg: var(--brand-900);
  --bs-tooltip-font-size: .8125rem;
}

@media (min-width: 992px) {
  .app-sidebar {
    transition: width .28s var(--ease-out), flex-basis .28s var(--ease-out);
  }

  .sidebar-brand {
    transition: padding .28s var(--ease-out);
  }

  .sidebar-brand > div:not(.brand-mark),
  .sidebar-nav .nav-link span {
    display: inline-block;
    max-width: 180px;
    overflow: hidden;
    transition: max-width .28s var(--ease-out), opacity .18s ease;
  }

  .sidebar-section {
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    transition: color .18s ease;
  }

  .sidebar-section::after {
    /* short divider shown in place of the section title when collapsed */
    content: "";
    position: absolute;
    left: 50%;
    bottom: .75rem;
    width: 20px;
    height: 1px;
    margin-left: -10px;
    background: rgba(255, 255, 255, .22);
    opacity: 0;
    transition: opacity .18s ease;
  }

  .sidebar-footer {
    overflow: hidden;
    transition: opacity .18s ease;
  }

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

  .sidebar-collapsed .sidebar-brand {
    padding-left: 18px;
    padding-right: 18px;
  }

  .sidebar-collapsed .sidebar-brand > div:not(.brand-mark),
  .sidebar-collapsed .sidebar-nav .nav-link span {
    max-width: 0;
    opacity: 0;
  }

  .sidebar-collapsed .sidebar-nav .nav-link {
    gap: 0;
    padding-left: calc((var(--sidebar-collapsed-width) - 1.5rem - 1.05rem) / 2);
    padding-right: 0;
  }

  .sidebar-collapsed .sidebar-section { color: transparent; }
  .sidebar-collapsed .sidebar-section::after { opacity: 1; }
  .sidebar-collapsed .sidebar-footer { opacity: 0; }
  .sidebar-collapsed .sidebar-toggle .bi { transform: rotate(180deg); }
}

@media (max-width: 991.98px) {
  /* links glide in one group after another when the menu opens */
  .app-sidebar.showing .sidebar-nav .nav-link,
  .app-sidebar.show:not(.hiding) .sidebar-nav .nav-link {
    animation: sidebarLinkIn .4s var(--ease-out) both;
  }

  .app-sidebar .sidebar-nav:nth-of-type(2) .nav-link { animation-delay: .06s; }
  .app-sidebar .sidebar-nav:nth-of-type(3) .nav-link { animation-delay: .12s; }
  .app-sidebar .sidebar-nav:nth-of-type(4) .nav-link { animation-delay: .18s; }
}

/* dimmed, slightly blurred page behind the mobile menu */
.offcanvas-backdrop {
  --bs-backdrop-bg: #1f0707;
  --bs-backdrop-opacity: .45;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

@keyframes sidebarLinkIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-sidebar *,
  .sidebar-toggle .bi {
    transition: none !important;
    animation: none !important;
  }
}

/* =========================================================
   Dashboard polish — effects only, layout unchanged
   ========================================================= */

/* ---------- Soft background tint ---------- */
body {
  background:
    radial-gradient(900px 500px at 100% 0%, rgba(224, 165, 38, .06), transparent 60%),
    radial-gradient(800px 500px at 0% 100%, rgba(122, 31, 31, .045), transparent 60%),
    var(--canvas);
  background-attachment: fixed;
}

/* ---------- Page entrance (first load only, see ui.js) ---------- */
.page-enter > *,
.page-enter .row > [class*="col"] {
  animation: polishFadeUp .5s var(--ease-out) both;
}
.page-enter .row > [class*="col"]:nth-child(2) { animation-delay: .06s; }
.page-enter .row > [class*="col"]:nth-child(3) { animation-delay: .12s; }
.page-enter .row > [class*="col"]:nth-child(4) { animation-delay: .18s; }
.page-enter .row > [class*="col"]:nth-child(n+5) { animation-delay: .24s; }

/* ---------- Page header ---------- */
.page-title {
  position: relative;
  padding-bottom: .35rem;
}
.page-title::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 36px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--gold-500), var(--brand-600));
}

/* ---------- Topbar: shadow appears once you scroll ---------- */
@supports (animation-timeline: scroll()) {
  .app-topbar {
    animation: topbarShadow linear both;
    animation-timeline: scroll(root);
    animation-range: 0 80px;
  }
}
@keyframes topbarShadow {
  to { box-shadow: 0 6px 18px -10px rgba(63, 15, 15, .25); }
}

.user-chip {
  transition: border-color .2s, box-shadow .2s, transform .2s var(--ease-out);
}
.user-chip:hover {
  border-color: var(--brand-100);
  box-shadow: 0 4px 12px -6px rgba(63, 15, 15, .25);
}
.user-avatar {
  background: linear-gradient(145deg, var(--brand-100), #f1d3d3);
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--gold-500);
}

/* ---------- Cards ---------- */
.card {
  transition: box-shadow .25s var(--ease-out), border-color .25s, transform .25s var(--ease-out);
}
.card:hover {
  box-shadow: 0 1px 2px rgba(29, 33, 37, .05), 0 10px 24px -14px rgba(63, 15, 15, .22);
}
.card-header .card-title-sm {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-header .card-title-sm::before {
  content: "";
  width: 4px;
  height: 1em;
  border-radius: 4px;
  background: var(--gold-500);
}

/* ---------- Stat cards ---------- */
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  /* gold-to-maroon line that grows on hover */
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  background: linear-gradient(90deg, var(--gold-500), var(--brand-600));
  transform: scaleX(.18);
  transform-origin: left;
  transition: transform .45s var(--ease-out);
}
.stat-card::after {
  /* soft tint in the corner */
  content: "";
  position: absolute;
  right: -40px;
  bottom: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(122, 31, 31, .06), transparent 70%);
  pointer-events: none;
  transition: transform .45s var(--ease-out);
}
.stat-card:hover {
  transform: translateY(-3px);
}
.stat-card:hover::before { transform: scaleX(1); }
.stat-card:hover::after { transform: scale(1.3); }

.stat-icon {
  transition: transform .3s var(--ease-out), box-shadow .3s;
}
.stat-card:hover .stat-icon {
  transform: rotate(-6deg) scale(1.08);
  box-shadow: 0 6px 14px -6px rgba(122, 31, 31, .35);
}
.stat-card:hover .stat-icon.gold {
  box-shadow: 0 6px 14px -6px rgba(185, 130, 26, .45);
}

/* ---------- Tables ---------- */
.table > tbody tr {
  transition: background-color .15s;
}
.table > tbody tr:hover > * {
  background-color: var(--brand-50);
}
.table > tbody tr:hover > td:first-child {
  box-shadow: inset 3px 0 0 var(--gold-500);
}

/* ---------- Lists (sessions, attention, devices) ---------- */
.session-item,
.attention-item,
.device-item {
  transition: background-color .15s, padding-left .2s var(--ease-out);
}
.session-item:hover,
.attention-item:hover,
.device-item:hover {
  background-color: #fcfaf8;
}
.attention-icon {
  transition: transform .2s var(--ease-out);
}
.attention-item:hover .attention-icon {
  transform: scale(1.1);
}

/* ---------- Attendance bar ---------- */
.att-bar > * {
  transition: filter .2s;
}
.att-bar:hover > * {
  filter: brightness(1.1);
}
.page-enter .att-bar {
  animation: barGrow .9s .2s var(--ease-out) both;
}

/* ---------- Device status ---------- */
.status-dot.online {
  animation: onlinePulse 2.2s infinite;
}

/* ---------- Buttons ---------- */
.btn {
  transition: transform .2s var(--ease-out), box-shadow .2s var(--ease-out),
              background-color .2s, border-color .2s, color .2s;
}
.btn:not(:disabled):hover {
  transform: translateY(-1px);
}
.btn:not(:disabled):active {
  transform: translateY(0) scale(.98);
  transition-duration: .06s;
}
.btn-primary {
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .08), transparent);
  box-shadow: 0 4px 10px -6px rgba(122, 31, 31, .6);
}
.btn-primary:hover {
  box-shadow: 0 8px 16px -8px rgba(122, 31, 31, .6);
}
.btn:focus-visible {
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--gold-500);
}

/* ---------- Tabs ---------- */
.nav-pills .nav-link {
  transition: background-color .2s, color .2s, box-shadow .2s;
}
.nav-pills .nav-link.active {
  box-shadow: 0 4px 10px -6px rgba(122, 31, 31, .6);
}

/* ---------- Dropdowns, modals, toasts ---------- */
.dropdown-menu {
  border-color: var(--line);
  border-radius: 10px;
}
.dropdown-menu.show {
  animation: menuIn .18s var(--ease-out);
}
.dropdown-item {
  border-radius: 6px;
  transition: background-color .15s, padding-left .15s;
}
.dropdown-menu {
  padding: .35rem;
}
.dropdown-item:hover {
  background: var(--brand-50);
  color: var(--brand-800);
}

.modal.fade .modal-dialog {
  transform: translateY(12px) scale(.97);
  transition: transform .28s var(--ease-out);
}
.modal.show .modal-dialog {
  transform: none;
}
.modal-content {
  border: 0;
  border-radius: 14px;
  box-shadow: 0 24px 60px -20px rgba(63, 15, 15, .35);
}
.modal-backdrop {
  --bs-backdrop-bg: #1f0707;
  --bs-backdrop-opacity: .4;
}

.toast.showing,
.toast.show {
  animation: toastIn .3s var(--ease-out);
}

/* ---------- Sidebar touches ---------- */
.sidebar-nav .nav-link.active .bi {
  color: var(--gold-500);
}
.brand-mark {
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .45);
}
.app-sidebar {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .2) transparent;
}

/* ---------- Keyframes ---------- */
@keyframes polishFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes barGrow {
  from { clip-path: inset(0 100% 0 0 round 999px); }
  to { clip-path: inset(0 0 0 0 round 999px); }
}
@keyframes onlinePulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 139, 87, .5); }
  70% { box-shadow: 0 0 0 6px rgba(46, 139, 87, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 139, 87, 0); }
}
@keyframes menuIn {
  /* uses `translate`, not `transform`, so Bootstrap's dropdown positioning isn't overridden */
  from { opacity: 0; translate: 0 -4px; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .page-enter > *,
  .page-enter .row > [class*="col"],
  .page-enter .att-bar,
  .status-dot.online,
  .dropdown-menu.show,
  .toast.show,
  .app-topbar {
    animation: none !important;
  }
  .card,
  .btn,
  .stat-card,
  .stat-card::before,
  .stat-icon,
  .modal.fade .modal-dialog {
    transition: none !important;
  }
}

/* =========================================================
   Topbar design
   ========================================================= */
.app-topbar {
  min-height: 64px;
  border-bottom: 0;
  background:
    linear-gradient(90deg, rgba(251, 244, 244, .9), rgba(255, 255, 255, .92) 35%, rgba(255, 255, 255, .92) 70%, rgba(253, 241, 214, .55));
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
}

/* thin maroon → gold line along the bottom, with a slow shimmer */
.app-topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .9), transparent) -40% 0 / 30% 100% no-repeat,
    linear-gradient(90deg, var(--brand-700), var(--gold-500) 55%, var(--brand-100));
  animation: topbarShimmer 6s ease-in-out infinite;
  pointer-events: none;
}

/* ---------- Toggle buttons ---------- */
.topbar-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #fff;
  color: var(--brand-800);
  box-shadow: var(--shadow-sm);
}
.topbar-btn:hover {
  background: var(--brand-700);
  border-color: var(--brand-700) !important;
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(122, 31, 31, .55);
}

/* ---------- Page heading ---------- */
.topbar-heading {
  display: flex;
  align-items: center;
  gap: .7rem;
}
.topbar-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 1.05rem;
  color: var(--gold-500);
  background: linear-gradient(145deg, var(--brand-700), var(--brand-900));
  box-shadow: 0 6px 14px -6px rgba(63, 15, 15, .55), inset 0 1px 0 rgba(255, 255, 255, .15);
  animation: topbarIconIn .5s var(--ease-out) both;
}
.topbar-eyebrow {
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gold-600);
  line-height: 1.2;
}
.topbar-eyebrow .bi {
  font-size: .6rem;
  opacity: .7;
  margin: 0 .15rem;
}
.topbar-title {
  line-height: 1.25;
  font-weight: 700;
  color: var(--brand-900);
  animation: polishFadeUp .45s .05s var(--ease-out) both;
}

/* ---------- Date & time chip ---------- */
.topbar-clock {
  align-items: center;
  gap: .4rem;
  padding: .35rem .8rem;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--ink-muted);
  background: rgba(255, 255, 255, .8);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.topbar-clock .bi {
  color: var(--brand-700);
}
.topbar-clock-sep {
  width: 1px;
  height: 14px;
  margin: 0 .25rem;
  background: var(--line);
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2e8b57;
  margin-right: .15rem;
  animation: onlinePulse 2.2s infinite;
}

/* ---------- User chip ---------- */
.user-chip {
  padding-right: .85rem;
  background: #fff;
}
.user-chip:hover,
.user-chip[aria-expanded="true"] {
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(224, 165, 38, .15), 0 6px 14px -8px rgba(63, 15, 15, .3);
}
.user-chip::after {
  transition: transform .2s var(--ease-out);
}
.user-chip[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

@keyframes topbarShimmer {
  0%, 60% { background-position: -40% 0, 0 0; }
  100% { background-position: 140% 0, 0 0; }
}
@keyframes topbarIconIn {
  from { opacity: 0; transform: scale(.8) rotate(-8deg); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 575.98px) {
  .topbar-icon { display: none; }
  .topbar-eyebrow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-topbar::after,
  .topbar-icon,
  .topbar-title,
  .live-dot {
    animation: none !important;
  }
}

/* =========================================================
   Page transitions (login ⇄ dashboard, and between pages)
   Uses the browser's View Transitions. Chrome, Edge and Safari
   animate; other browsers just switch pages normally.
   ========================================================= */
@view-transition {
  navigation: auto;
}

/* Name the pieces that should move on their own */
.auth-card { view-transition-name: login-card; }
.auth-splash { view-transition-name: auth-splash; }

@media (min-width: 992px) {
  .app-sidebar { view-transition-name: sidebar; }
}
.app-topbar { view-transition-name: topbar; }

/* Whole page: old one fades back, new one rises in */
::view-transition-old(root) {
  animation: vtFadeOut .35s ease both;
}
::view-transition-new(root) {
  animation: vtRiseIn .55s .1s var(--ease-out, cubic-bezier(.2, .8, .2, 1)) both;
}

/* Login card shrinks away (login → dashboard) */
::view-transition-old(login-card):only-child {
  animation: vtCardOut .45s cubic-bezier(.4, 0, .2, 1) both;
}
/* …and pops back in after signing out (dashboard → login) */
::view-transition-new(login-card):only-child {
  animation: vtCardIn .6s .1s var(--ease-out, cubic-bezier(.2, .8, .2, 1)) both;
}

/* "Signing you in…" screen melts into the dashboard */
::view-transition-old(auth-splash):only-child {
  animation: vtSplashOut .5s ease both;
}

/* Sidebar slides in from the left when the dashboard first appears,
   and stays still when moving between dashboard pages */
::view-transition-new(sidebar):only-child {
  animation: vtSlideInLeft .6s .05s var(--ease-out, cubic-bezier(.2, .8, .2, 1)) both;
}
::view-transition-old(sidebar):only-child {
  animation: vtSlideOutLeft .35s ease both;
}

/* Topbar drops in from above on first appearance */
::view-transition-new(topbar):only-child {
  animation: vtDropIn .5s .15s var(--ease-out, cubic-bezier(.2, .8, .2, 1)) both;
}
::view-transition-old(topbar):only-child {
  animation: vtFadeOut .25s ease both;
}

@keyframes vtFadeOut {
  to { opacity: 0; }
}
@keyframes vtRiseIn {
  from { opacity: 0; transform: translateY(14px); }
}
@keyframes vtCardOut {
  to { opacity: 0; transform: scale(.92) translateY(10px); filter: blur(4px); }
}
@keyframes vtCardIn {
  from { opacity: 0; transform: scale(.94) translateY(14px); }
}
@keyframes vtSplashOut {
  to { opacity: 0; transform: scale(1.04); }
}
@keyframes vtSlideInLeft {
  from { transform: translateX(-100%); }
}
@keyframes vtSlideOutLeft {
  to { transform: translateX(-100%); }
}
@keyframes vtDropIn {
  from { opacity: 0; transform: translateY(-100%); }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}
/* =========================================================
   Instructor & Student portals
   ========================================================= */

/* Attendance rate meter */
.rate-meter {
  height: 6px;
  border-radius: 999px;
  background: #ece8e3;
  overflow: hidden;
  margin-top: 0.4rem;
}
.rate-meter > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width .6s var(--ease-out);
}
.rate-success > span { background: #2e8b57; }
.rate-warning > span { background: var(--gold-500); }
.rate-danger > span { background: #c0392b; }
.rate-secondary > span { background: #b8b2ab; }
.page-enter .rate-meter > span { animation: barGrow .9s .2s var(--ease-out) both; }

.att-bar-wide { max-width: none; height: 8px; margin-top: 0.85rem; }

/* Class & subject cards */
.class-card { transition: transform .2s var(--ease-out), box-shadow .2s; }
.class-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -14px rgba(63, 15, 15, .35); }
.class-card .card-footer { border-top: 1px solid var(--line); }
.class-card-code {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: none; /* codes are typed in the right case already (BSCpE, not BSCPE) */
  color: var(--gold-600);
}
.class-card-title { font-weight: 600; line-height: 1.3; }

.schedule-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}
.schedule-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-50);
  font-size: 0.75rem;
  white-space: nowrap;
}
.schedule-chip strong { color: var(--brand-700); }

.subject-item {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
}
.subject-item:first-of-type { border-top: 0; }
.subject-rate {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Small summary tiles (session / report / history) */
.summary-tile {
  padding: 0.6rem 0.4rem;
  border-radius: 10px;
  background: var(--canvas);
  border: 1px solid var(--line);
}
.summary-num {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.summary-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-muted);
}
.summary-tile.tone-success { background: #eaf6ef; border-color: #cde9d8; }
.summary-tile.tone-success .summary-num { color: #1f6b41; }
.summary-tile.tone-warning { background: var(--gold-100); border-color: #f4dfa8; }
.summary-tile.tone-warning .summary-num { color: #8a5c05; }
.summary-tile.tone-danger { background: #fbe9e9; border-color: #f2cccc; }
.summary-tile.tone-danger .summary-num { color: #a12121; }

/* Correction dialog: status buttons */
.status-choice {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

/* Report matrix (P / L / A per session) */
.mark {
  display: inline-grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}
.mark-success { background: #eaf6ef; color: #1f6b41; }
.mark-warning { background: var(--gold-100); color: #8a5c05; }
.mark-danger { background: #fbe9e9; color: #a12121; }
.mark-secondary { background: #f1efec; color: var(--ink-muted); }
.matrix-table th, .matrix-table td { white-space: nowrap; }
.matrix-sticky {
  width: 1%;
  min-width: 190px;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface) !important;
  box-shadow: 1px 0 0 var(--line);
}

/* Student profile */
.profile-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--brand-600), var(--brand-900));
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
}
.rfid-card {
  max-width: 320px;
  padding: 1rem 1.15rem;
  border-radius: 14px;
  color: #fff;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(224, 165, 38, .35), transparent 55%),
    linear-gradient(135deg, var(--brand-700), var(--brand-900));
  box-shadow: 0 12px 24px -14px rgba(63, 15, 15, .6);
}

/* Printing a class report: only the report itself */
@media print {
  .app-sidebar, .app-topbar, .d-print-none, .toast-container { display: none !important; }
  .app-layout, .app-main, .app-content { display: block !important; margin: 0 !important; padding: 0 !important; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none !important; }
  .table-responsive { overflow: visible !important; }
  .matrix-sticky { position: static; }
  .page-enter > *, .page-enter .row > [class*="col"] { animation: none !important; }
}

/* Instructor dashboard: the whole class card opens the roster */
.class-card-open { cursor: pointer; border-radius: inherit; }
.class-card-open:hover .class-card-title { color: var(--brand-700); text-decoration: underline; }
.class-card-open:focus-visible { outline: 2px solid var(--brand-700); outline-offset: -2px; }


/* =========================================================
   Layout fixes (frontend polish)
   ========================================================= */

/* Hidden table labels (.visually-hidden is position:absolute) must stay inside
   the table's scroll box, or a wide table stretches the whole page on phones. */
.table-responsive { position: relative; }

/* Edge adds its own reveal eye next to our show/hide button: keep only ours */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }
/* 44px touch target for the show/hide buttons without changing how they look */
[data-toggle-password]::after { content: ""; position: absolute; inset: -4px; }

/* Sidebar footer: wrap instead of being cut off ("Computer Engin…") */
.app-layout:not(.sidebar-collapsed) .sidebar-footer { white-space: normal; line-height: 1.4; }
@media (max-width: 991.98px) {
  .sidebar-footer { white-space: normal; line-height: 1.4; }
}

/* Small buttons keep icon + label on one line (e.g. "✎ Correct" on phones) */
.btn-sm { white-space: nowrap; }

/* Sidebar on a short screen: scroll instead of squeezing every part
   (squeezing cut the section labels in half: "OVERVIEW", "PEOPLE"…). */
.app-sidebar > * { flex-shrink: 0; }

/* The main area always takes exactly the space left next to the sidebar,
   never the width of its content. A wide table then scrolls inside its card
   instead of pushing the page (and the top bar) past the right edge. */
.app-layout { width: 100%; }
.app-main { flex: 1 1 0%; min-width: 0; }
.app-content { min-width: 0; max-width: 100%; }

/* =========================================================
   Phones and tablets
   ========================================================= */

/* Rate column in the instructor report */
.report-rate-col { min-width: 150px; }

@media (max-width: 575.98px) {
  /* Tables: a little less padding so 3–4 columns fit a 360px screen */
  .table > :not(caption) > * > * { padding: .65rem .55rem; }
  .table > :not(caption) > * > *:first-child { padding-left: .9rem; }
  .table > :not(caption) > * > *:last-child { padding-right: .9rem; }
  .report-rate-col { min-width: 110px; }

  /* iPhone zooms the whole page when you tap a field with text under 16px */
  input.form-control, select.form-select, textarea.form-control,
  .form-control-sm, .form-select-sm { font-size: 16px; }
}

/* Touch screens: every button is big enough for a finger (about 36px) */
@media (pointer: coarse) {
  .btn-sm { min-height: 36px; min-width: 36px; }
  .btn-group-sm > .btn { min-height: 36px; }
  .btn-link.p-0 { min-height: 32px; display: inline-flex; align-items: center; }
}
