/* ==========================================================================
   Chemistry Zone Attendance System — visual theme
   Palette: deep indigo (brand) + lab-glass teal (accent) + warm amber
   (highlight/streaks). Top navbar layout with animated active indicator.
   ========================================================================== */

:root {
  --brand-ink: #3730a3;       /* deep indigo — primary brand */
  --brand-ink-dark: #2c2483;
  --brand-glass: #0ea5a5;     /* lab-glass teal — accent for icon circles */
  --brand-amber: #f59e0b;     /* warm amber — streaks / highlights */
  --shadow-color: 55, 48, 163; /* rgb of --brand-ink, used in tinted shadows */
}

* {
  scroll-behavior: smooth;
}

body {
  background-color: #f3f4fb;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-bs-theme="dark"] body,
[data-bs-theme="dark"] {
  background-color: #12131c;
}

/* -------------------- App shell: sidebar + topbar -------------------- */

:root {
  --sidebar-width: 264px;
  --sidebar-width-collapsed: 76px;
  --topbar-height: 64px;
  --surface: #ffffff;
  --surface-muted: #f6f7fb;
  --border-subtle: rgba(17, 24, 39, 0.08);
  --text-muted-2: #6b7280;
}

[data-bs-theme="dark"] {
  --surface: #171827;
  --surface-muted: #1e2032;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text-muted-2: #9599ad;
}

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

/* ---- Sidebar ---- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1040;
  transition: transform 0.2s ease, width 0.2s ease;
}

.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-width-collapsed);
}

.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}

.brand-icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 10px;
  background: var(--brand-ink);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--bs-body-color);
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell.sidebar-collapsed .sidebar-brand .brand-name,
.app-shell.sidebar-collapsed .sidebar-link span,
.app-shell.sidebar-collapsed .sidebar-group-toggle span,
.app-shell.sidebar-collapsed .sidebar-group-toggle .chevron,
.app-shell.sidebar-collapsed .sidebar-submenu,
.app-shell.sidebar-collapsed .sidebar-footer .user-meta {
  display: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.65rem;
}

.sidebar-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted-2);
  padding: 0.9rem 0.6rem 0.3rem;
  font-weight: 700;
}

.sidebar-link,
.sidebar-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  color: var(--bs-body-color);
  text-decoration: none;
  font-size: 0.9rem;
  width: 100%;
  border: none;
  background: transparent;
  margin-bottom: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-link i,
.sidebar-group-toggle > i:first-child {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  color: var(--text-muted-2);
  flex-shrink: 0;
}

.sidebar-link:hover,
.sidebar-group-toggle:hover {
  background: var(--surface-muted);
  color: var(--bs-body-color);
}

.sidebar-link.active {
  background: rgba(var(--shadow-color), 0.1);
  color: var(--brand-ink);
  font-weight: 600;
}
.sidebar-link.active i {
  color: var(--brand-ink);
}
[data-bs-theme="dark"] .sidebar-link.active {
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
}
[data-bs-theme="dark"] .sidebar-link.active i {
  color: #a5b4fc;
}

.sidebar-group-toggle .chevron {
  margin-left: auto;
  font-size: 0.8rem;
  transition: transform 0.15s ease;
}
.sidebar-group.open .sidebar-group-toggle .chevron {
  transform: rotate(180deg);
}
.sidebar-group-toggle.has-open {
  color: var(--brand-ink);
}

.sidebar-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.2s ease;
  padding-left: 2.1rem;
}
.sidebar-group.open .sidebar-submenu {
  max-height: 400px;
}

.sidebar-submenu .sidebar-link {
  font-size: 0.86rem;
  padding: 0.45rem 0.6rem;
}

.sidebar-link.disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.sidebar-soon-badge {
  margin-left: auto;
  font-size: 0.62rem;
  padding: 0.1rem 0.4rem;
  border-radius: 20px;
  background: var(--surface-muted);
  color: var(--text-muted-2);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 0.75rem;
  flex-shrink: 0;
}

.sidebar-footer .user-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem;
  border-radius: 10px;
}

.sidebar-footer .user-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  background: var(--brand-glass);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.sidebar-footer .user-meta {
  overflow: hidden;
  flex: 1;
}
.sidebar-footer .user-meta .name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer .user-meta .role {
  font-size: 0.72rem;
  color: var(--text-muted-2);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1035;
}

/* ---- Topbar ---- */

.main-wrap {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}
.app-shell.sidebar-collapsed .main-wrap {
  margin-left: var(--sidebar-width-collapsed);
}

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.1rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.sidebar-toggle-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--bs-body-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
  background: var(--surface-muted);
}

.global-search {
  position: relative;
  flex: 1;
  max-width: 480px;
}

.global-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  border: 1px solid transparent;
}
.global-search-input-wrap:focus-within {
  border-color: var(--brand-ink);
}
.global-search-input-wrap i {
  color: var(--text-muted-2);
}
.global-search-input-wrap input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 0.88rem;
  color: var(--bs-body-color);
  min-width: 0;
}
.global-search-input-wrap kbd {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  color: var(--text-muted-2);
  white-space: nowrap;
}

.global-search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
  max-height: 420px;
  overflow-y: auto;
  z-index: 1050;
}
.global-search-results.show {
  display: block;
}
.global-search-results .result-category {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted-2);
  font-weight: 700;
  padding: 0.6rem 0.9rem 0.2rem;
}
.global-search-results .result-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  color: var(--bs-body-color);
}
.global-search-results .result-item:hover,
.global-search-results .result-item.active-result {
  background: var(--surface-muted);
}
.global-search-results .result-item small {
  color: var(--text-muted-2);
}
.global-search-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted-2);
  font-size: 0.85rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--bs-body-color);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
  position: relative;
}
.icon-btn:hover {
  background: var(--surface-muted);
}

/* Keyboard shortcuts hint row inside modal */
.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-subtle);
}
.shortcut-row:last-child {
  border-bottom: none;
}
.shortcut-row kbd {
  background: var(--surface-muted);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
}

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .app-shell.sidebar-mobile-open .sidebar {
    transform: translateX(0);
    width: var(--sidebar-width);
  }
  .app-shell.sidebar-mobile-open .sidebar .brand-name,
  .app-shell.sidebar-mobile-open .sidebar-link span,
  .app-shell.sidebar-mobile-open .sidebar-group-toggle span,
  .app-shell.sidebar-mobile-open .sidebar-group-toggle .chevron,
  .app-shell.sidebar-mobile-open .sidebar-footer .user-meta {
    display: flex;
  }
  .app-shell.sidebar-mobile-open .sidebar-submenu {
    display: block;
  }
  .app-shell.sidebar-mobile-open .sidebar-backdrop {
    display: block;
  }
  .main-wrap,
  .app-shell.sidebar-collapsed .main-wrap {
    margin-left: 0;
  }
  .global-search .global-search-input-wrap kbd {
    display: none;
  }
}

/* -------------------- Content -------------------- */

.content {
  min-width: 0;
}

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

.card {
  border: none;
  border-radius: 14px;
  box-shadow: 0 2px 14px rgba(var(--shadow-color), 0.06);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

[data-bs-theme="dark"] .card {
  background: #1a1c2b;
}

.stat-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 28px rgba(var(--shadow-color), 0.16);
}

.stat-icon-circle {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 0.6rem;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.stat-card:hover .stat-icon-circle {
  transform: scale(1.12) rotate(-4deg);
}

.stat-value {
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}

kbd {
  background: var(--surface-muted, #f1f2f6);
  border: 1px solid var(--border-subtle, rgba(17,24,39,.12));
  border-radius: 5px;
  padding: 0.1rem 0.4rem;
  font-size: 0.78rem;
  color: var(--bs-body-color);
}

.stat-trend {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted-2);
}
.stat-trend.up {
  color: #198754;
}
.stat-trend.down {
  color: #dc3545;
}

.at-risk-item {
  border-left: 3px solid #dc3545;
  background: rgba(220, 53, 69, 0.06);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}
[data-bs-theme="dark"] .at-risk-item {
  background: rgba(220, 53, 69, 0.12);
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.quick-action-btn {
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  text-decoration: none;
  display: block;
}
.quick-action-btn:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 24px rgba(var(--shadow-color), 0.14);
}
.quick-action-btn i {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 0.4rem;
}

/* Clickable table rows / list items get a subtle lift */
.table-hover tbody tr {
  transition: background 0.12s ease;
}

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

.login-wrapper {
  background: linear-gradient(135deg, var(--brand-ink) 0%, var(--brand-glass) 130%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 20px;
  animation: cardEnter 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.entry-card {
  border-radius: 18px;
}

.student-info-box {
  background: #ecfbfb;
  border-radius: 12px;
  padding: 1rem;
  border-left: 3px solid var(--brand-glass);
  animation: cardEnter 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
[data-bs-theme="dark"] .student-info-box {
  background: #16232b;
}

.student-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-glass);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

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

.btn {
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: scale(0.96);
}
.btn-primary {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
}
.btn-primary:hover {
  background: var(--brand-ink-dark);
  border-color: var(--brand-ink-dark);
  box-shadow: 0 6px 16px rgba(var(--shadow-color), 0.28);
}
.btn-outline-primary {
  color: var(--brand-ink);
  border-color: var(--brand-ink);
}
.btn-outline-primary:hover {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
}

.btn-ripple {
  position: absolute;
  width: 10px;
  height: 10px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  animation: rippleGrow 0.5s ease-out;
}

@keyframes rippleGrow {
  from { transform: translate(-50%, -50%) scale(0); opacity: 0.6; }
  to { transform: translate(-50%, -50%) scale(18); opacity: 0; }
}

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

.badge {
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* -------------------- Success confirmation (attendance entry) -------------------- */

#successAnim i {
  animation: successPop 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes successPop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* -------------------- Motion: orchestrated entrances -------------------- */

.page-fade-in {
  animation: pageFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast-alert {
  animation: fadeIn 0.3s ease;
}

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

/* Staggered fade-up for stat cards / lists, applied via .stagger-item */
.stagger-item {
  animation: staggerUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes staggerUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
