/* ============================================================
   css/app.css — Application Shell & Layout (v1 — refactored)
   ----------------------------------------------------------------------------
   This file owns ONLY page-chrome/layout: design tokens, sidebar, topbar,
   search bar, page scaffolding, loader/toast shell, guest banner, and
   responsive shell behavior.

   Reusable UI COMPONENTS (cards, buttons, forms, modals, badges, and
   one-off utility classes) now live under css/components/ — see that
   folder for buttons.css, cards.css, forms.css, modals.css, badges.css,
   and utilities.css. Load order on every page:

     1. components/forms.css     (base form system — safety net)
     2. components/buttons.css
     3. components/cards.css
     4. components/badges.css
     5. components/modals.css
     6. app.css                  (this file — shell/layout, uses the vars
                                   and components above)
     7. components/utilities.css (last — utility classes win ties)
     8. breakpoints.css          (last of all — responsive refinements)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --app-theme-color: #2B2640;
  --app-bg:          #F0EEF8;
  --sidebar-w:       220px;
  --header-h:        54px;
  --radius-sm:       8px;
  --radius-md:       12px;
  --radius-lg:       16px;
  --shadow-card:     0 2px 12px rgba(0,0,0,.08);
  --shadow-float:    0 6px 20px rgba(0,0,0,.22);
  --transition:      0.18s ease;
  --accent:          #6C5CE7;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--app-bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════════
   SIDEBAR LAYOUT
══════════════════════════════════════════════ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--app-theme-color);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1100;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  will-change: transform;
}

.sidebar-brand {
  padding: 22px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 2px;
  letter-spacing: -.01em;
  color: #fff;
}
.sidebar-brand .brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,.5);
  font-weight: 500;
}

.sidebar-greeting {
  padding: 10px 18px 6px;
  font-size: 12px;
  color: rgba(255,255,255,.6);
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: rgba(255,255,255,.35);
  padding: 12px 18px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  min-height: 44px;
  color: rgba(255,255,255,.72);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border-radius: 0;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 15px;
}
.nav-item:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
  text-decoration: none;
}
.nav-item:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -2px;
  background: rgba(255,255,255,.1);
}
.nav-item.active {
  background: rgba(255,255,255,.14);
  color: #fff;
  font-weight: 600;
  position: relative;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: #fff;
}
.nav-item.danger { color: rgba(255,120,100,.8); }
.nav-item.danger:hover { background: rgba(255,80,60,.12); color: #ff7878; }
.nav-item.success { color: rgba(100,230,150,.85); }
.nav-item.success:hover { background: rgba(40,200,100,.12); color: #64e696; }

.sidebar-footer {
  padding: 14px 0 8px;
  border-top: 1px solid rgba(255,255,255,.1);
}

/* ── Main content area ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar (inside main) ── */
.topbar {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid #e8e5f0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--app-theme-color);
  cursor: pointer;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 -4px 0 -8px;
  border-radius: 8px;
  transition: background var(--transition);
}
.topbar-menu-btn:hover { background: rgba(43,38,64,.06); }
.topbar-menu-btn:focus-visible {
  outline: 2px solid var(--app-theme-color);
  outline-offset: 2px;
}
.topbar-menu-btn .hamburger-icon {
  position: relative;
  width: 18px;
  height: 14px;
}
.topbar-menu-btn .hamburger-icon span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .2s ease, top .25s cubic-bezier(.4,0,.2,1);
}
.topbar-menu-btn .hamburger-icon span:nth-child(1) { top: 0; }
.topbar-menu-btn .hamburger-icon span:nth-child(2) { top: 6px; }
.topbar-menu-btn .hamburger-icon span:nth-child(3) { top: 12px; }
.topbar-menu-btn[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
  top: 6px; transform: rotate(45deg);
}
.topbar-menu-btn[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
  opacity: 0;
}
.topbar-menu-btn[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
  top: 6px; transform: rotate(-45deg);
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--app-theme-color);
  flex: 1;
  letter-spacing: -.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-icon-btn {
  background: none;
  border: none;
  color: var(--app-theme-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  transition: background var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.topbar-icon-btn:hover { background: #f0eef8; color: var(--app-theme-color); }

/* ── Page content wrapper ── */
.page-body {
  flex: 1;
  padding: 0;
}


/* ══════════════════════════════════════════════
   SEARCH BAR (sticky under topbar)
══════════════════════════════════════════════ */
#search_bar {
  padding: 10px 16px 6px;
  background: var(--app-bg);
  position: sticky;
  top: var(--header-h);
  z-index: 800;
  border-bottom: 1px solid #e8e5f0;
}

#search_bar .input-group.mb-4 { margin-bottom: 6px !important; }

#search_bar .input-group-text {
  background: #fff;
  border-right: none;
  color: var(--app-theme-color);
}

#search_bar .form-control#search {
  border-left: none;
  box-shadow: none;
  font-size: 14px;
  height: 44px;
}

#search:focus {
  border-color: var(--app-theme-color);
  box-shadow: none;
  outline: none;
}

#search_bar .row.pt-2 {
  padding-top: 2px !important;
  align-items: center;
}
#search_bar .row .row {
  margin-left: 0;
  margin-top: 0;
  padding-bottom: 6px;
  align-items: center;
  gap: 2px;
}

#records {
  font-size: 13px;
  font-weight: 600;
  color: #888;
  margin: 0;
  padding-top: 0 !important;
  white-space: nowrap;
}

.filter-items { margin: 0; }
#filter_params { flex-wrap: wrap; gap: 4px; }
#filter_params h6 {
  background: #fff;
  border: 1.5px solid var(--app-theme-color);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--app-theme-color);
  margin: 0;
}

/* ══════════════════════════════════════════════
   LIST
══════════════════════════════════════════════ */
.list-container {
  padding: 10px 16px 80px;
}


/* ══════════════════════════════════════════════
   LOADER & TOAST
══════════════════════════════════════════════ */
#__loader__ {
  position: fixed;
  inset: 0;
  background: rgba(20,16,40,.52);
  color: #fff;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  gap: 14px;
  backdrop-filter: blur(2px);
}
#__loader__ span {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
}
#__loader__::before {
  content: '';
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#__toast__ {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #222;
  color: #fff;
  padding: 11px 22px;
  border-radius: 999px;
  display: none;
  z-index: 2100;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.28);
}
#__toast__.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}


/* ══════════════════════════════════════════════
   GUEST BANNER
══════════════════════════════════════════════ */
#__guest_banner__ {
  background: #fff8e1;
  color: #7a5c00;
  font-size: 12.5px;
  text-align: center;
  padding: 7px 10px;
  position: sticky;
  top: var(--header-h);
  z-index: 850;
  font-weight: 500;
}
#__guest_banner__ a {
  color: var(--app-theme-color);
  font-weight: 700;
  text-decoration: underline;
}


/* ══════════════════════════════════════════════
   SIDEBAR OVERLAY (mobile)
══════════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1050;
  opacity: 0;
  transition: opacity .28s ease;
}
.sidebar-overlay.open {
  display: block;
}
.sidebar-overlay.show {
  opacity: 1;
}


/* ══════════════════════════════════════════════
   RESPONSIVE — MOBILE
══════════════════════════════════════════════ */
@media (max-width: 640px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .topbar-menu-btn {
    display: flex;
  }
  .dashboard-cards {
    padding: 12px 14px;
  }
}

/* Lock body scroll while the mobile sidebar is open */
body.sidebar-locked {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-overlay,
  .topbar-menu-btn .hamburger-icon span {
    transition-duration: 0.001ms !important;
  }
}


/* ══════════════════════════════════════════════
   HIDE INJECTED OLD HEADER, MOVE BUTTONS TO TOPBAR
══════════════════════════════════════════════ */

/* The JS injects a .header fixed bar — hide it in our new layout */
.app-shell .header {
  display: none !important;
}

/* The search bar sticky top needs to account for our new topbar height */
.app-shell #search_bar {
  top: var(--header-h);
}

/* Guest banner also shifts down */
.app-shell #__guest_banner__ {
  top: var(--header-h);
}

/* Move the injected header buttons into topbar via JS cloning —
   until JS runs, keep them invisible inside the hidden header */
#topbar_actions .header-icons-L,
#topbar_actions a {
  color: var(--app-theme-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 16px;
  transition: background var(--transition);
}
#topbar_actions .header-icons-L:hover,
#topbar_actions a:hover {
  background: #f0eef8;
  color: var(--app-theme-color);
}


/* ══════════════════════════════════════════════
   DETAIL PAGE TOPBAR — shared sticky header for standalone
   detail/edit pages (student-view.html, student-edit.html)
   ──────────────────────────────────────────────
   Was duplicated near-verbatim as inline <style> in both pages (one used
   --theme, the other --app-theme-color — both resolve to the same brand
   color); consolidated here as the single definition.
══════════════════════════════════════════════ */
.detail-page-wrap { max-width: 720px; margin: 0 auto; padding: 1rem; }
.detail-topbar {
  display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem;
  background: var(--app-theme-color, #2B2640); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.detail-topbar a {
  color: #fff; font-size: 1.25rem; text-decoration: none;
  padding: 6px 8px; display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; touch-action: manipulation;
}
.detail-topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; flex: 1; }

/* ── Bulk action bar (layout/positioning — see components/buttons.css for .bulk-bar-btn) ── */
/* ============================================================
   Bulk Operations  (pwa_v16_bulk)
   ──────────────────────────────────────────────
   Checkbox/indent/highlight rules now live on the shared .entity-card
   selector (see ENTITY CARD section above) so any future list page using
   the same card pattern inherits them automatically. Student's cards
   carry both `.student-card` (used by bulk-operations.js/student-actions.js
   JS selectors) and `.entity-card` (shared CSS hook) classes.
   ============================================================ */

/* ── Bulk action bar ── */
#bulk_action_bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 2px solid var(--app-theme-color, #1976d2);
  box-shadow: 0 -3px 16px rgba(0,0,0,0.15);
  z-index: 1051;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#bulk_action_bar.bulk-bar--visible {
  transform: translateY(0);
}

#bulk_bar_inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 4px;
}

#bulk_bar_count {
  color: var(--app-theme-color, #1976d2);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 72px;
}

#bulk_bar_actions {
  display: flex;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 1;
}

#bulk_bar_actions::-webkit-scrollbar { display: none; }

/* Pad list so bar doesn't obscure last card */
#bulk_action_bar.bulk-bar--visible ~ * #list_id,
body.bulk-active #list_id {
  padding-bottom: 88px;
}

/* Responsive: hide labels on very narrow screens */
@media (max-width: 360px) {
  .bulk-bar-btn { min-width: 40px; padding: 5px 5px; font-size: 10px; }
  .bulk-bar-btn i { font-size: 16px; }
  .bulk-btn-lbl { display: none; }
}


/* ── Pull-to-refresh / scroll shadow / anti-flicker shell behavior (js/app-polish.js) ── */
/* ── Pull to refresh ── */
#ptr_indicator {
  position: fixed;
  left: 0; right: 0;
  top: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  color: var(--app-theme-color);
  z-index: 850;
  pointer-events: none;
  transition: height .15s ease;
}
#ptr_indicator .ptr-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid #e2dff0;
  border-top-color: var(--app-theme-color);
}
#ptr_indicator.ptr-spin .ptr-spinner { animation: exportSpinPtr .6s linear infinite; }
@keyframes exportSpinPtr { to { transform: rotate(360deg); } }

/* ── Sticky header/search subtle shadow once scrolled ── */
.app-scrolled .topbar { box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.app-scrolled #search_bar { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* ── Anti layout-shift: reserve list space so header/search don't jump ── */
#list_id { min-height: 240px; }

/* ── Anti-flicker page reveal ── */
html.app-prep body { opacity: 0; }
html.app-ready body { opacity: 1; transition: opacity .18s ease; }

