/*
  Al-Mahir classic educational SaaS App Shell
  RTL-first · emerald accent sparingly · high density · no glass/glow heroes
*/

:root {
  --app-bg: #f5f7fa;
  --app-surface: #ffffff;
  --app-surface-2: #f8fafc;
  --app-border: #e5e7eb;
  --app-border-strong: #d1d5db;
  --app-text: #0f172a;
  --app-muted: #64748b;
  --app-emerald: #059669;
  --app-emerald-deep: #047857;
  --app-emerald-soft: #ecfdf5;
  --app-amber: #b45309;
  --app-danger: #b91c1c;
  --app-radius: 10px;
  --app-radius-sm: 8px;
  --app-sidebar-w: 232px;
  --app-sidebar-w-collapsed: 72px;
  --app-topbar-h: 52px;
  --app-font: 'Tajawal', sans-serif;
  --app-shadow: none;
  --app-focus: 0 0 0 3px rgba(5, 150, 105, 0.18);
}

html.dark {
  --app-bg: #0b1220;
  --app-surface: #111827;
  --app-surface-2: #0f172a;
  --app-border: #1f2937;
  --app-border-strong: #374151;
  --app-text: #e5e7eb;
  --app-muted: #94a3b8;
  --app-emerald: #34d399;
  --app-emerald-deep: #10b981;
  --app-emerald-soft: rgba(16, 185, 129, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body.mahir-app {
  margin: 0;
  min-height: 100vh;
  background: var(--app-bg) !important;
  color: var(--app-text) !important;
  font-family: var(--app-font) !important;
  letter-spacing: 0;
}

body.mahir-app.mahir-shell-ready {
  padding-top: var(--app-topbar-h);
  padding-inline-end: var(--app-sidebar-w);
}

body.mahir-app.mahir-shell-collapsed.mahir-shell-ready {
  padding-inline-end: var(--app-sidebar-w-collapsed);
}

body.mahir-app::before,
body.mahir-app::after {
  display: none !important;
}

/* —— Fixed chrome —— */
#mahir-app-sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: var(--app-sidebar-w);
  z-index: 1200;
  background: var(--app-surface);
  border-inline-start: 1px solid var(--app-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  transition: width 0.2s ease, transform 0.2s ease;
}

body.mahir-shell-collapsed #mahir-app-sidebar {
  width: var(--app-sidebar-w-collapsed);
}

#mahir-app-topbar {
  position: fixed;
  top: 0;
  inset-inline-start: 0;
  inset-inline-end: var(--app-sidebar-w);
  height: var(--app-topbar-h);
  z-index: 1190;
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  transition: inset-inline-end 0.2s ease;
}

body.mahir-shell-collapsed #mahir-app-topbar {
  inset-inline-end: var(--app-sidebar-w-collapsed);
}

.mahir-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 12px;
  border-bottom: 1px solid var(--app-border);
  text-decoration: none !important;
  color: var(--app-text) !important;
  margin-bottom: 4px;
}

.mahir-brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}

.mahir-brand strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--app-text) !important;
}

.mahir-brand span {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--app-muted) !important;
}

body.mahir-shell-collapsed .mahir-brand-text {
  display: none;
}

.mahir-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.mahir-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--app-radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: #334155 !important;
  font-weight: 800;
  font-size: 0.88rem;
  text-decoration: none !important;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
}

html.dark .mahir-nav-link {
  color: #cbd5e1 !important;
}

.mahir-nav-link i {
  width: 18px;
  text-align: center;
  color: var(--app-emerald) !important;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.mahir-nav-link:hover,
.mahir-nav-link.is-active {
  background: var(--app-emerald-soft) !important;
  border-color: #a7f3d0 !important;
  color: var(--app-emerald-deep) !important;
}

html.dark .mahir-nav-link:hover,
html.dark .mahir-nav-link.is-active {
  border-color: rgba(52, 211, 153, 0.35) !important;
}

body.mahir-shell-collapsed .mahir-nav-link span {
  display: none;
}

body.mahir-shell-collapsed .mahir-nav-link {
  justify-content: center;
  padding-inline: 0;
}

.mahir-sidebar-foot {
  border-top: 1px solid var(--app-border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mahir-topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mahir-topbar-title h1 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--app-text) !important;
  font-family: var(--app-font) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mahir-topbar-title p {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--app-muted) !important;
  display: none;
}

@media (min-width: 900px) {
  .mahir-topbar-title p {
    display: block;
  }
}

.mahir-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mahir-icon-btn,
.mahir-chip-btn {
  min-height: 34px;
  border-radius: var(--app-radius-sm) !important;
  border: 1px solid var(--app-border) !important;
  background: var(--app-surface-2) !important;
  color: var(--app-text) !important;
  font-weight: 800;
  font-size: 0.78rem;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none !important;
  cursor: pointer;
  font-family: inherit;
  box-shadow: none !important;
}

.mahir-icon-btn {
  width: 34px;
  padding: 0;
  justify-content: center;
}

.mahir-icon-btn i,
.mahir-chip-btn i {
  color: var(--app-emerald) !important;
}

.mahir-chip-btn--admin {
  background: #fffbeb !important;
  border-color: #fcd34d !important;
  color: #92400e !important;
}

.mahir-chip-btn--admin i {
  color: #d97706 !important;
}

.mahir-chip-btn--admin.mahir-admin-active {
  background: #ecfdf5 !important;
  border-color: #6ee7b7 !important;
  color: var(--app-emerald-deep) !important;
}

#mahir-shell-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 1180;
}

body.mahir-drawer-open #mahir-shell-overlay {
  display: block;
}

/* Workspace helpers */
.mahir-workspace {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 28px;
}

.mahir-panel {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  padding: 14px 16px;
}

.mahir-panel + .mahir-panel,
.mahir-workspace > * + * {
  margin-top: 12px;
}

.mahir-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.mahir-section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--app-text) !important;
  font-family: var(--app-font) !important;
}

.mahir-kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--app-muted) !important;
}

.mahir-search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  background: var(--app-surface);
  padding: 0 12px;
  min-height: 40px;
}

.mahir-search i {
  color: var(--app-muted) !important;
}

.mahir-search input {
  flex: 1;
  border: 0 !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--app-text) !important;
  min-width: 0;
}

.mahir-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--app-surface-2);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  flex-wrap: wrap;
}

.mahir-tabs .tab-btn,
.mahir-tabs button {
  min-height: 34px;
  padding: 0 12px !important;
  border-radius: 6px !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--app-muted) !important;
  font-weight: 800 !important;
  font-size: 0.8rem !important;
  box-shadow: none !important;
}

.mahir-tabs .tab-btn.active-tab,
.mahir-tabs button.active-tab {
  background: var(--app-emerald) !important;
  border-color: var(--app-emerald-deep) !important;
  color: #fff !important;
}

/* Compact Massar widget */
.mahir-massar {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 12px;
  align-items: start;
}

.mahir-massar-form {
  display: grid;
  gap: 8px;
}

.mahir-massar-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mahir-massar-row input,
.mahir-massar select {
  min-height: 38px;
  border-radius: var(--app-radius-sm) !important;
  border: 1px solid var(--app-border) !important;
  background: #fff !important;
  padding: 0 12px;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--app-text) !important;
  flex: 1;
  min-width: 140px;
}

.mahir-massar-row button,
.mahir-btn-primary {
  min-height: 38px;
  padding: 0 14px !important;
  border-radius: var(--app-radius-sm) !important;
  background: var(--app-emerald) !important;
  border: 1px solid var(--app-emerald-deep) !important;
  color: #fff !important;
  font-weight: 800 !important;
  font-size: 0.82rem !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: none !important;
}

.mahir-massar-result {
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  background: var(--app-surface-2);
  min-height: 120px;
  padding: 12px;
  font-size: 0.85rem;
}

.mahir-massar-result .empty-hint {
  color: var(--app-muted);
  text-align: center;
  padding: 24px 8px;
  font-weight: 700;
}

/* Hide legacy chrome when shell is mounted */
body.mahir-shell-ready .shell-header,
body.mahir-shell-ready header.shell-header,
body.mahir-shell-ready .books-nav,
body.mahir-shell-ready [data-legacy-nav],
body.mahir-shell-ready .glass-sidebar,
body.mahir-shell-ready aside.glass-sidebar {
  display: none !important;
}

body.mahir-shell-ready .dashboard-shell {
  display: block !important;
  max-width: none !important;
  padding: 0 !important;
  min-height: 0 !important;
  grid-template-columns: none !important;
}

body.mahir-shell-ready .wpf-content,
body.mahir-shell-ready .dashboard-shell > .wpf-content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 28px;
}

body.mahir-shell-ready .shell-footer,
body.mahir-shell-ready footer.shell-footer {
  margin-inline-end: 0;
  border-top: 1px solid var(--app-border);
  background: var(--app-surface) !important;
}

/* Home density overrides */
body.mahir-shell-ready .dashboard-hero {
  padding: 12px 14px !important;
  margin: 0 !important;
  box-shadow: none !important;
}

body.mahir-shell-ready .dashboard-hero h1 {
  font-size: 1.15rem !important;
  margin: 0 !important;
  font-family: var(--app-font) !important;
}

body.mahir-shell-ready .dashboard-hero p,
body.mahir-shell-ready .dashboard-kicker {
  font-size: 0.82rem !important;
  margin: 4px 0 0 !important;
}

body.mahir-shell-ready .dashboard-topbar {
  margin-bottom: 10px !important;
}

body.mahir-shell-ready .dashboard-actions {
  display: none !important; /* moved to global topbar */
}

body.mahir-shell-ready .floating-search {
  margin-top: 8px !important;
}

body.mahir-shell-ready .shell-stat-grid {
  display: none !important; /* marketing stats out of workspace */
}

body.mahir-shell-ready .minimal-card {
  padding: 14px !important;
  border-radius: var(--app-radius) !important;
  box-shadow: none !important;
}

body.mahir-shell-ready .minimal-card:hover {
  transform: none !important;
}

body.mahir-shell-ready #student-portal .minimal-card {
  padding: 12px 14px !important;
}

body.mahir-shell-ready #student-portal .w-14,
body.mahir-shell-ready #student-portal .text-3xl {
  display: none !important;
}

body.mahir-shell-ready #student-portal h2 {
  font-size: 1rem !important;
  font-family: var(--app-font) !important;
  margin-bottom: 4px !important;
}

body.mahir-shell-ready #student-portal > .minimal-card > .grid {
  gap: 12px !important;
}

body.mahir-shell-ready #student-portal p.text-slate-500 {
  font-size: 0.78rem !important;
  line-height: 1.6 !important;
  margin-bottom: 8px !important;
}

body.mahir-shell-ready #lessons-anchor .shell-section-title h2,
body.mahir-shell-ready [data-home-panel] .shell-section-title h2 {
  font-size: 1.05rem !important;
  font-family: var(--app-font) !important;
}

body.mahir-shell-ready #education-grid {
  gap: 12px !important;
}

body.mahir-shell-ready .wpf-tab-panel:not(.is-active) {
  display: none !important;
}

body.mahir-shell-ready #quran-club {
  background: var(--app-surface) !important;
  border: 1px solid var(--app-border) !important;
  border-radius: var(--app-radius) !important;
  color: var(--app-text) !important;
}

body.mahir-shell-ready #quran-club h2,
body.mahir-shell-ready #quran-club p,
body.mahir-shell-ready #quran-club span {
  color: var(--app-text) !important;
}

body.mahir-shell-ready #quran-club .absolute.inset-0 {
  display: none !important;
}

body.mahir-shell-ready #quran-club .bg-white\/5,
body.mahir-shell-ready #quran-club [class*="bg-white/5"] {
  background: var(--app-surface-2) !important;
  border-color: var(--app-border) !important;
  backdrop-filter: none !important;
}

/* Books: tone down hero inside shell */
body.mahir-shell-ready .books-hero {
  padding: 18px 16px !important;
  min-height: 0 !important;
  border-radius: 0 !important;
}

body.mahir-shell-ready .books-brand-mark {
  font-size: 1.35rem !important;
}

body.mahir-shell-ready .books-hero-lead {
  font-size: 0.88rem !important;
  max-width: 52rem;
}

/* Quran reader fill mode */
body.mahir-app.mahir-shell-fill {
  height: 100vh;
  overflow: hidden;
}

body.mahir-app.mahir-shell-fill.mahir-shell-ready {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap;
  align-items: stretch;
}

body.mahir-app.mahir-shell-fill.mahir-shell-ready > #mahir-app-sidebar,
body.mahir-app.mahir-shell-fill.mahir-shell-ready > #mahir-app-topbar,
body.mahir-app.mahir-shell-fill.mahir-shell-ready > #mahir-shell-overlay {
  /* keep fixed chrome out of flex flow */
}

body.mahir-app.mahir-shell-fill .reader-main,
body.mahir-app.mahir-shell-fill > .sidebar,
body.mahir-app.mahir-shell-fill > aside.sidebar {
  height: calc(100vh - var(--app-topbar-h));
  margin-top: 0;
  max-height: calc(100vh - var(--app-topbar-h));
}

body.mahir-app.mahir-shell-fill > .sidebar,
body.mahir-app.mahir-shell-fill > aside.sidebar {
  z-index: 40;
  margin-top: 0 !important;
}

body.mahir-app.mahir-shell-fill .shell-header,
body.mahir-app.mahir-shell-fill header.shell-header {
  display: none !important;
}

body.mahir-app.mahir-shell-fill.mahir-shell-ready > .sidebar,
body.mahir-app.mahir-shell-fill.mahir-shell-ready > aside.sidebar,
body.mahir-app.mahir-shell-fill.mahir-shell-ready > .reader-main {
  position: relative;
  top: 0;
}

/* Focus a11y */
.mahir-nav-link:focus-visible,
.mahir-icon-btn:focus-visible,
.mahir-chip-btn:focus-visible,
.mahir-search input:focus-visible {
  outline: none;
  box-shadow: var(--app-focus);
}

@media (max-width: 800px) {
  .mahir-massar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 960px) {
  body.mahir-app.mahir-shell-ready {
    padding-inline-end: 0 !important;
  }

  #mahir-app-topbar {
    inset-inline-end: 0 !important;
  }

  #mahir-app-sidebar {
    transform: translateX(110%);
    width: min(280px, 86vw);
    box-shadow: -8px 0 24px rgba(15, 23, 42, 0.12);
  }

  html[dir="rtl"] #mahir-app-sidebar {
    transform: translateX(110%);
  }

  body.mahir-drawer-open #mahir-app-sidebar {
    transform: translateX(0) !important;
  }

  body.mahir-shell-collapsed #mahir-app-sidebar {
    width: min(280px, 86vw);
  }

  body.mahir-shell-collapsed .mahir-brand-text,
  body.mahir-shell-collapsed .mahir-nav-link span {
    display: block;
  }

  body.mahir-shell-collapsed .mahir-nav-link {
    justify-content: flex-start;
    padding: 8px 10px;
  }
}

@media print {
  #mahir-app-sidebar,
  #mahir-app-topbar,
  #mahir-shell-overlay {
    display: none !important;
  }

  body.mahir-app.mahir-shell-ready {
    padding: 0 !important;
  }
}
