/* ====================================================================
   School Connect — Shared Stylesheet (Gen v7)
   Single source of truth used by every page in the platform.
   Fixes D-09 (was: each page inlined ~10KB of duplicated CSS).
   ==================================================================== */

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #818cf8;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --dark: #0f172a;
  --gray-900: #1e293b;
  --gray-800: #334155;
  --gray-700: #475569;
  --gray-600: #64748b;
  --gray-500: #94a3b8;
  --gray-400: #cbd5e1;
  --gray-300: #e2e8f0;
  --gray-200: #f1f5f9;
  --gray-100: #f8fafc;
  --white: #ffffff;
  --gradient: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
  --gradient-dark: linear-gradient(135deg, #3730a3 0%, #0891b2 100%);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  --shadow-xl: 0 25px 50px -12px rgba(0,0,0,0.25);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode variables */
[data-theme="dark"] {
  --dark: #f8fafc;
  --gray-900: #f1f5f9;
  --gray-800: #e2e8f0;
  --gray-700: #cbd5e1;
  --gray-600: #94a3b8;
  --gray-500: #64748b;
  --gray-400: #475569;
  --gray-300: #334155;
  --gray-200: #1e293b;
  --gray-100: #0f172a;
  --white: #0f172a;
  background: var(--gray-100);
  color: var(--gray-800);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font, 'Inter'), -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--white);
  color: var(--gray-900);
  line-height: 1.6;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; height: auto; display: block; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }

input, textarea, select { font-family: inherit; font-size: 1rem; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* ===== Navigation ===== */
.nav {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 1000;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  transition: var(--transition);
}
[data-theme="dark"] .nav { background: rgba(15,23,42,0.92); border-bottom-color: var(--gray-300); }
.nav-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 70px; }
.nav-logo { display: flex; align-items: center; gap: 10px; color: var(--dark); font-weight: 700; font-size: 1.2rem; }
.nav-logo img { width: 40px; height: 40px; border-radius: 10px; }
.nav-links { display: flex; align-items: center; gap: 6px; list-style: none; }
.nav-links a { color: var(--gray-700); font-size: 0.92rem; font-weight: 500; padding: 8px 14px; border-radius: 8px; transition: var(--transition); }
.nav-links a:hover { background: var(--gray-100); color: var(--primary); }
.nav-links a.active { background: rgba(79,70,229,0.1); color: var(--primary); }
.nav-links .btn-primary { background: var(--primary); color: white; padding: 10px 22px; border-radius: 10px; font-weight: 600; }
.nav-links .btn-primary:hover { background: var(--primary-dark); color: white; }
.mobile-toggle { display: none; padding: 8px; color: var(--gray-700); }
.mobile-toggle svg { width: 24px; height: 24px; }

/* ===== Hero ===== */
.hero { padding: 140px 24px 80px; text-align: center; position: relative; background: linear-gradient(180deg, #f8faff 0%, var(--white) 100%); overflow: hidden; }
.hero::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 0%, rgba(79,70,229,0.08) 0%, transparent 70%); pointer-events: none; }
.hero-badge { display: inline-flex; align-items: center; gap: 8px; background: linear-gradient(135deg, rgba(79,70,229,0.08) 0%, rgba(6,182,212,0.08) 100%); border: 1px solid rgba(79,70,229,0.15); padding: 8px 20px; border-radius: 50px; font-size: 0.85rem; font-weight: 600; color: var(--primary); margin-bottom: 24px; }
.hero h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 900; color: var(--dark); line-height: 1.1; margin-bottom: 20px; max-width: 900px; margin-left: auto; margin-right: auto; }
.hero h1 .highlight { background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.hero-sub { font-size: 1.2rem; color: var(--gray-600); max-width: 720px; margin: 0 auto 40px; line-height: 1.7; }
.hero-actions { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; margin-bottom: 60px; }
.btn-hero { display: inline-flex; align-items: center; gap: 10px; padding: 16px 36px; border-radius: 14px; font-size: 1.05rem; font-weight: 700; transition: var(--transition); }
.btn-hero-primary { background: var(--gradient); color: white; box-shadow: 0 8px 24px rgba(79,70,229,0.35); }
.btn-hero-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(79,70,229,0.45); color: white; }
.btn-hero-secondary { background: white; color: var(--gray-800); border: 2px solid var(--gray-200); }
.btn-hero-secondary:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }

/* ===== Section ===== */
.section { padding: 80px 24px; }
.section-head { text-align: center; margin-bottom: 60px; }
.section-eyebrow { display: inline-block; padding: 6px 16px; background: rgba(79,70,229,0.08); color: var(--primary); border-radius: 50px; font-size: 0.85rem; font-weight: 700; margin-bottom: 16px; letter-spacing: 0.5px; }
.section-title { font-size: clamp(1.8rem, 4vw, 2.8rem); font-weight: 900; color: var(--dark); line-height: 1.2; margin-bottom: 16px; }
.section-sub { font-size: 1.1rem; color: var(--gray-600); max-width: 700px; margin: 0 auto; }

/* ===== Cards / Grids ===== */
.grid { display: grid; gap: 24px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: white; border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow); border: 1px solid var(--gray-200); transition: var(--transition); }
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card h3 { font-size: 1.2rem; font-weight: 800; color: var(--dark); margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.card p { color: var(--gray-700); font-size: 0.95rem; line-height: 1.6; }
.card-icon { font-size: 2.2rem; margin-bottom: 12px; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 50px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.tag-new { background: rgba(16,185,129,0.12); color: var(--success); }
.tag-pop { background: rgba(245,158,11,0.12); color: var(--warning); }
.tag-core { background: rgba(79,70,229,0.12); color: var(--primary); }
.tag-enterprise { background: rgba(217,70,239,0.12); color: #c026d3; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 10px; font-weight: 600; font-size: 0.95rem; transition: var(--transition); border: 1px solid transparent; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); }
.btn-secondary:hover { background: var(--gray-200); color: var(--dark); }
.btn-outline { background: transparent; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: 12px; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; font-size: 0.9rem; color: var(--gray-700); margin-bottom: 6px; }
.form-input, .form-textarea, .form-select { width: 100%; padding: 12px 16px; border: 1.5px solid var(--gray-300); border-radius: 10px; background: white; color: var(--gray-900); transition: var(--transition); font-size: 0.95rem; }
.form-input:focus, .form-textarea:focus, .form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,70,229,0.12); }
.form-textarea { resize: vertical; min-height: 100px; }
.form-help { font-size: 0.82rem; color: var(--gray-500); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 4px; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--gray-200); }
table { width: 100%; border-collapse: collapse; }
th { padding: 14px 16px; background: var(--gray-100); text-align: left; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray-600); border-bottom: 2px solid var(--gray-200); }
td { padding: 14px 16px; border-bottom: 1px solid var(--gray-200); font-size: 0.92rem; color: var(--gray-800); }
tbody tr:hover { background: var(--gray-100); }

/* ===== Badges & Status ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 50px; font-size: 0.75rem; font-weight: 700; }
.badge-success { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.12); color: var(--info); }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.6); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(8px); }
.modal-backdrop.show { display: flex; }
.modal { background: white; border-radius: var(--radius-xl); max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-xl); }
.modal-header { padding: 24px 28px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 1.3rem; font-weight: 800; color: var(--dark); }
.modal-close { background: var(--gray-100); border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; color: var(--gray-700); }
.modal-close:hover { background: var(--gray-200); }
.modal-body { padding: 28px; }
.modal-footer { padding: 20px 28px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 12px; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 90px; right: 20px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: white; padding: 14px 20px; border-radius: var(--radius); box-shadow: var(--shadow-lg); border-left: 4px solid var(--primary); min-width: 280px; max-width: 400px; animation: slideIn 0.3s ease; }
.toast-success { border-left-color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-title { font-weight: 700; font-size: 0.92rem; color: var(--dark); margin-bottom: 2px; }
.toast-msg { font-size: 0.85rem; color: var(--gray-700); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(120%); opacity: 0; } }

/* ===== Stats ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 20px; margin-bottom: 40px; }
.stat-card { background: white; padding: 24px; border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid var(--gray-200); text-align: center; }
.stat-value { font-size: 2.2rem; font-weight: 900; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.stat-label { font-size: 0.78rem; color: var(--gray-600); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; font-weight: 600; }

/* ===== Footer ===== */
.footer { background: var(--dark); color: var(--gray-300); padding: 60px 24px 30px; margin-top: 80px; }
[data-theme="dark"] .footer { background: #020617; }
.footer-grid { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 40px; margin-bottom: 40px; }
.footer-brand h4 { color: white; font-size: 1.3rem; margin-bottom: 12px; }
.footer-brand p { font-size: 0.9rem; line-height: 1.7; opacity: 0.8; }
.footer h5 { color: white; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; font-weight: 700; }
.footer ul { list-style: none; }
.footer ul li { margin-bottom: 8px; }
.footer a { color: var(--gray-400); font-size: 0.9rem; transition: var(--transition); }
.footer a:hover { color: white; }
.footer-bottom { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 24px; text-align: center; font-size: 0.85rem; opacity: 0.7; }

/* ===== Notification Bell ===== */
.notif-bell { position: relative; background: var(--gray-100); border-radius: 50%; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: var(--transition); }
.notif-bell:hover { background: var(--gray-200); }
.notif-bell svg { width: 20px; height: 20px; color: var(--gray-700); }
.notif-badge { position: absolute; top: -2px; right: -2px; background: var(--danger); color: white; font-size: 0.65rem; font-weight: 700; border-radius: 50%; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; padding: 0 4px; border: 2px solid white; }
.notif-dropdown { position: fixed; top: 72px; right: 18px; left: auto; background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); width: min(420px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 92px)); overflow-y: auto; border: 1px solid var(--gray-200); display: none; z-index: 20000; text-align:left; }
.notif-dropdown.show { display: block; }
.notif-item { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); cursor: pointer; transition: var(--transition); }
.notif-item:hover { background: var(--gray-100); }
.notif-item-title { font-weight: 700; color: var(--dark); font-size: 0.92rem; margin-bottom: 4px; }
.notif-item-msg { font-size: 0.85rem; color: var(--gray-700); }
.notif-item-time { font-size: 0.75rem; color: var(--gray-500); margin-top: 6px; }

/* ===== PWA Install Banner ===== */
.pwa-install { position: fixed; bottom: 20px; left: 20px; right: 20px; max-width: 480px; background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); padding: 20px; z-index: 2500; border: 2px solid var(--primary); display: none; animation: slideUp 0.4s ease; }
[data-theme="dark"] .pwa-install { background: var(--gray-200); }
.pwa-install.show { display: block; }
.pwa-install-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.pwa-install-icon { width: 48px; height: 48px; flex-shrink: 0; }
.pwa-install-title { font-weight: 800; color: var(--dark); font-size: 1.05rem; margin-bottom: 4px; }
.pwa-install-msg { font-size: 0.88rem; color: var(--gray-700); }
.pwa-install-actions { display: flex; gap: 10px; margin-top: 12px; }
.pwa-install-actions button { flex: 1; }
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== Voting Cards ===== */
.vote-card { background: white; border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); border: 1px solid var(--gray-200); transition: var(--transition); cursor: pointer; }
.vote-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.vote-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }
.vote-candidate-photo { width: 80px; height: 80px; border-radius: 50%; background: var(--gradient); display: flex; align-items: center; justify-content: center; color: white; font-size: 2rem; font-weight: 800; margin: 0 auto 16px; }
.vote-candidate-name { text-align: center; font-weight: 800; color: var(--dark); font-size: 1.05rem; margin-bottom: 4px; }
.vote-candidate-info { text-align: center; font-size: 0.85rem; color: var(--gray-600); }
.vote-progress { background: var(--gray-200); height: 8px; border-radius: 4px; overflow: hidden; margin-top: 12px; }
.vote-progress-bar { background: var(--gradient); height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.vote-percent { text-align: center; font-weight: 700; color: var(--primary); margin-top: 6px; font-size: 0.9rem; }

/* ===== Animations ===== */
.fade-in { animation: fadeIn 0.5s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .nav-links { display: none; position: absolute; top: 70px; left: 0; right: 0; background: white; flex-direction: column; padding: 20px; border-bottom: 1px solid var(--gray-200); box-shadow: var(--shadow-lg); }
  [data-theme="dark"] .nav-links { background: var(--gray-200); }
  .nav-links.show { display: flex; }
  .nav-links a { width: 100%; padding: 12px 16px; }
  .mobile-toggle { display: flex; }
  .hero { padding: 110px 24px 60px; }
  .section { padding: 60px 24px; }
  .footer-grid { grid-template-columns: 1fr; gap: 30px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .pwa-install { left: 10px; right: 10px; }
  .notif-dropdown { right: 12px; left: 12px; width: auto; max-width: none; top: 64px; }
  /* update v4: touch-friendly + scalable previews on phones */
  .btn { min-height: 44px; }                 /* comfortable tap targets */
  .form-input, .form-select { font-size: 16px; min-height: 44px; }  /* prevents iOS zoom */
  .modal, .modal-content { width: 96vw !important; max-width: 96vw !important; }
  .sc-idcard, .sc-flyer, .sc-cert { max-width: 94vw !important; }
  .sc-flyer { transform-origin: top center; }
  table { font-size: 0.85rem; }
}
@media (max-width: 480px) {
  .app-content { padding: 12px; }
  .sc-idcard { width: 92vw !important; }
}

/* ===== Print ===== */
@media print {
  .nav, .footer, .pwa-install, .notif-bell, .toast-container, .btn, .modal-backdrop { display: none !important; }
  body { background: white; color: black; }
  .card, .modal { box-shadow: none; border: 1px solid #ccc; }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* =====================================================================
   APP SHELL — logged-in dashboard layout (sidebar / topnav / cards)
   These classes were previously missing, causing the disorganised UI
   after login. This block styles the full authenticated experience.
   ===================================================================== */

.app-layout { display: flex; min-height: 100vh; background: var(--gray-100); }

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: 250px; flex-shrink: 0; background: var(--white);
  border-right: 1px solid var(--gray-300);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.app-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px; border-bottom: 1px solid var(--gray-300);
}
.app-brand img { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; flex-shrink: 0; background: var(--gray-100); }
.app-brand strong { display: block; font-size: 0.95rem; font-weight: 800; color: var(--dark); line-height: 1.2; }

.app-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; flex: 1; }
.app-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  color: var(--gray-700); text-decoration: none;
  font-size: 0.9rem; font-weight: 600; line-height: 1;
  transition: var(--transition); white-space: nowrap;
}
.app-nav a:hover { background: var(--gray-200); color: var(--primary); }
.app-nav a.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.app-nav-icon {
  width: 24px; min-width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem; flex-shrink: 0;
}

/* ---------- Main area ---------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; background: var(--white);
  border-bottom: 1px solid var(--gray-300);
  position: sticky; top: 0; z-index: 30;
}
.app-page-title { font-size: 1.25rem; font-weight: 800; color: var(--dark); margin: 0; }
.app-content { padding: 24px; flex: 1; max-width: 1280px; width: 100%; }

/* ---------- Layout variants ---------- */
/* Top-navigation variant: nav becomes a horizontal bar on top */
.app-layout.topnav { flex-direction: column; }
.app-layout.topnav .app-sidebar {
  width: 100%; height: auto; position: sticky; top: 0;
  flex-direction: row; align-items: center; overflow-x: auto; overflow-y: hidden;
  border-right: none; border-bottom: 1px solid var(--gray-300);
}
.app-layout.topnav .app-brand { border-bottom: none; border-right: 1px solid var(--gray-300); }
.app-layout.topnav .app-nav { flex-direction: row; flex: 1; padding: 8px; gap: 4px; }
.app-layout.topnav .app-nav a { flex-direction: column; gap: 4px; font-size: 0.7rem; padding: 8px 12px; text-align: center; }
.app-layout.topnav .app-sidebar > div:last-child { display: none; }

/* Card-hub variant: same sidebar, but content uses big cards (handled by markup) */
.app-layout.cards .app-content .stats-grid { margin-bottom: 28px; }

/* V4 layout variants — sidebar width overrides + nav grid layout for long labels */
.app-layout.sidebar .app-sidebar { width: 286px; }
.app-layout.topnav, .app-layout.cardhub, .app-layout.mega-menu, .app-layout.tabbed, .app-layout.dashboard-pro { flex-direction: column; }
.app-layout.topnav .app-sidebar, .app-layout.cardhub .app-sidebar, .app-layout.mega-menu .app-sidebar, .app-layout.tabbed .app-sidebar, .app-layout.dashboard-pro .app-sidebar { width: 100%; height: auto; max-height: 210px; position: sticky; top: 0; flex-direction: row; align-items: stretch; overflow: hidden; border-right: none; border-bottom: 1px solid var(--gray-300); }
.app-layout.topnav .app-brand, .app-layout.cardhub .app-brand, .app-layout.mega-menu .app-brand, .app-layout.tabbed .app-brand, .app-layout.dashboard-pro .app-brand { width: 260px; min-width: 260px; border-bottom: none; border-right: 1px solid var(--gray-300); }
.app-layout.topnav .app-nav, .app-layout.cardhub .app-nav, .app-layout.mega-menu .app-nav, .app-layout.tabbed .app-nav, .app-layout.dashboard-pro .app-nav { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(116px, 150px); overflow-x: auto; overflow-y: hidden; padding: 10px; align-items: center; }
.app-layout.topnav .app-nav a, .app-layout.cardhub .app-nav a, .app-layout.mega-menu .app-nav a, .app-layout.tabbed .app-nav a, .app-layout.dashboard-pro .app-nav a { display: flex; flex-direction: column; gap: 4px; min-height: 68px; padding: 8px 10px; font-size: .75rem; text-align: center; justify-content: center; }
.app-layout.topnav .app-nav-icon, .app-layout.cardhub .app-nav-icon, .app-layout.mega-menu .app-nav-icon, .app-layout.tabbed .app-nav-icon, .app-layout.dashboard-pro .app-nav-icon { margin: auto; }
.app-layout.compact .app-sidebar, .app-layout.dock .app-sidebar { width: 224px; }
.app-layout.expanded .app-sidebar { width: 330px; }
.app-layout.minimalist .app-sidebar { box-shadow: none; }
.app-layout.floating .app-sidebar { margin: 14px; border-radius: 22px; height: calc(100vh - 28px); border: 1px solid var(--gray-300); }
.app-layout.split-view .app-content, .app-layout.grid-master .app-content, .app-layout.masonry .app-content { max-width: 1500px; }
.app-layout.vertical-hub .app-sidebar { width: 300px; }

/* Nav grid layout — supports long text labels on all layouts */
.app-nav a { display: grid !important; grid-template-columns: 32px minmax(0, 1fr) !important; align-items: center !important; gap: 10px !important; }
.app-nav-icon { width: 32px !important; min-width: 32px !important; height: 32px !important; }

/* Responsive sidebar drawer */
@media (max-width: 900px) {
  .app-sidebar, .app-layout.floating .app-sidebar { position: fixed !important; left: 0; top: 0; bottom: 0; width: min(86vw, 310px) !important; height: 100vh !important; margin: 0 !important; border-radius: 0 !important; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); z-index: 100; }
  .app-sidebar.open { transform: translateX(0); }
  .app-layout.topnav .app-sidebar, .app-layout.cardhub .app-sidebar, .app-layout.mega-menu .app-sidebar, .app-layout.tabbed .app-sidebar, .app-layout.dashboard-pro .app-sidebar { position: sticky; transform: none; width: 100%; height: auto; max-height: none; flex-direction: row; border-right: none; border-bottom: 1px solid var(--gray-300); }
  .app-layout.topnav .app-nav, .app-layout.cardhub .app-nav, .app-layout.mega-menu .app-nav, .app-layout.tabbed .app-nav, .app-layout.dashboard-pro .app-nav { display: flex; flex-direction: column; overflow-y: auto; }
  .app-layout.topnav .app-nav a, .app-layout.cardhub .app-nav a, .app-layout.mega-menu .app-nav a, .app-layout.tabbed .app-nav a, .app-layout.dashboard-pro .app-nav a { display: grid; grid-template-columns: 32px minmax(0, 1fr); min-height: 42px; }
  .app-topbar .mobile-toggle { display: inline-flex !important; align-items: center; justify-content: center; background: var(--gray-100); border: 1px solid var(--gray-300); border-radius: 10px; width: 40px; height: 40px; font-size: 1.2rem; cursor: pointer; }
  .user-chip { max-width: 150px; overflow: hidden; }
  .user-chip strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
}
@media (min-width: 901px) {
  .app-topbar .mobile-toggle { display: none !important; }
}

/* ---------- Dashboard cards & tables polish ---------- */
.app-content .card { margin-bottom: 20px; }
.app-content .card h3 { font-size: 1.05rem; font-weight: 800; color: var(--dark); margin-bottom: 6px; }
.app-content .grid { display: grid; gap: 20px; }
.app-content .grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.app-content .grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--gray-300); }
.table-wrap table { width: 100%; border-collapse: collapse; min-width: 480px; background: var(--white); }
.table-wrap th { text-align: left; padding: 12px 14px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gray-600); background: var(--gray-100); border-bottom: 1px solid var(--gray-300); }
.table-wrap td { padding: 12px 14px; font-size: 0.9rem; color: var(--gray-800); border-bottom: 1px solid var(--gray-200); }
.table-wrap tr:last-child td { border-bottom: none; }
.pulse { color: var(--gray-500); }

/* ---------- Dark mode for the app shell ---------- */
[data-theme="dark"] .app-layout { background: #0b1220; }
[data-theme="dark"] .app-sidebar,
[data-theme="dark"] .app-topbar { background: #0f172a; border-color: #1e293b; }
[data-theme="dark"] .app-brand { border-color: #1e293b; }
[data-theme="dark"] .app-brand strong,
[data-theme="dark"] .app-page-title { color: #e2e8f0; }
[data-theme="dark"] .app-nav a { color: #94a3b8; }
[data-theme="dark"] .app-nav a:hover { background: #1e293b; color: #fff; }
[data-theme="dark"] .app-content .card { background: #0f172a; border-color: #1e293b; }
[data-theme="dark"] .table-wrap, [data-theme="dark"] .table-wrap table { background: #0f172a; border-color: #1e293b; }
[data-theme="dark"] .table-wrap th { background: #111c30; color: #94a3b8; }
[data-theme="dark"] .table-wrap td { color: #cbd5e1; border-color: #1e293b; }

/* ---------- High-contrast accessibility mode (toggled by enterprise.js) ---------- */
body.sc-high-contrast { background: #fff; }
body.sc-high-contrast .app-nav a,
body.sc-high-contrast .app-page-title,
body.sc-high-contrast .table-wrap td { color: #000 !important; }
body.sc-high-contrast .app-nav a.active { background: #000 !important; color: #fff !important; }
body.sc-high-contrast .card,
body.sc-high-contrast .table-wrap { border: 2px solid #000 !important; }

/* ---------- Responsive: sidebar becomes a slide-in drawer ---------- */
@media (max-width: 900px) {
  .app-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
    transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-layout.topnav .app-sidebar { position: sticky; transform: none; }
  .app-content { padding: 16px; }
}
@media (min-width: 901px) {
  .app-topbar .mobile-toggle { display: none; }
}
@media (max-width: 900px) {
  .app-topbar .mobile-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--gray-100); border: 1px solid var(--gray-300);
    border-radius: 8px; width: 40px; height: 40px; font-size: 1.2rem; cursor: pointer;
  }
}

/* Generated app-shell nav safety: restricted modules remain visible instead of disappearing. */
.app-nav a.nav-locked { opacity: .62; }
.app-nav a.nav-locked .app-nav-icon { filter: grayscale(.35); }
.app-nav a.nav-locked::after { content: '🔒'; font-size: .72rem; opacity: .65; justify-self: end; }
.app-nav a.nav-locked.active { opacity: 1; }

/* V4 professional visual system: calmer enterprise palette, stronger typography, safer contrast. */
:root {
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #0f172a;
  --muted-ink: #475569;
  --ring: rgba(37, 99, 235, .18);
}
body { letter-spacing: -0.01em; background: linear-gradient(180deg,#f8fafc 0%,#eef2f7 100%); }
.app-layout { background: linear-gradient(180deg,#f8fafc 0%,#eef2f7 100%) !important; }
.app-sidebar { background: linear-gradient(180deg,#ffffff 0%,#f8fafc 100%) !important; border-right: 1px solid #dbe3ef !important; }
.app-brand strong, .app-page-title, .card h3 { letter-spacing: -0.025em; }
.app-nav a { color:#334155 !important; }
.app-nav a:hover { background:#eaf2ff !important; color:var(--primary) !important; }
.app-nav a.active { background:linear-gradient(135deg,var(--primary),var(--accent)) !important; color:#fff !important; }
.card, .stat-card { background:rgba(255,255,255,.96) !important; border:1px solid #dde7f3 !important; box-shadow:0 12px 30px rgba(15,23,42,.07) !important; }
.btn-primary { background:linear-gradient(135deg,var(--primary),var(--accent)) !important; border:0 !important; box-shadow:0 10px 22px rgba(37,99,235,.18); }
.btn-outline { background:#fff !important; border-color:#cbd5e1 !important; }
.form-input:focus, .form-select:focus, .form-textarea:focus { box-shadow:0 0 0 4px var(--ring) !important; }
.table-wrap { background:#fff; box-shadow:0 8px 22px rgba(15,23,42,.04); }
th { background:#f1f5f9 !important; color:#334155 !important; }

/* V5 secure navigation: hide role-filtered menu until profile role is resolved. */
body:not([data-role-ready="1"]) .app-nav a[data-role-allow] { display: none !important; }
.app-nav a[style*="display: none"] { display: none !important; }

.dashboard-live-feed{margin-top:18px;border:1px solid var(--gray-200);background:linear-gradient(180deg,#fff,#f8fafc)}
.dashboard-live-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:14px}.feed-item{padding:12px;border-bottom:1px solid var(--gray-100)}.feed-item:last-child{border-bottom:none}.feed-item a{font-weight:800;color:var(--primary);text-decoration:none}.feed-meta{font-size:.78rem;color:var(--gray-500);margin-top:3px}.feed-body{font-size:.88rem;color:var(--gray-700);margin-top:5px;line-height:1.55}.receipt-mini{display:flex;justify-content:space-between;gap:8px;padding:10px 0;border-bottom:1px solid var(--gray-100)}
