:root{
  --app-bg:#f3f4f6;
  --card-bg:#ffffff;
  --border:#e5e7eb;
  --text:#111827;
  --muted:#6b7280;
  --primary:#2563eb;
  --primary-light:#eff6ff;
  --primary-dark:#1d4ed8;
  --sidebar-bg:#ffffff;
  --sidebar-link:#374151;
  --sidebar-active-bg:var(--primary-light);
  --sidebar-active-text:var(--primary-dark);
  --radius:14px;
  --shadow:0 4px 16px rgba(17,24,39,.07);
  --shadow-sm:0 1px 3px rgba(0,0,0,.06);
  --shadow-md:0 4px 12px rgba(0,0,0,.08);

  /* Semantic status colors -- for badges/alerts, kept separate from
     --primary so "this needs attention" never looks like "click me". */
  --success:#16a34a;
  --success-soft:#dcfce7;
  --warning:#d97706;
  --warning-soft:#fef3c7;
  --danger:#dc2626;
  --danger-soft:#fee2e2;

  /* Spacing scale -- use instead of one-off margin/padding values so new
     screens land on the same rhythm as everything else. */
  --space-1:4px;
  --space-2:8px;
  --space-3:12px;
  --space-4:16px;
  --space-5:24px;
  --space-6:32px;
}

html,body{height:100%;}
body{
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: var(--app-bg);
  color: var(--text);
  font-size: 0.9rem;
}

a{color:inherit;}
.page-subtitle{color:var(--muted); font-size:.9rem;}

/* ── Layout shell ─────────────────────────────────────────────────────────── */
.app-shell{
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-sidebar{
  width: 260px;
  min-width: 260px;
  flex-shrink: 0;
  padding: 14px 10px 14px 10px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}
.app-sidebar::-webkit-scrollbar{ width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb{ background: #e5e7eb; border-radius: 4px; }

/* ── Sidebar Search ── */
.sidebar-search-wrap{
  padding: 0 6px;
  margin-bottom: 10px;
  position: relative;
}
.sidebar-search-wrap i{
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: .8rem;
  pointer-events: none;
}
#sidebarSearch{
  padding-left: 30px !important;
  border-radius: 8px !important;
  font-size: .8rem;
  height: 32px;
  border: 1px solid var(--border);
  background: #f9fafb;
  width: 100%;
  outline: none;
  color: var(--text);
}
#sidebarSearch:focus{
  border-color: rgba(37,99,235,.4);
  box-shadow: 0 0 0 2px rgba(37,99,235,.1);
  background: #fff;
}
.nav-search-empty{
  font-size:.78rem; color:var(--muted);
  text-align:center; padding: 10px 0;
  display: none;
}

/* ── Brand ── */
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  transition: background .15s;
}
.brand:hover{background:#f9fafb;}
.brand-mark{
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  color: #fff;
  display:flex; align-items:center; justify-content:center;
  font-weight:700;
  font-size: .9rem;
  flex-shrink: 0;
}
.brand-name{font-weight:700; line-height:1.1; font-size: .92rem;}
.brand-sub{color:var(--muted); font-size:.78rem;}

/* ── Top-level section buttons (Operations / Finance / People / etc.) ── */
.nav-section-btn {
  display: flex; align-items: center; width: 100%;
  padding: 0.35rem 0.9rem; font-size: 0.69rem; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: #9ca3af;
  background: none; border: none; cursor: pointer; margin-top: 0.3rem;
  transition: color 0.15s;
}
.nav-section-btn:hover { color: #4b5563; }
body.dark-mode .nav-section-btn { color: #666; }
body.dark-mode .nav-section-btn:hover { color: #ccc; }
.nav-section-btn .chev { margin-left: auto; font-size: 0.6rem; transition: transform 0.2s; }
.nav-section-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

/* ── Sub-section buttons (Inventory / Procurement / etc. within Operations) ── */
.nav-sub-section-btn {
  display: flex; align-items: center; width: 100%;
  padding: 0.42rem 0.7rem 0.42rem 1rem;
  font-size: 0.78rem; font-weight: 600;
  color: var(--sidebar-link);
  background: none; border: none; cursor: pointer;
  border-radius: 10px;
  margin: 1px 4px;
  gap: 6px;
  transition: background .15s, color .15s;
}
.nav-sub-section-btn:hover { background: #f3f4f6; }
.nav-sub-section-btn .chev { margin-left: auto; font-size: 0.6rem; transition: transform 0.2s; color: #9ca3af; }
.nav-sub-section-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.nav-sub-section-btn[aria-expanded="true"] { color: var(--primary-dark); background: var(--primary-light); }
.nav-sub-section-btn i.module-icon { color: var(--muted); font-size: .78rem; }
.nav-sub-section-btn[aria-expanded="true"] i.module-icon { color: var(--primary-dark); }
body.dark-mode .nav-sub-section-btn { color: #ccc; }
body.dark-mode .nav-sub-section-btn:hover { background: #0f3460; }
body.dark-mode .nav-sub-section-btn[aria-expanded="true"] { background: #0f3460; color: #60a5fa; }

/* ── Nav links (leaves) ── */
.app-sidebar .nav-link {
  width: calc(100% - 8px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px 7px 14px;
  border-radius: 9px;
  color: var(--sidebar-link);
  text-decoration: none;
  margin: 1px 4px;
  font-weight: 500;
  font-size: .82rem;
  transition: background .12s, color .12s;
}
.app-sidebar .nav-link i { font-size: .78rem; color: #9ca3af; flex-shrink: 0; }
.app-sidebar .nav-link:hover { background: #f3f4f6; color: var(--text); }
.app-sidebar .nav-link:hover i { color: #6b7280; }
.app-sidebar .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}
.app-sidebar .nav-link.active i { color: var(--primary-dark); }

/* ── Nav sub-section indent ── */
.nav-sub { padding-left: 14px !important; }

/* ── Group label (smaller secondary divider) ── */
.nav-group-label {
  font-size: 0.62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: #d1d5db;
  padding: 0.55rem 1rem 0.15rem 1.5rem;
}
body.dark-mode .nav-group-label { color: #2a3a5a; }

.nav-divider { border-top: 1px solid #f3f4f6; margin: 0.4rem 10px; }
body.dark-mode .nav-divider { border-top-color: #1e2a4a; }

/* ── Quick Actions bar ── */
.quick-actions {
  padding: 2px 4px 10px;
}
.qa-label {
  font-size: 0.62rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: #d1d5db;
  padding: 0.3rem 0.5rem 0.25rem;
}
.qa-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.qa-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 8px 6px;
  border-radius: 9px; background: #f3f4f6;
  color: var(--sidebar-link); text-decoration: none;
  font-size: 0.69rem; font-weight: 500; line-height: 1.2;
  transition: background .12s, color .12s;
  text-align: center;
}
.qa-btn i { font-size: 1rem; color: var(--primary); }
.qa-btn:hover { background: var(--primary-light); color: var(--primary-dark); }
.qa-btn:hover i { color: var(--primary-dark); }
body.dark-mode .qa-btn { background: #0f3460; color: #ccc; }
body.dark-mode .qa-btn:hover { background: #1a4a80; color: #fff; }
body.dark-mode .qa-btn i { color: #60a5fa; }

/* ── Sidebar standalone home link ── */
.sidebar-home {
  font-size: 0.85rem !important;
  font-weight: 600 !important;
  margin: 2px 4px 2px !important;
}

/* ── Sidebar footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .small { font-size: .72rem; }
.sidebar-footer .fw-semibold { font-size: .82rem; }

/* ══════════════════════════════════════════════════════════════════════════
   MINI SIDEBAR RAIL + CONTEXT PANEL  (business/ERP org type only)
   ══════════════════════════════════════════════════════════════════════════ */

/* Shell wrapper that holds rail + panel side by side */
.app-sidebar-shell {
  display: flex;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

/* ── Icon Rail ── */
.sidebar-rail {
  width: 70px;
  min-width: 70px;
  background: #1e293b;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 8px;
  overflow: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
}

.rail-brand {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem;
  margin-bottom: 14px;
  flex-shrink: 0;
  text-decoration: none;
  transition: opacity .15s;
}
.rail-brand:hover { opacity: .85; }
.rail-brand img {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: inherit;
}

.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 58px;
  padding: 8px 4px;
  border-radius: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.6rem;
  font-weight: 500;
  line-height: 1.2;
  transition: background .15s, color .15s;
  margin: 1px 0;
  text-align: center;
  text-decoration: none;
}
.rail-btn i { font-size: 1.1rem; transition: color .15s; }
.rail-btn:hover { background: rgba(255,255,255,.09); color: #e2e8f0; }
.rail-btn:hover i { color: #e2e8f0; }
.rail-btn.active, .rail-btn.panel-active {
  background: rgba(37,99,235,.25);
  color: #93c5fd;
}
.rail-btn.active i, .rail-btn.panel-active i { color: #93c5fd; }

.rail-spacer { flex: 1; }

.rail-divider {
  width: 36px;
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 6px 0;
  flex-shrink: 0;
}

.rail-user {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.rail-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #334155;
  color: #cbd5e1;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 600;
}

/* ── Context Panel ── */
.sidebar-panel {
  width: 0;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .22s cubic-bezier(.4,0,.2,1), min-width .22s cubic-bezier(.4,0,.2,1);
  flex-shrink: 0;
}
.sidebar-panel.open {
  width: 240px;
  min-width: 240px;
}
body.dark-mode .sidebar-panel { background: #16213e; border-right-color: #0f3460; }

.sidebar-panel-header {
  display: flex;
  align-items: center;
  padding: 13px 12px 10px 14px;
  font-weight: 700;
  font-size: .82rem;
  color: #111827;
  border-bottom: 1px solid var(--border);
  min-width: 240px;
  gap: 7px;
  flex-shrink: 0;
}
.sidebar-panel-header i { color: var(--primary); font-size: .9rem; }
body.dark-mode .sidebar-panel-header { color: #e0e0e0; border-bottom-color: #0f3460; }

.panel-close-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  padding: 3px 5px;
  border-radius: 5px;
  font-size: .85rem;
  display: flex; align-items: center;
  transition: background .12s, color .12s;
}
.panel-close-btn:hover { background: #f3f4f6; color: #374151; }
body.dark-mode .panel-close-btn:hover { background: #0f3460; color: #e0e0e0; }

.sidebar-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0 12px;
  min-width: 240px;
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}
.sidebar-panel-body::-webkit-scrollbar { width: 3px; }
.sidebar-panel-body::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 3px; }

/* Panel content blocks (one per module) */
.panel-content { display: none; }
.panel-content.active { display: block; }

/* Panel links */
.panel-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 14px;
  color: #374151;
  text-decoration: none;
  font-size: .81rem;
  font-weight: 500;
  border-radius: 8px;
  margin: 1px 6px;
  transition: background .12s, color .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-link i { font-size: .76rem; color: #9ca3af; flex-shrink: 0; }
.panel-link:hover { background: #f3f4f6; color: #111827; }
.panel-link:hover i { color: #6b7280; }
.panel-link.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.panel-link.active i { color: var(--primary-dark); }
body.dark-mode .panel-link { color: #ccc; }
body.dark-mode .panel-link:hover { background: #0f3460; color: #fff; }
body.dark-mode .panel-link.active { background: #0f3460; color: #60a5fa; }

/* Panel section label */
.panel-section {
  font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #d1d5db;
  padding: 0.55rem 14px 0.12rem;
}
body.dark-mode .panel-section { color: #2a3a5a; }

/* Collapsible panel groups -- a group of related panel-links under one
   clickable header, collapsed by default unless it contains the active
   page (see toggleNavGroup() in base.html). Keeps a long module's nav
   scannable at a glance instead of one long flat list. */
.panel-group { margin: 2px 6px; }
.panel-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: #9ca3af;
  cursor: pointer;
  user-select: none;
}
.panel-group-header:hover { background: #f3f4f6; color: #374151; }
.panel-group-header i:first-child { font-size: .76rem; width: 14px; text-align: center; flex-shrink: 0; }
.panel-group-header .chev { margin-left: auto; font-size: .65rem; transition: transform .15s; }
.panel-group.open .panel-group-header .chev { transform: rotate(90deg); }
.panel-group-items { display: none; }
.panel-group.open .panel-group-items { display: block; }
body.dark-mode .panel-group-header { color: #64748b; }
body.dark-mode .panel-group-header:hover { background: #0f3460; color: #e0e0e0; }

/* Panel divider */
.panel-divider { border-top: 1px solid #f3f4f6; margin: 4px 10px; }
body.dark-mode .panel-divider { border-top-color: #1e2a4a; }

/* Advanced items toggle */
.panel-advanced-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 14px;
  margin: 2px 6px;
  font-size: .78rem;
  color: #9ca3af;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  width: calc(100% - 12px);
  transition: background .12s, color .12s;
}
.panel-advanced-btn:hover { background: #f3f4f6; color: #6b7280; }
.panel-advanced-btn .chev { margin-left: auto; font-size: .58rem; transition: transform .2s; }
.panel-advanced-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.panel-advanced-collapse { padding-left: 10px; }
body.dark-mode .panel-advanced-btn { color: #555; }
body.dark-mode .panel-advanced-btn:hover { background: #0f3460; color: #94a3b8; }

/* ── Topbar Quick Actions (FAB group) ── */
.fab-group {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-right: 4px;
}
.fab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 7px;
  background: #f3f4f6;
  color: #374151;
  text-decoration: none;
  font-size: .88rem;
  transition: background .12s, color .12s;
  border: 1px solid var(--border);
  position: relative;
}
.fab-btn:hover { background: var(--primary-light); color: var(--primary); border-color: rgba(37,99,235,.3); }
body.dark-mode .fab-btn { background: #0f3460; color: #ccc; border-color: #1a4a80; }
body.dark-mode .fab-btn:hover { background: #1a4a80; color: #60a5fa; }

/* ── Main content area ────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.app-topbar {
  height: 58px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.topbar-title { font-weight: 600; color: #111827; font-size: .88rem; }
.topbar-spacer { flex: 1; }
.topbar-search {
  position: relative;
  width: min(420px, 45vw);
}
.topbar-search i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: .8rem;
}
.topbar-search input {
  padding-left: 34px !important;
  border-radius: 999px !important;
  border: 1px solid var(--border) !important;
  background: #f9fafb !important;
  font-size: .82rem !important;
  height: 34px;
}
.topbar-search input:focus {
  border-color: rgba(37,99,235,.4) !important;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1) !important;
  background: #fff !important;
}
.topbar-kbd {
  font-size: .65rem; background: #f1f3f5; border: 1px solid #ced4da;
  border-radius: 3px; padding: 1px 4px;
}
.topbar-user .btn { border-radius: 999px; font-size: .78rem; }
.app-topbar .btn-outline-secondary { border-color: var(--border); color: var(--muted); }
.app-topbar .btn-outline-secondary:hover { background: #f3f4f6; color: var(--text); border-color: #d1d5db; }

/* ── Content ──────────────────────────────────────────────────────────────── */
.app-content { padding: 22px 24px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--card-bg);
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card .card-body { padding: 18px; }
.card-header {
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0 !important;
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  font-weight: 600;
  font-size: .88rem;
  background: #fafafa;
}

/* ── Stat/KPI cards ─────────────────────────────────────────────────────── */
.stat-card { text-align: center; padding: 20px 16px; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 4px; }
.stat-card .stat-icon { font-size: 1.4rem; margin-bottom: 8px; opacity: .8; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table { --bs-table-bg: transparent; font-size: .84rem; }
.table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: .71rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  background: #fafafa;
  white-space: nowrap;
}
.table td, .table th { vertical-align: middle; padding: 10px 12px; }
.table-hover tbody tr { transition: background .1s; }
.table-hover tbody tr:hover { background: #f0f7ff !important; }
.table tbody tr:not(:last-child) { border-bottom: 1px solid #f3f4f6; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { font-weight: 500; font-size: .71rem; border-radius: 6px; padding: .28em .55em; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { border-radius: 8px; font-weight: 500; font-size: .83rem; transition: all .12s; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-secondary { border-width: 1px; }
.btn-sm { padding: .32rem .65rem; font-size: .78rem; }
.btn-lg { border-radius: 10px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 9px;
  border: 1px solid var(--border);
  font-size: .85rem;
}
.form-control:focus, .form-select:focus {
  border-color: rgba(37,99,235,.4);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-label { font-weight: 500; font-size: .82rem; margin-bottom: .35rem; }

.alert { border-radius: 10px; font-size: .85rem; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb { font-size: .78rem; margin-bottom: 14px; }
.breadcrumb-item + .breadcrumb-item::before { color: #d1d5db; }
.breadcrumb-item.active { color: var(--muted); }

/* ── Action bar ───────────────────────────────────────────────────────────── */
.action-bar {
  position: sticky;
  bottom: 10px;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  padding: 12px;
  background: rgba(243,244,246,.85);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  margin-top: 12px;
}
.action-bar > * { width: 100%; max-width: 1100px; }
.action-bar .btn { box-shadow: var(--shadow-sm); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { font-size: .82rem; gap: 2px; }
.page-link { border-radius: 8px !important; border-color: var(--border); color: var(--muted); padding: .35rem .6rem; }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }
.page-link:hover { background: #f3f4f6; color: var(--text); }

/* ── Page header helper ──────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h2, .page-header h3 { margin-bottom: 0; font-weight: 700; }

/* ── Dark Mode ─────────────────────────────────────────────────────────── */
body.dark-mode {
  --app-bg: #0f172a;
  --card-bg: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --sidebar-bg: #1e293b;
  --sidebar-link: #cbd5e1;
  --sidebar-active-bg: rgba(37,99,235,.2);
  --sidebar-active-text: #93c5fd;
  /* --primary-light defaults to #eff6ff (near-white) at :root -- it backs
     the active pill-tab, active sidebar/panel links, and several hover
     states, so left unredefined here every one of those renders as a
     white patch on the dark background (this is what "Academics" showing
     as a white pill on the student profile tabs actually was). */
  --primary-light: rgba(37,99,235,.18);
  --success-soft: rgba(22,163,74,.16);
  --warning-soft: rgba(217,119,6,.18);
  --danger-soft: rgba(220,38,38,.18);
  background-color: #0f172a !important;
  color: #e2e8f0 !important;
  /* Bootstrap 5.3's bg-*-subtle / text-*-emphasis utilities read these
     variables (that's the mechanism its own [data-bs-theme=dark] uses) --
     this app toggles dark mode via body.dark-mode instead, so without
     redefining them here every subtle-badge/callout across the app keeps
     its light-mode colors verbatim: near-white body text landing on a
     pale subtle background, or a dark emphasis color on a dark card. */
  --bs-primary-bg-subtle: rgba(37,99,235,.18);
  --bs-primary-text-emphasis: #93c5fd;
  --bs-secondary-bg-subtle: rgba(100,116,139,.2);
  --bs-secondary-text-emphasis: #cbd5e1;
  --bs-success-bg-subtle: rgba(22,163,74,.18);
  --bs-success-text-emphasis: #86efac;
  --bs-danger-bg-subtle: rgba(220,38,38,.18);
  --bs-danger-text-emphasis: #fca5a5;
  --bs-warning-bg-subtle: rgba(217,119,6,.18);
  --bs-warning-text-emphasis: #fcd34d;
  --bs-info-bg-subtle: rgba(6,182,212,.18);
  --bs-info-text-emphasis: #67e8f9;
  --bs-light-bg-subtle: #263245;
  --bs-light-text-emphasis: #e2e8f0;
  --bs-dark-bg-subtle: #0f172a;
  --bs-dark-text-emphasis: #cbd5e1;
}
/* Modals, toasts, and similar overlay chrome render outside the normal
   page flow but still inherit body.dark-mode's near-white text color, so
   without their own background override they show that text on
   Bootstrap's native white modal/toast background -- unreadable. */
body.dark-mode .modal-content { background-color: #1e293b; color: #e2e8f0; border-color: #334155; }
body.dark-mode .modal-header, body.dark-mode .modal-footer { border-color: #334155; }
body.dark-mode .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
body.dark-mode .toast { background-color: #1e293b; color: #e2e8f0; }
body.dark-mode .accordion-item { background-color: #1e293b; border-color: #334155; color: #e2e8f0; }
body.dark-mode .accordion-button { background-color: #1e293b; color: #e2e8f0; }
body.dark-mode .accordion-button:not(.collapsed) { background-color: #263245; color: #e2e8f0; }
body.dark-mode .popover { background-color: #1e293b; border-color: #334155; }
body.dark-mode .popover-body { color: #e2e8f0; }
body.dark-mode .card { background-color: #1e293b !important; border-color: #334155 !important; }
body.dark-mode .card-header { background-color: #263245 !important; color: #e2e8f0 !important; border-color: #334155 !important; }
body.dark-mode .table {
  /* Bootstrap 5.3's actual cell text comes from .table > :not(caption) > * > *,
     which reads --bs-table-color-state/-type/-color (falling through to
     --bs-table-color, which itself defaults to --bs-emphasis-color -- a
     near-black light-mode color) -- NOT the plain `color` below, which
     that more specific Bootstrap rule always wins over. Setting the plain
     property too covers any non-Bootstrap-variable text inside the table. */
  --bs-table-bg: transparent;
  --bs-table-color: #e2e8f0;
  color: #e2e8f0;
}
body.dark-mode .table thead th { background: #263245; color: #94a3b8; border-color: #334155; }
body.dark-mode .table-hover tbody tr:hover { background: rgba(37,99,235,.12) !important; }
body.dark-mode .table tbody tr { border-bottom-color: #2d3f55; }
body.dark-mode .form-control, body.dark-mode .form-select {
  background-color: #263245; color: #e2e8f0; border-color: #334155;
}
body.dark-mode .form-control::placeholder { color: #64748b; }
body.dark-mode aside { background-color: #1e293b !important; border-right-color: #334155 !important; }
body.dark-mode .app-topbar { background-color: #1e293b !important; border-bottom-color: #334155 !important; }
body.dark-mode .topbar-search input { background: #263245 !important; color: #e2e8f0; border-color: #334155 !important; }
body.dark-mode .topbar-search input:focus { background: #1e293b !important; border-color: rgba(37,99,235,.5) !important; }
body.dark-mode .topbar-search input::placeholder { color: #64748b; }
body.dark-mode .topbar-kbd { background: #0f172a; border-color: #334155; color: #94a3b8; }
body.dark-mode .badge.bg-light { background-color: #334155 !important; color: #e2e8f0 !important; }
body.dark-mode .list-group-item { background-color: #1e293b; color: #e2e8f0; border-color: #334155; }
body.dark-mode .list-group-item:hover { background-color: #263245; }
body.dark-mode .alert { border-color: #334155; }
body.dark-mode .alert-success { background: var(--success-soft); color: #86efac; border-color: rgba(22,163,74,.35); }
body.dark-mode .alert-danger { background: var(--danger-soft); color: #fca5a5; border-color: rgba(220,38,38,.35); }
body.dark-mode .alert-warning { background: var(--warning-soft); color: #fcd34d; border-color: rgba(217,119,6,.35); }
body.dark-mode .input-group-text { background-color: #263245; color: #e2e8f0; border-color: #334155; }
body.dark-mode .btn-outline-secondary { color: #94a3b8; border-color: #475569; }
body.dark-mode .app-topbar .btn-outline-secondary:hover { background: #263245 !important; color: #e2e8f0 !important; border-color: #475569 !important; }
body.dark-mode .text-muted { color: #94a3b8 !important; }
body.dark-mode .bg-light { background-color: #1e293b !important; }
body.dark-mode .nav-link { color: #cbd5e1; }
body.dark-mode .nav-link:hover { color: #f1f5f9; background-color: #263245; }
body.dark-mode .nav-link.active { background: rgba(37,99,235,.25); color: #93c5fd; }
body.dark-mode .nav-link.active i { color: #93c5fd; }
body.dark-mode .pill-tabs.nav-tabs .nav-link.active { color: #93c5fd; }
body.dark-mode .nav-link i { color: #64748b; }
body.dark-mode .nav-link:hover i { color: #94a3b8; }
body.dark-mode .page-link { background-color: #1e293b; border-color: #334155; color: #e2e8f0; }
body.dark-mode .dropdown-menu { background-color: #1e293b; border-color: #334155; }
body.dark-mode .dropdown-item { color: #e2e8f0; }
body.dark-mode .dropdown-item:hover { background-color: #263245; }
body.dark-mode .table-light { --bs-table-bg: #263245; }
body.dark-mode .table-warning { --bs-table-bg: rgba(217,119,6,.18); }
body.dark-mode .table-danger { --bs-table-bg: rgba(220,38,38,.18); }
body.dark-mode .table-success { --bs-table-bg: rgba(22,163,74,.18); }
/* The plain `color` above never reached actual cell text -- Bootstrap 5.3
   sets it per-cell via .table > :not(caption) > * > *, which each variant
   class feeds through its own --bs-table-color-type/-state chain, not a
   plain inherited color. Every variant here wants the same light-on-dark
   text, so override the real cell selector directly instead of chasing
   each variant's internal variable name. */
body.dark-mode .table > :not(caption) > * > * { color: #e2e8f0; }
body.dark-mode .card-header { background-color: #263245 !important; }
body.dark-mode #sidebarSearch { background: #263245; color: #e2e8f0; border-color: #334155; }
body.dark-mode #sidebarSearch:focus { border-color: rgba(37,99,235,.5); background: #1e293b; }
body.dark-mode .brand-mark { background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%); }
body.dark-mode .brand:hover { background: #263245; }

/* ── Profile header + pill tabs (Student Profile redesign) ──────────────── */
.profile-header{
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: var(--space-5); margin-bottom: var(--space-4);
}
.profile-avatar{
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; flex-shrink: 0;
}
.profile-kpi-strip{
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3);
  margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border);
}
.profile-kpi .label{ font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.profile-kpi .value{ font-size: 1.25rem; font-weight: 800; margin-top: 2px; }
.profile-kpi .sub{ font-size: .76rem; color: var(--muted); margin-top: 1px; }
.profile-kpi.warn .value{ color: var(--danger); }
@media (max-width: 700px){ .profile-kpi-strip{ grid-template-columns: 1fr 1fr; } }

.pill-tabs.nav-tabs{ border-bottom: 1px solid var(--border); gap: 4px; flex-wrap: nowrap; overflow-x: auto; }
.pill-tabs.nav-tabs .nav-link{
  border: none; border-radius: 10px 10px 0 0; color: var(--muted);
  font-weight: 600; font-size: .83rem; padding: 9px 14px; white-space: nowrap;
}
.pill-tabs.nav-tabs .nav-link.active{
  color: var(--primary); background: var(--primary-light); border-bottom: 2px solid var(--primary);
}
.pill-tabs.nav-tabs .nav-link .badge{ font-size: .68rem; }

/* ── Gradebook matrix (sticky header + first column, horizontal scroll) ─── */
.gradebook-wrap{
  overflow: auto; max-height: 75vh; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card-bg); box-shadow: var(--shadow-sm);
}
.gradebook-table{ border-collapse: separate; border-spacing: 0; font-size: .82rem; white-space: nowrap; }
.gradebook-table th, .gradebook-table td{ padding: 8px 12px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.gradebook-table thead th{
  position: sticky; top: 0; z-index: 2; background: var(--app-bg); color: var(--muted);
  font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; text-align: right;
  vertical-align: bottom;
}
.gradebook-table thead th.gb-student-col{ text-align: left; }
.gradebook-table .gb-assignment-title{ display: block; font-weight: 700; text-transform: none; letter-spacing: 0; color: var(--text); max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.gradebook-table .gb-assignment-meta{ display: block; font-weight: 600; color: var(--muted); font-size: .64rem; }
.gradebook-table td{ text-align: right; font-variant-numeric: tabular-nums; }
.gradebook-table .gb-student-col{
  position: sticky; left: 0; z-index: 1; background: var(--card-bg); text-align: left;
  font-weight: 600; min-width: 160px; box-shadow: 1px 0 0 var(--border);
}
.gradebook-table thead th.gb-student-col{ z-index: 3; background: var(--app-bg); }
.gradebook-table tbody tr:hover td{ background: var(--primary-light); }
.gradebook-table tbody tr:hover .gb-student-col{ background: var(--primary-light); }
.gradebook-table .gb-total-col{ font-weight: 700; background: var(--app-bg); }
.gradebook-table tbody tr:hover .gb-total-col{ background: var(--primary-light); }
.gradebook-table .gb-muted{ color: var(--muted); }
.gradebook-pct{ font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.gradebook-pct.good{ background: var(--success-soft); color: var(--success); }
.gradebook-pct.mid{ background: var(--warning-soft); color: var(--warning); }
.gradebook-pct.low{ background: var(--danger-soft); color: var(--danger); }

/* ── Printable receipt sheet ──────────────────────────────────────────────
   Shared visual language for every printable receipt (fee payment,
   subscription, donation, pharmacy sale/dispensing, credit note, giving
   statement) -- one canonical design instead of each document inventing
   its own card/table/print rules. Deliberately mirrors report_card.html's
   paper-document look (cream sheet, serif letterhead, double-rule divider)
   so every official printable document in the app reads as one family,
   and always renders as a physical paper document regardless of the
   viewer's light/dark theme -- these are meant to be printed and handed
   to someone, not read on a dashboard. */
.receipt-sheet {
  background: #fdfcf8;
  color: #1a1a1a;
  border: 1px solid #c9c2b0;
  border-radius: 4px;
  padding: 40px 48px 32px;
  font-family: -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  max-width: 680px;
  margin: 0 auto;
}
.receipt-letterhead {
  display: flex; align-items: center; gap: 18px;
  padding-bottom: 18px; margin-bottom: 18px;
  border-bottom: 3px double #2a2f38;
}
.receipt-crest { width: 56px; height: 56px; flex-shrink: 0; object-fit: contain; }
.receipt-crest-spacer { width: 56px; flex-shrink: 0; }
.receipt-letterhead-text { flex: 1; text-align: center; }
.receipt-org-name {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 22px; font-weight: 700; letter-spacing: .01em; margin: 0 0 2px; color: #2a2f38;
}
.receipt-org-meta { font-size: 11px; color: #55524a; margin: 0; }
.receipt-doc-title {
  text-align: center; font-family: Georgia, serif; font-size: 13px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: #2a2f38; margin: 0 0 18px;
  border-top: 1px solid #c9c2b0; position: relative;
}
.receipt-doc-title span { background: #fdfcf8; padding: 0 14px; position: relative; top: -9px; }
.receipt-refdate { display: flex; justify-content: space-between; margin-bottom: 18px; }
.receipt-label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #55524a; margin-bottom: 2px; }
.receipt-value { font-weight: 600; font-variant-numeric: tabular-nums; color: #2a2f38; }
.receipt-value.mono { font-family: "SFMono-Regular", Consolas, monospace; }
.receipt-rule { border: none; border-top: 1px solid #c9c2b0; margin: 14px 0; }
.receipt-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 13.5px; }
.receipt-row .receipt-row-label { color: #55524a; }
.receipt-row .receipt-row-value { font-weight: 600; text-align: right; color: #2a2f38; }
table.receipt-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 14px 0; }
table.receipt-table thead th {
  background: #e7ecf3; color: #2a2f38; font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 700; padding: 7px 10px; border: 1px solid #c9c2b0; text-align: left;
}
table.receipt-table thead th.num { text-align: right; }
table.receipt-table tbody td { padding: 6px 10px; border: 1px solid #c9c2b0; font-variant-numeric: tabular-nums; }
table.receipt-table tbody td.num { text-align: right; }
table.receipt-table tbody tr:nth-child(even) { background: #f6f4ee; }
.receipt-total-row {
  display: flex; justify-content: space-between; padding: 10px 0; margin-top: 6px;
  border-top: 2px solid #2a2f38; font-weight: 700; font-size: 16px; color: #2a2f38;
}
.receipt-words {
  font-size: 11.5px; font-style: italic; color: #55524a; margin: 10px 0 4px;
  padding-top: 8px; border-top: 1px dotted #c9c2b0;
}
.receipt-footer-grid { display: flex; justify-content: space-between; gap: 20px; margin-top: 28px; font-size: 11px; color: #55524a; }
.receipt-sig-line { padding-top: 8px; border-top: 1px dotted #c9c2b0; min-width: 200px; text-align: center; }
.receipt-stamp-note { margin-top: 16px; font-size: 10px; font-style: italic; color: #55524a; text-align: center; }
@media print {
  .receipt-sheet { box-shadow: none; border: none; padding: 0.3in; max-width: 100%; }
}
@media (max-width: 640px) {
  .receipt-sheet { padding: 24px 18px 20px; }
  .receipt-letterhead { flex-direction: column; text-align: center; }
  .receipt-crest-spacer { display: none; }
  .receipt-refdate { flex-direction: column; gap: 8px; }
  .receipt-footer-grid { flex-direction: column; gap: 14px; }
}

/* ── Back to top ──────────────────────────────────────────────────────── */
#scroll-top-btn {
  position: fixed;
  bottom: 5.5rem;
  right: 1.25rem;
  z-index: 1049;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--card-bg, #fff);
  color: var(--text, #333);
  border: 1px solid var(--border, #d1d5db);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .15s, transform .15s;
}
#scroll-top-btn.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
#scroll-top-btn:hover { background: var(--primary-light, #eef2ff); }
@media (max-width: 767.98px) { #scroll-top-btn { bottom: 4.75rem; right: 1rem; } }

/* ── Print styles ──────────────────────────────────────────────────────── */
@media print {
  aside, .topbar, nav.navbar, .sidebar-footer,
  .btn, .pagination, .no-print,
  #ai-copilot-toggle, #ai-copilot-panel { display: none !important; }
  .app-content { margin: 0 !important; padding: 0 !important; }
  body { background: white !important; color: black !important; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; }
  a[href]:after { content: none !important; }
  .badge { border: 1px solid #999; }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 767.98px){
  .app-content{ padding: 14px; }
  .app-topbar{ display: none; }
}
@media (min-width: 768px){
  .offcanvas-backdrop{ display: none !important; }
}
