/* Bristol LMS — Professional UI polish (v3 — School Ledger) */

/* System font stack — no render-blocking Google Fonts @import.
   Keeps first paint fast; looks still clean and modern on every OS. */
:root {
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ===== Dashboard canvas — theme-tinted, quiet ===== */
body.dashboard-layout {
  background:
    radial-gradient(ellipse 80% 50% at 100% -10%, color-mix(in srgb, var(--theme-primary) 7%, transparent), transparent 50%),
    radial-gradient(ellipse 60% 40% at 0% 100%, color-mix(in srgb, var(--theme-accent) 6%, transparent), transparent 45%),
    var(--bg);
}

body.dashboard-layout .content {
  /* No fill-mode `both` / lasting transform — that traps position:fixed modals inside .content */
  animation: bls-fade-up 0.35s ease;
}

@keyframes bls-fade-up {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Focus-visible rings ===== */
.btn:focus-visible,
.action-btn:focus-visible,
.tb-icon:focus-visible,
.menu-toggle:focus-visible,
.sb-item:focus-visible,
.filter-chip:focus-visible,
.add-btn:focus-visible,
.logout-btn:focus-visible,
.modal-close:focus-visible,
.bls-mobile-bar a:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ===== Sidebar ===== */
.sidebar {
  background: linear-gradient(180deg, var(--theme-sidebar) 0%, color-mix(in srgb, var(--theme-sidebar) 92%, #000) 100%);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
html[dir="rtl"] .sidebar {
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  border-right: none;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.sb-logo-box {
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.sb-item {
  border-radius: var(--radius-sm);
  position: relative;
}

.sb-item.active {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.sb-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--theme-accent);
  border-radius: 0 3px 3px 0;
}
html[dir="rtl"] .sb-item.active::before {
  left: auto;
  right: 0;
  border-radius: 3px 0 0 3px;
}

.sb-badge {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.sb-avatar {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

/* ===== Topbar ===== */
.topbar {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: 0 1px 0 var(--border), var(--shadow-sm);
}

.topbar h2 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.tb-icon {
  border-radius: var(--radius-sm);
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
}

.tb-icon:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ===== Welcome bar — theme-only (tenant-safe) ===== */
.welcome-bar {
  background: linear-gradient(
    135deg,
    var(--theme-primary) 0%,
    color-mix(in srgb, var(--theme-primary) 82%, #000) 70%,
    color-mix(in srgb, var(--theme-primary) 70%, var(--theme-accent)) 100%
  );
  box-shadow: var(--shadow-md);
  border: 1px solid color-mix(in srgb, var(--theme-on-primary) 12%, transparent);
  position: relative;
  overflow: hidden;
}

.welcome-bar::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--theme-on-primary) 10%, transparent) 0%, transparent 70%);
  pointer-events: none;
}

.welcome-bar::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: 10%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--theme-accent) 22%, transparent) 0%, transparent 70%);
  pointer-events: none;
}

.welcome-bar > * {
  position: relative;
  z-index: 1;
}

.w-stat {
  background: color-mix(in srgb, var(--theme-on-primary) 8%, transparent);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--theme-on-primary) 12%, transparent);
  min-width: 72px;
}

/* ===== Stat cards ===== */
.stat-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--theme-primary), var(--theme-accent));
  opacity: 0.9;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.sc-icon {
  border-radius: var(--radius-sm);
}

/* ===== School Ledger — section cards (signature) ===== */
.sec-card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  position: relative;
  background: var(--surface);
}

.sec-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--theme-accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 1;
}

.sec-header {
  background: color-mix(in srgb, var(--surface-elevated) 85%, var(--bg));
  border-bottom: 1px solid var(--border);
  padding-top: 16px;
}

/* ===== List items ===== */
.list-item {
  border-radius: 0;
  margin: 0;
}

.list-item:hover {
  background: color-mix(in srgb, var(--theme-primary) 4%, var(--surface));
}

.li-icon {
  border-radius: var(--radius-sm);
}

/* ===== Assignment cards ===== */
.assign-card {
  border: none;
  box-shadow: var(--shadow-sm);
}

.assign-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-4px);
}

.assign-card h5 {
  font-size: 15px;
  letter-spacing: -0.01em;
}

/* ===== Buttons ===== */
.btn {
  border-radius: var(--radius-sm);
  letter-spacing: 0.01em;
}

.btn-primary {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--theme-primary) 28%, transparent);
}

.btn-primary:hover {
  box-shadow: 0 4px 14px color-mix(in srgb, var(--theme-primary) 32%, transparent);
}

.btn-gold {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--theme-accent) 35%, transparent);
}

.add-btn {
  border-radius: var(--radius-sm);
  background: var(--theme-primary);
  color: var(--theme-on-primary);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--theme-primary) 28%, transparent);
  transition: transform var(--transition), box-shadow var(--transition);
}

.add-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

/* ===== Filters & search ===== */
.filter-chip {
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.filter-chip:not(.active):hover {
  background: color-mix(in srgb, var(--theme-primary) 8%, var(--surface));
  color: var(--theme-primary);
  border-color: color-mix(in srgb, var(--theme-primary) 25%, var(--border));
}

.search-box input {
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border-color: transparent;
  transition: box-shadow var(--transition), border-color var(--transition);
}

.search-box input:focus {
  border-color: var(--theme-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-primary) 12%, transparent);
}

/* ===== Forms ===== */
.form-control {
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

/* ===== School Ledger — data tables (signature) ===== */
.data-table th {
  background: color-mix(in srgb, var(--theme-primary) 5%, var(--surface-elevated));
  border-bottom: 2px solid color-mix(in srgb, var(--theme-accent) 55%, var(--border));
  position: relative;
}

.data-table td {
  border-bottom-color: var(--border-light);
}

.data-table tr:hover td {
  background: var(--hover-tint);
}

.data-table tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg) 45%, var(--surface));
}

.data-table tr:nth-child(even):hover td {
  background: var(--hover-tint);
}

/* ===== Progress bars ===== */
.prog-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 80%, var(--bg));
}

.prog-fill {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--theme-primary), color-mix(in srgb, var(--theme-primary) 65%, var(--theme-accent))) !important;
}

/* ===== Modals ===== */
.modal {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.modal-header h3 {
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* ===== Toasts (enhanced in main.css) ===== */

/* ===== Notifications list ===== */
.list-item.unread {
  animation: bls-notif-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
  border-left: 3px solid var(--theme-accent);
}

.list-item.unread .li-info h5::after {
  animation: bls-pulse-badge 2s ease infinite;
}

@keyframes bls-notif-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes bls-pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

@keyframes bls-bell-shake {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(12deg); }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(8deg); }
  60% { transform: rotate(-6deg); }
  75% { transform: rotate(3deg); }
}

.bls-bell-shake {
  animation: bls-bell-shake 0.55s ease;
}

.bls-bell-shake .notif-dot {
  animation: bls-dot-pop 0.5s ease;
}

@keyframes bls-dot-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ===== Dark mode v2 ===== */
html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #0a0f1e 0%, #060912 100%);
  border-right-color: rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .assign-card {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), var(--shadow-sm);
}

html[data-theme="dark"] .stat-card::after {
  background: linear-gradient(90deg, var(--theme-primary), var(--theme-accent));
  opacity: 1;
}

html[data-theme="dark"] .welcome-bar {
  background: linear-gradient(
    135deg,
    var(--theme-primary) 0%,
    color-mix(in srgb, var(--theme-primary) 75%, #000) 100%
  );
}

html[data-theme="dark"] .topbar {
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .search-box input {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

html[data-theme="dark"] .filter-chip:not(.active) {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}

html[data-theme="dark"] .portal-card {
  background: var(--surface);
  border: 1px solid var(--border);
}

html[data-theme="dark"] .stats-portal {
  background: var(--surface);
}

html[data-theme="dark"] .list-item.unread {
  background: color-mix(in srgb, var(--theme-primary) 8%, var(--surface));
}

html[data-theme="dark"] .toast-success {
  background: linear-gradient(135deg, #1b5e3a, #2E7D52);
}

html[data-theme="dark"] .toast-error {
  background: linear-gradient(135deg, #8b2020, #C62828);
}

html[data-theme="dark"] .toast-info {
  background: linear-gradient(135deg, #0a1628, #1B2E6B);
}

/* ===== Mobile & PWA ===== */
@media (max-width: 767px) {
  .toast-container {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
    max-width: none;
  }

  .toast {
    animation-name: toastSlideUp;
    font-size: 14px;
    padding: 16px 18px;
    min-height: 52px;
  }

  .toast.toast-exit {
    animation-name: toastSlideDown;
  }

  @keyframes toastSlideUp {
    from { opacity: 0; transform: translateY(100%) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }

  @keyframes toastSlideDown {
    to { opacity: 0; transform: translateY(100%) scale(0.95); }
  }

  body.pwa-standalone .content,
  body.bls-mobile-app .content {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  body.pwa-standalone .filter-bar,
  body.bls-mobile-app .filter-bar,
  body.dashboard-layout .filter-bar {
    position: sticky;
    top: calc(var(--topbar-height, 64px) - 1px);
    z-index: 40;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    margin: 0 0 14px;
    padding: 8px 0 10px;
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
  }
  /* Notifications page owns its own sticky filter (avoid double sticky) */
  body.dashboard-layout[data-bls-page="notifications"] .filter-bar {
    top: 0;
    z-index: 30;
    margin: 0 0 12px;
    padding: 8px 0 10px;
  }

  body.dashboard-layout .filter-bar::-webkit-scrollbar {
    display: none;
  }

  body.dashboard-layout .filter-chip {
    flex-shrink: 0;
  }

  body.pwa-standalone .topbar,
  body.bls-mobile-app .topbar {
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
  }

  /* Notifications page — readable cards on phone */
  body[data-bls-page="notifications"] .list-item {
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
  }

  body[data-bls-page="notifications"] .list-item .li-info {
    flex: 1;
    min-width: 0;
  }

  body[data-bls-page="notifications"] .list-item .li-info h5 {
    white-space: normal;
    line-height: 1.35;
    font-size: 14px;
  }

  body[data-bls-page="notifications"] .list-item .li-info p {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    margin-top: 4px;
  }

  body[data-bls-page="notifications"] .list-item > span {
    flex-shrink: 0;
    align-self: flex-start;
    font-size: 11px !important;
    margin-top: 2px;
  }

  body[data-bls-page="notifications"] .nt-actions {
    margin-bottom: 12px;
  }

  body[data-bls-page="notifications"] .nt-file {
    margin-top: 8px;
  }

  body[data-bls-page="notifications"] #nt-card {
    margin-bottom: 8px;
  }

  .stat-card:active,
  .assign-card:active,
  .portal-card:active {
    transform: scale(0.98);
  }

  .sb-item {
    min-height: 48px;
    font-size: 14px;
  }

  .btn, .login-btn, .tb-icon, .menu-toggle {
    -webkit-tap-highlight-color: transparent;
  }

  .welcome-bar {
    padding: 18px 20px;
  }

  .welcome-stats {
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .w-stat {
    min-width: 64px;
    padding: 8px 12px;
  }
}

/* Mobile bottom quick bar — always on phone (browser + PWA) */
.bls-mobile-bar {
  display: none;
}

@media (max-width: 767px) {
  body.dashboard-layout .bls-mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
  }

  body.dashboard-layout .main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  body.dashboard-layout .toast-container {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Sidebar above bottom bar when opened from hamburger */
  body.dashboard-layout .sidebar {
    z-index: 120;
  }
  body.dashboard-layout .sb-overlay {
    z-index: 110;
  }

  /* ===== Messages page — scrollable so Send stays reachable =====
     Rest of the app keeps its normal fixed/contained feel; only messages
     unlocks vertical scroll on short phones / PWAs. */
  body.dashboard-layout[data-bls-page="messages"] {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    height: auto;
    min-height: 100dvh;
    -webkit-overflow-scrolling: touch;
  }
  html.pwa-app:has(body[data-bls-page="messages"]),
  body.pwa-standalone[data-bls-page="messages"],
  body.bls-mobile-app[data-bls-page="messages"] {
    overscroll-behavior-y: auto;
    touch-action: pan-y pinch-zoom;
  }
  body.dashboard-layout[data-bls-page="messages"] .main {
    min-height: auto;
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }
  body.dashboard-layout[data-bls-page="messages"] .content {
    overflow: visible;
    padding-bottom: 12px;
    overscroll-behavior-y: auto;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-layout {
    display: flex;
    flex-direction: column;
    overflow: visible;
    min-height: 0;
    border-radius: 14px;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-list {
    max-height: min(38vh, 260px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-detail {
    flex: 1 1 auto;
    min-height: 120px;
    padding: 16px;
    overflow: visible;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-thread {
    max-height: min(58vh, 560px);
    padding-bottom: 140px;
  }
  body.dashboard-layout[data-bls-page="messages"].msg-thread-open .msg-list,
  body.dashboard-layout[data-bls-page="messages"] .msg-layout.msg-thread-open .msg-list {
    display: none;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-layout.msg-thread-open .msg-detail {
    min-height: 55vh;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-bubble.mine {
    margin-left: 10%;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-bubble.theirs {
    margin-right: 10%;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-compose {
    position: sticky;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--msg-keyboard-inset, 0px));
    z-index: 25;
    flex-shrink: 0;
    margin: 0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08);
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-reply-box {
    position: sticky;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--msg-keyboard-inset, 0px));
    z-index: 26;
    flex-shrink: 0;
    margin: 0;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08);
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-compose .btn,
  body.dashboard-layout[data-bls-page="messages"] #msg-send,
  body.dashboard-layout[data-bls-page="messages"] #msg-reply-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    margin-top: 10px;
    font-weight: 700;
  }
  body.dashboard-layout[data-bls-page="messages"] .msg-compose .form-control,
  body.dashboard-layout[data-bls-page="messages"] .msg-detail .form-control,
  body.dashboard-layout[data-bls-page="messages"] .msg-reply-box .form-control {
    font-size: 16px; /* avoid iOS zoom on focus */
  }
}

/* Mobile touch targets — enlarge interactive chrome without changing desktop density */
@media (max-width: 767px) {
  .action-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }
  .modal-close {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
}

.bls-mobile-bar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  min-width: 56px;
  transition: color 0.2s, background 0.2s;
}

.bls-mobile-bar a i {
  font-size: 22px;
}

.bls-mobile-bar a.active {
  color: var(--theme-primary);
  background: color-mix(in srgb, var(--theme-primary) 10%, transparent);
}

.bls-mobile-bar a:active {
  transform: scale(0.94);
}

/* ===== Dark mode refinements ===== */
html[data-theme="dark"] body.dashboard-layout {
  background:
    radial-gradient(ellipse 80% 50% at 100% -10%, color-mix(in srgb, var(--theme-primary) 14%, transparent), transparent 50%),
    radial-gradient(ellipse 60% 40% at 0% 100%, color-mix(in srgb, var(--theme-accent) 6%, transparent), transparent 45%),
    var(--bg);
}

html[data-theme="dark"] .topbar {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

html[data-theme="dark"] .stat-card::after {
  opacity: 1;
}

html[data-theme="dark"] .sec-card::before {
  opacity: 0.9;
}

html[data-theme="dark"] .data-table th {
  background: color-mix(in srgb, var(--theme-primary) 12%, var(--surface-elevated));
}

html[data-theme="dark"] .data-table tr:nth-child(even) td {
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
}

html[data-theme="dark"] .welcome-bar {
  border-color: rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .bls-mobile-bar {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top-color: var(--border);
}

html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, var(--theme-sidebar) 0%, color-mix(in srgb, var(--theme-sidebar) 88%, #000) 100%);
}

/* Hardcoded navy/gray inline colors → readable on dark canvas */
html[data-theme="dark"] .content h1,
html[data-theme="dark"] .content h2,
html[data-theme="dark"] .content h3,
html[data-theme="dark"] .content h4,
html[data-theme="dark"] .content h5,
html[data-theme="dark"] .content h6,
html[data-theme="dark"] .content label,
html[data-theme="dark"] .content .meta,
html[data-theme="dark"] .content .due,
html[data-theme="dark"] .content .act-info h5,
html[data-theme="dark"] .content .act-info p,
html[data-theme="dark"] .content .msg-item,
html[data-theme="dark"] .content .cl-empty,
html[data-theme="dark"] .content .an-empty,
html[data-theme="dark"] .content .nt-empty,
html[data-theme="dark"] .content .empty-state p {
  color: var(--text);
}
html[data-theme="dark"] .content .meta,
html[data-theme="dark"] .content .due,
html[data-theme="dark"] .content .act-info p,
html[data-theme="dark"] .content .act-time,
html[data-theme="dark"] .content .cl-empty,
html[data-theme="dark"] .content .an-empty,
html[data-theme="dark"] .content .nt-empty,
html[data-theme="dark"] .content .empty-state p,
html[data-theme="dark"] .content .li-info p {
  color: var(--text-muted);
}
html[data-theme="dark"] .content [style*="color:#888"],
html[data-theme="dark"] .content [style*="color: #888"],
html[data-theme="dark"] .content [style*="color:#666"],
html[data-theme="dark"] .content [style*="color: #666"],
html[data-theme="dark"] .content [style*="color:#AAA"],
html[data-theme="dark"] .content [style*="color:#aaa"],
html[data-theme="dark"] .content [style*="color:#555"],
html[data-theme="dark"] .content [style*="color:#333"] {
  color: var(--text-muted) !important;
}
html[data-theme="dark"] .content [style*="color:#1B2E6B"],
html[data-theme="dark"] .content [style*="color:#0F1D45"],
html[data-theme="dark"] .content [style*="color:#0A0F1E"] {
  color: #B8C4E8 !important;
}
html[data-theme="dark"] .content [style*="color:#2E7D52"] {
  color: #6BCB8A !important;
}
html[data-theme="dark"] .content [style*="background:#FAFBFF"],
html[data-theme="dark"] .content [style*="background:#F0F3FF"],
html[data-theme="dark"] .content [style*="background:#E8F0FF"] {
  background: var(--surface-elevated) !important;
}
html[data-theme="dark"] .sec-header .link,
html[data-theme="dark"] .add-link {
  color: #B8C4E8;
}
html[data-theme="dark"] .modal {
  background: var(--surface);
  color: var(--text);
}
html[data-theme="dark"] .modal-header h3,
html[data-theme="dark"] .modal-body,
html[data-theme="dark"] .modal-body p,
html[data-theme="dark"] .modal-body strong {
  color: var(--text);
}
html[data-theme="dark"] .modal-body p {
  color: var(--text-muted);
}
html[data-theme="dark"] .msg-item h5,
html[data-theme="dark"] .msg-detail h4,
html[data-theme="dark"] .msg-detail p {
  color: var(--text);
}
html[data-theme="dark"] .msg-item p,
html[data-theme="dark"] .msg-item .msg-time {
  color: var(--text-muted);
}

/* ===== Empty & loading ===== */
.empty-state {
  padding: 56px 24px;
}

.empty-state i {
  opacity: 0.35;
}

.bls-loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.bls-loading::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--theme-primary);
  border-radius: 50%;
  animation: bls-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes bls-spin {
  to { transform: rotate(360deg); }
}

/* ===== Materials by subject (student / parent library) ===== */
.mat-subject-block {
  margin: 0 0 14px;
  border: 1px solid var(--border, #E2E7F0);
  border-radius: 14px;
  background: var(--surface, #fff);
  overflow: hidden;
}
.mat-subject-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  color: var(--text, #1a1a2e);
  text-align: start;
}
.mat-subject-head span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.mat-subject-head .ti {
  color: var(--theme-primary, #1B2E6B);
}
.mat-subject-count {
  min-width: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #EEF2FF;
  color: var(--theme-primary, #1B2E6B);
  font-size: 12px;
  font-weight: 800;
}
.mat-subject-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--border, #E2E7F0);
}
.mat-subject-block.open .mat-subject-body {
  display: grid;
}
.mat-subject-head::after {
  content: '\ea5f';
  font-family: 'tabler-icons' !important;
  font-size: 18px;
  color: var(--text-muted, #888);
  transition: transform .18s ease;
}
.mat-subject-block.open .mat-subject-head::after {
  transform: rotate(180deg);
}
#mat-subject-bar {
  flex-wrap: wrap;
  gap: 8px;
}

/* Folder library (student / parent) */
.mat-crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted, #666);
}
.mat-crumb-back {
  border: 0;
  background: #EEF2FF;
  color: var(--theme-primary, #1B2E6B);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mat-crumb-sep { opacity: .45; }
.mat-crumb-here {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text, #1a1a2e);
}
.mat-folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 14px;
}
.mat-folder {
  appearance: none;
  border: 1px solid var(--border, #E2E7F0);
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF8EB 100%);
  border-radius: 16px;
  padding: 18px 14px 16px;
  text-align: start;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 132px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  box-shadow: 0 1px 0 rgba(27, 46, 107, 0.04);
}
.mat-folder:hover,
.mat-folder:focus-visible {
  transform: translateY(-2px);
  border-color: #C9D4F5;
  box-shadow: 0 8px 20px rgba(27, 46, 107, 0.08);
  outline: none;
}
.mat-folder-icon {
  font-size: 34px;
  line-height: 1;
  color: #E2A93B;
}
.mat-folder-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text, #1a1a2e);
  line-height: 1.35;
}
.mat-folder-meta {
  margin-top: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted, #888);
}

/* ===== Weekly Plan (student/parent) — mobile-first cards, no horizontal scroll ===== */
.wp-page-hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted, #667);
  line-height: 1.45;
}
.wp-plans {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.wp-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #E8EAF0);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 2px rgba(15, 29, 69, 0.04);
}
.wp-card-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.wp-day-badge {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #E8F0FF;
  color: #1B2E6B;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.wp-card-titles { flex: 1; min-width: 0; }
.wp-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--text, #1a1a2e);
  line-height: 1.3;
  word-break: break-word;
}
.wp-card-week {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: #1B2E6B;
}
.wp-card-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border-light, #F0F1F5);
}
.wp-meta-row {
  display: flex;
  gap: 10px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.wp-meta-label {
  flex: 0 0 64px;
  font-weight: 700;
  color: var(--text-muted, #888);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding-top: 1px;
}
.wp-card-notes {
  font-size: 13px;
  color: var(--text-muted, #666);
  line-height: 1.45;
  word-break: break-word;
}
.wp-card-actions { margin-top: 2px; }
.wp-open-btn {
  width: 100%;
  min-height: 44px;
  justify-content: center;
  font-weight: 700;
}
.wp-no-file {
  display: block;
  font-size: 12px;
  color: var(--text-muted, #888);
  padding: 8px 0;
}
@media (min-width: 900px) {
  .wp-plans {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}
@media (max-width: 767px) {
  .wp-page .wp-plans,
  .wp-page .wp-card {
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  body.dashboard-layout .content,
  .stat-card,
  .assign-card,
  .portal-card,
  .btn-primary:hover,
  .list-item.unread,
  .list-item.unread .li-info h5::after,
  .toast,
  .bls-bell-shake,
  .bls-bell-shake .notif-dot,
  .bls-loading::before,
  .skeleton {
    animation: none !important;
    transform: none !important;
  }

  html.theme-switching,
  html.theme-switching * {
    transition: none !important;
  }
}

/* ===== Phase 2 — Shared Mobile UI/UX Hardening =====
   Prefer shared rules over page hacks. Desktop (≥768px) unchanged. */

@media (max-width: 767px) {
  /* --- Page shell (vertical scroll must work) ---
     Never set overflow-x:hidden/clip on BOTH html and body — that creates two
     scrollports and breaks touch scrolling on mobile. html owns X-clip + Y-scroll;
     body stays overflow:visible so document scroll is unambiguous. */
  html {
    max-width: 100%;
    height: auto;
    overflow-x: clip;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
  }
  body,
  body.dashboard-layout,
  body.portal-page,
  body.auth-page,
  body.admin-login,
  body.auth-immersive {
    max-width: 100%;
    height: auto !important;
    max-height: none !important;
    min-height: 100dvh;
    overflow: visible !important;
    overscroll-behavior-y: auto;
  }
  body.dashboard-layout .main,
  body.dashboard-layout .content {
    overflow: visible !important;
    height: auto;
    max-height: none;
  }
  /* Temporary lock only while sidebar / modal overlays are open */
  body.bls-sidebar-open,
  body.bls-modal-open,
  body.bls-video-open,
  body.pwa-onboard-lock {
    overflow: hidden !important;
    touch-action: none;
    overscroll-behavior: none;
  }

  .topbar {
    gap: 8px;
    align-items: center;
  }
  .topbar h2 {
    min-width: 0;
    flex: 1 1 auto;
    font-size: 15px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar .tb-actions,
  .topbar .tb-right {
    flex-shrink: 0;
    gap: 4px;
  }
  .menu-toggle,
  .tb-icon {
    min-width: 44px;
    min-height: 44px;
  }

  /* --- Forms: full width in container --- */
  .form-control,
  select.form-control,
  textarea.form-control,
  input[type="date"].form-control,
  input[type="search"].form-control,
  input[type="text"].form-control,
  input[type="number"].form-control,
  input[type="email"].form-control,
  input[type="tel"].form-control {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    font-size: 16px; /* avoid iOS focus zoom */
  }
  .form-row { grid-template-columns: 1fr !important; }
  .filter-bar .form-control,
  .admin-exam-filters .form-control {
    min-width: 0 !important;
    max-width: none !important;
    flex: 1 1 100%;
  }
  .admin-exam-filters {
    flex-direction: column;
    align-items: stretch !important;
  }
  .admin-exam-filters .btn {
    width: 100%;
    min-height: 44px;
  }

  /* --- Reports filters / KPIs / tabs --- */
  .rpt-filters {
    flex-direction: column;
    align-items: stretch !important;
  }
  .rpt-filters label {
    width: 100%;
  }
  .rpt-filters select,
  .rpt-filters input[type="date"] {
    min-width: 0 !important;
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }
  .rpt-filters .btn {
    width: 100%;
    min-height: 44px;
  }
  .rpt-quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .rpt-quick::-webkit-scrollbar { display: none; }
  .rpt-quick button {
    flex-shrink: 0;
    min-height: 40px;
  }
  #rpt-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #rpt-tabs::-webkit-scrollbar { display: none; }
  #rpt-tabs .btn {
    flex-shrink: 0;
    min-height: 40px;
  }
  .rpt-kpi-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .rpt-kpi .val {
    font-size: 18px;
    overflow-wrap: anywhere;
  }
  .rpt-export-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- Tables: no forced 500px min-width; card-stack when labeled --- */
  .data-table {
    min-width: 0 !important;
  }
  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Teacher Activity + any .mobile-stack / tables with data-label cells */
  #te-table thead,
  .data-table.mobile-stack thead,
  table.mobile-stack thead {
    display: none;
  }
  #te-table,
  #te-table tbody,
  #te-table tr,
  #te-table td,
  .data-table.mobile-stack,
  .data-table.mobile-stack tbody,
  .data-table.mobile-stack tr,
  .data-table.mobile-stack td,
  table.mobile-stack,
  table.mobile-stack tbody,
  table.mobile-stack tr,
  table.mobile-stack td {
    display: block;
    width: 100%;
  }
  #te-table tr,
  .data-table.mobile-stack tr,
  table.mobile-stack tr {
    border: 1px solid var(--border, #dde1ee);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: var(--surface, #fff);
  }
  #te-table td,
  .data-table.mobile-stack td,
  table.mobile-stack td {
    border: 0 !important;
    padding: 6px 0 !important;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }
  #te-table td::before,
  .data-table.mobile-stack td::before,
  table.mobile-stack td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted, #778);
    flex: 0 0 38%;
    max-width: 42%;
  }
  #te-table td:first-child,
  #te-table td:last-child,
  .data-table.mobile-stack td:first-child,
  .data-table.mobile-stack td.actions,
  .data-table.mobile-stack td[data-label=""],
  table.mobile-stack td:first-child,
  table.mobile-stack td[data-label=""] {
    display: block;
  }
  #te-table td:first-child::before,
  #te-table td:last-child::before,
  .data-table.mobile-stack td:first-child::before,
  .data-table.mobile-stack td[data-label=""]::before,
  table.mobile-stack td:first-child::before,
  table.mobile-stack td[data-label=""]::before {
    content: none;
  }
  #te-table .hide-mobile,
  .data-table.mobile-stack .hide-mobile {
    display: none !important;
  }

  /* --- Modals: never exceed viewport; respect inline max-width --- */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }
  .modal-overlay .modal,
  .modal-overlay > .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(92vh, 92dvh) !important;
    border-radius: 16px 16px 0 0 !important;
    margin: 0 !important;
  }
  .modal-header {
    gap: 8px;
    padding: 14px 16px;
  }
  .modal-header h3 {
    min-width: 0;
    flex: 1;
    font-size: 15px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  .modal-body {
    padding: 14px 16px;
    max-height: none;
  }
  .modal-footer {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-footer .btn {
    width: 100%;
    min-height: 48px;
  }
  .modal-close {
    width: 44px !important;
    height: 44px !important;
    flex-shrink: 0;
  }

  /* --- Cards / dashboards --- */
  .quick-actions {
    grid-template-columns: 1fr 1fr !important;
  }
  .stat-card h4,
  .w-stat strong {
    overflow-wrap: anywhere;
  }
  .list-item {
    align-items: flex-start;
  }
  .list-item .li-info {
    min-width: 0;
    flex: 1;
  }
  .list-item .li-info h5 {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  /* --- Messaging chips --- */
  .cmp-chip span {
    max-width: min(220px, 55vw) !important;
  }
  .cmp-scope {
    grid-template-columns: 1fr !important;
  }

  /* --- Touch density for chrome --- */
  .sb-item {
    min-height: 48px;
  }
  .btn-sm {
    min-height: 40px;
    padding-left: 12px;
    padding-right: 12px;
  }
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--theme-primary, #1B2E6B);
  }
}

/* Exam take — vertical MCQ options (all viewports; mobile + desktop) */
.exam-q-card,
.sec-card.exam-q-card {
  overflow: visible;
}
.exam-question-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px 12px;
  margin-bottom: 10px;
}
.exam-question-prompt {
  flex: 1 1 12rem;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.exam-question-points {
  flex: 0 0 auto;
  color: #888;
  font-size: 13px;
  white-space: nowrap;
  line-height: 1.45;
  padding-top: 1px;
}
.exam-choices {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 0;
}
.exam-choice {
  display: flex !important;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0 !important;
  padding: 12px 14px;
  min-height: 44px;
  border: 1px solid var(--border, #dde1ee);
  border-radius: 12px;
  background: var(--surface, #fff);
  cursor: pointer;
  text-align: start;
}
.exam-choice:has(input:checked) {
  border-color: var(--theme-primary, #1B2E6B);
  background: #EEF3FF;
}
.exam-choice input[type="radio"] {
  margin: 2px 0 0;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  accent-color: var(--theme-primary, #1B2E6B);
}
.exam-choice-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}
.exam-authored img,
[data-exam-authored] img,
.exam-q-image {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
  margin: 0 0 10px;
}
html[dir="rtl"] .exam-choice,
html[dir="rtl"] .exam-question-header {
  text-align: start;
}

/* Exam take / review — larger tap targets on narrow screens */
@media (max-width: 767px) {
  .exam-choice {
    padding: 12px 14px;
    min-height: 48px;
  }
  .exam-authored img,
  [data-exam-authored] img,
  .exam-q-image,
  .modal-body img {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 10px;
  }
  #exam-timer {
    flex-shrink: 0;
  }
  #exam-take-modal .modal-body,
  #exam-student-review-modal .modal-body,
  #exam-attempt-review-modal .modal-body {
    max-height: min(65vh, 65dvh) !important;
  }
}

/* RTL dashboard forms — mirror auth icon/padding (all widths) */
html[dir="rtl"] .input-icon-wrap i {
  left: auto;
  right: 13px;
}
html[dir="rtl"] .input-icon-wrap .form-control {
  padding-left: 14px;
  padding-right: 42px;
}
html[dir="rtl"] .search-box i {
  left: auto;
  right: 12px;
}
html[dir="rtl"] .search-box input {
  padding-left: 14px;
  padding-right: 38px;
}

/* RTL mobile refinements */
@media (max-width: 767px) {
  html[dir="rtl"] .topbar h2 {
    text-align: start;
    white-space: normal;
    line-height: 1.3;
  }
  html[dir="rtl"] #te-table td,
  html[dir="rtl"] .data-table.mobile-stack td,
  html[dir="rtl"] table.mobile-stack td {
    flex-direction: row;
  }
  html[dir="rtl"] .exam-choice,
  html[dir="rtl"] .exam-question-header {
    text-align: start;
  }

  /* Filter / search toolbar — full-width search, 44px chips */
  .filter-bar {
    flex-wrap: wrap !important;
  }
  .filter-bar .search-box {
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
  }
  .filter-chip {
    min-height: 44px;
    padding: 10px 16px;
  }
  .btn-sm {
    min-height: 44px;
  }
  .data-table .btn-sm,
  .data-table .action-btn {
    min-height: 44px;
  }
  .topbar h2 {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

