/* Al-Burhaniya — application shell & responsive layout */
.app-root { min-height: 100dvh; }

/* ---------- Auth layout ---------- */
.auth-layout {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(340px, 46%) 1fr;
}
.auth-hero {
  position: relative;
  background: var(--grad-hero);
  color: #f2f6f3;
  padding: clamp(1.5rem, 4vw, 3.5rem);
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden;
}
.auth-hero::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M60 8l44 25.5v51L60 110 16 84.5v-51z' fill='none' stroke='%23cdae3a' stroke-opacity='.12' stroke-width='1.5'/%3E%3C/svg%3E");
  background-size: 150px 150px;
  opacity: .9;
}
.auth-hero > * { position: relative; z-index: 1; }
.auth-brand { display: flex; align-items: center; gap: .85rem; }
.auth-brand img { width: 56px; height: 56px; }
.auth-brand .name { font-size: 1.45rem; font-weight: 750; letter-spacing: .03em; }
.auth-brand .name-ar { font-family: var(--font-urdu); color: var(--light-gold); font-size: 1.2rem; }
.auth-hero h2 { color: #fff; font-size: clamp(1.4rem, 2.4vw, 2rem); }
.auth-hero .tagline { color: #cfe3d7; max-width: 46ch; }
.auth-points { list-style: none; display: flex; flex-direction: column; gap: .65rem; }
.auth-points li { display: flex; gap: .6rem; align-items: flex-start; color: #d7e8de; }
.auth-points .icon { color: var(--light-gold); flex: none; margin-top: .15rem; }
.auth-form-side {
  display: flex; align-items: center; justify-content: center;
  padding: clamp(1.2rem, 4vw, 3rem);
  background: var(--bg);
}
.auth-card { width: min(480px, 100%); }
.auth-card .brand-mini { display: none; }
.auth-title { margin-block-end: .35rem; }
.auth-sub { color: var(--text-2); margin-block-end: 1.4rem; }
.auth-footer { margin-block-start: 1.4rem; color: var(--text-2); font-size: var(--fs-sm); text-align: center; }
.auth-credit {
  display: flex; justify-content: center; align-items: center; gap: .45rem;
  margin-block-start: 1.05rem; font-size: .74rem; color: var(--text-2);
}
.credit-chip {
  display: inline-flex; align-items: center;
  padding: .04rem .48rem; border-radius: 999px;
  border: 1px solid var(--accent); background: var(--accent-soft);
  color: var(--accent); font-weight: 700; font-size: .66rem;
  text-decoration: none; line-height: 1.55;
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.credit-chip:hover, .credit-chip:focus-visible {
  text-decoration: none;
  transform: translateY(-1px);
  background: var(--card);
  box-shadow: 0 4px 11px rgba(12, 74, 52, .18);
}
.auth-footer a { font-weight: 600; }
.role-tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; margin-block-end: 1.25rem; }
.role-tab {
  position: relative;
  border: 1.5px solid var(--border); background: var(--card); color: var(--text-2);
  border-radius: var(--r-md); padding: .6rem .5rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .25rem;
  font-size: var(--fs-sm); font-weight: 600; transition: all var(--speed);
}
.role-tab:hover { border-color: var(--accent); color: var(--accent); }
.role-tab[aria-selected='true'] {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.hint-dot {
  position: absolute; top: 4px; right: 5px;
  width: 17px; height: 17px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-2); opacity: .7; line-height: 1;
}
.role-tab:hover .hint-dot { opacity: .95; }
.hint-dot:hover, .hint-dot:focus-visible { opacity: 1; color: var(--accent); border-color: var(--accent); outline: none; }
.hint-pop {
  position: absolute; top: calc(100% + 9px); right: -4px;
  width: min(252px, 72vw); padding: .55rem .72rem;
  background: var(--card); border: 1px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: 0 12px 28px rgba(12, 74, 52, .18);
  color: var(--text-2); font-size: var(--fs-sm); font-weight: 500;
  line-height: 1.5; text-align: start; z-index: 70;
}
.hint-pop::before {
  content: ''; position: absolute; top: -5px; right: 15px;
  width: 9px; height: 9px; background: var(--card);
  border-left: 1px solid var(--accent); border-top: 1px solid var(--accent);
  transform: rotate(45deg);
}

@media (max-width: 900px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-card .brand-mini { display: flex; align-items: center; gap: .7rem; margin-block-end: 1.2rem; }
  .auth-card .brand-mini img { width: 48px; height: 48px; }
}

/* ---------- Shell ---------- */
.shell { min-height: 100dvh; display: flex; }
.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Sidebar */
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 95;
  width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  transition: width var(--speed), transform var(--speed);
  overflow: hidden;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .7rem;
  padding: 1rem 1.1rem; border-block-end: 1px solid #ffffff14;
  min-height: var(--header-h);
}
.sidebar-brand img { width: 38px; height: 38px; flex: none; }
.sidebar-brand .b-text { min-width: 0; }
.sidebar-brand .b-name { font-weight: 750; letter-spacing: .03em; white-space: nowrap; }
.sidebar-brand .b-sub { font-family: var(--font-urdu); font-size: .72rem; color: var(--sidebar-muted); white-space: nowrap; }
.sidebar-role {
  margin: .75rem .9rem .35rem; font-size: .68rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--sidebar-muted);
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* drawer scroll never chains to the page behind */
  padding: .35rem .6rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-bg) var(--sidebar-bg);
}
/* scrollbar blends into the sidebar background (no contrasting thumb) */
.sidebar-nav::-webkit-scrollbar { width: 8px; height: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #ffffff3d; border-radius: 99px; }
.sidebar-nav::-webkit-scrollbar-track { background: var(--sidebar-bg); }
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .62rem .75rem; margin-block-end: 2px;
  color: var(--sidebar-text); border-radius: var(--r-md);
  font-size: var(--fs-base); font-weight: 500; text-decoration: none;
  opacity: .88; transition: background var(--speed), opacity var(--speed);
  position: relative;
}
.nav-item:hover { background: var(--sidebar-active); opacity: 1; text-decoration: none; }
.nav-item.active {
  background: linear-gradient(90deg, #ffffff1a, #ffffff08);
  opacity: 1; font-weight: 650;
}
.nav-item.active::before {
  content: ''; position: absolute; inset-inline-start: 0; inset-block: 8px;
  width: 3.5px; border-radius: 99px; background: var(--gold);
}
.nav-item .icon { flex: none; }
.nav-item .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item .nav-badge {
  margin-inline-start: auto; background: var(--gold); color: #1c1608;
  font-size: .68rem; font-weight: 750; border-radius: 99px; padding: .05rem .42rem;
}
.sidebar-foot { padding: .9rem .8rem; border-block-start: 1px solid #ffffff14; font-size: .72rem; color: var(--sidebar-muted); text-align: center; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 50;
  min-height: var(--header-h);
  height: auto; /* grows for the safe-area strip on notched phones / standalone PWA */
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem;
  padding-block: calc(.35rem + env(safe-area-inset-top, 0px)) .35rem;
  padding-inline: clamp(.6rem, 2vw, 1.25rem);
}
.topbar.is-scrolled { box-shadow: 0 12px 28px -18px rgba(14, 23, 18, .45); } /* content sliding under the header */
body.is-offline .topbar { top: 32px; }
.topbar-title { font-weight: 700; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .sub { display: block; font-weight: 500; font-size: .72rem; color: var(--text-3); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  cursor: pointer; position: relative; flex: none;
  transition: background var(--speed), color var(--speed);
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 6px; inset-inline-end: 6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: #fff; font-size: .62rem; font-weight: 750;
  border-radius: 99px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}
.icon-btn .dot.bell-pop { animation: bellPop .45s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes bellPop { 0% { transform: scale(.2); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .icon-btn .dot.bell-pop { animation: none; } }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--grad-emerald); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex: none; overflow: hidden;
  border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 72px; height: 72px; font-size: 1.4rem; }
.avatar.xs { width: 28px; height: 28px; font-size: .65rem; }
.user-chip {
  display: flex; align-items: center; gap: .55rem;
  border: 1px solid var(--border); background: var(--card);
  padding: .3rem .65rem .3rem .35rem; border-radius: var(--r-full);
  cursor: pointer; max-width: min(220px, 42vw); overflow: hidden;
}
[dir='rtl'] .user-chip { padding: .3rem .35rem .3rem .65rem; }
.user-chip .u-meta { min-width: 0; flex: 1; overflow: hidden; text-align: start; }
/* spans are inline by default — ellipsis/overflow need block-level boxes */
.user-chip .u-name,
.user-chip .u-role { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .u-name { font-size: .8rem; font-weight: 650; }
.user-chip .u-role { font-size: .66rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .08em; }
.menu-pop {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 80;
  min-width: 220px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: .4rem;
  animation: popIn .16s ease;
}
@keyframes popIn { from { opacity: 0; transform: translateY(-6px);} to { opacity: 1; transform: none;} }
.menu-pop .mi {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: .55rem .65rem; border: 0; background: none; color: var(--text);
  border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-sm); text-align: start;
  text-decoration: none;
}
.menu-pop .mi:hover { background: var(--card-2); text-decoration: none; }
.menu-pop .mi.danger { color: var(--danger); }
.menu-pop .sep { height: 1px; background: var(--border); margin: .3rem 0; }
.menu-anchor { position: relative; }

/* Content */
.content {
  flex: 1;
  width: 100%; max-width: var(--content-max);
  margin-inline: auto;
  padding: clamp(1.5rem, 3vw, 2.2rem) clamp(.85rem, 2.5vw, 1.6rem) calc(var(--bottomnav-h) + 1.6rem);
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-block-end: 1.25rem;
}
.page-head h1 { margin: 0; font-size: clamp(1.35rem, 2.4vw, 1.75rem); }
.page-head .sub { color: var(--text-2); font-size: var(--fs-sm); margin-block-start: .2rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 70;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-block-end: env(safe-area-inset-bottom, 0px);
  background: var(--header-bg); backdrop-filter: blur(12px);
  border-block-start: 1px solid var(--border);
  box-shadow: 0 -12px 28px -18px rgba(14, 23, 18, .4);
  display: none; align-items: stretch;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-3); font-size: .64rem; font-weight: 600;
  text-decoration: none; min-width: 0; padding: .3rem .1rem; position: relative;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a.active::after {
  content: ''; position: absolute; top: 0; width: 28px; height: 3px;
  background: var(--gold); border-radius: 0 0 4px 4px;
}
.bottom-nav a.active::before {
  /* native-app selected pill behind icon + label */
  content: ''; position: absolute; inset: 5px 15% 4px; z-index: -1;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.bottom-nav a .nav-badge {
  position: absolute; top: 4px; inset-inline-end: calc(50% - 22px);
  background: var(--danger); color: #fff; font-size: .58rem; font-weight: 750;
  border-radius: 99px; padding: 0 .3rem; border: 1.5px solid var(--bg);
}

/* Drawer / mobile nav overlay */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 90; background: var(--overlay);
  opacity: 0; pointer-events: none; transition: opacity var(--speed);
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.sidebar.drawer-open { transform: none; }

/* ---------- Breakpoints ---------- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-2); }
  [dir='rtl'] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: none; }
  .content { padding-block-end: calc(var(--bottomnav-h) + 1.5rem); }
}
@media (min-width: 1025px) {
  .shell { padding-inline-start: var(--sidebar-w); }
  .menu-toggle { display: none !important; }
  .drawer-overlay { display: none !important; }
  .bottom-nav { display: none !important; }
}
@media (max-width: 768px) {
  .bottom-nav { display: flex; }
  .topbar-title .sub { display: none; }
  .user-chip .u-meta { display: none; }
  .user-chip { padding: .25rem; border: 0; background: transparent; }
}
@media (max-width: 390px) {
  .content { padding-inline: .65rem; }
  .topbar { gap: .2rem; padding-inline: .45rem; }
}

/* RTL sidebar auto flip handled by logical props; icons stay LTR-safe */
[dir='rtl'] .nav-item.active::before { background: var(--gold); }


/* motion: active nav accent grows in */
@keyframes navBarY { from { transform: scaleY(0); } }
.nav-item.active::before { animation: navBarY .3s cubic-bezier(.2, .8, .3, 1); transform-origin: center; }
@keyframes navBarX { from { transform: scaleX(0); } }
.bottom-nav a.active::after { animation: navBarX .3s cubic-bezier(.2, .8, .3, 1); transform-origin: center; }

/* ---------- Phone app pass: rhythm, tap targets, drawer fit ---------- */
@media (max-width: 768px) {
  .content {
    /* content clears the tab bar incl. the iPhone home-indicator strip */
    padding-block: .95rem calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + .95rem);
  }
  .page-head { gap: .6rem; margin-block-end: .95rem; }
  .page-head h1 { font-size: 1.26rem; }
  .page-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: .5rem; width: 100%; }
  .page-actions .btn { width: 100%; min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; } /* 44px = Apple HIG minimum target */
  .nav-item { padding: .72rem .8rem; }
  .sidebar { width: min(var(--sidebar-w), 86vw); transition: transform .3s cubic-bezier(.32, .72, 0, 1); }
}
.topbar, .sidebar, .bottom-nav, .icon-btn, .user-chip, .menu-pop { user-select: none; -webkit-user-select: none; } /* chrome never highlights as text */
@media (pointer: coarse) {
  /* touch devices: no visible scrollbar chrome, native apps scroll bare */
  html, body, .sidebar-nav, .table-wrap { scrollbar-width: none; }
  html::-webkit-scrollbar, body::-webkit-scrollbar, .sidebar-nav::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { width: 0; height: 0; }
}
