/* =====================================================================
   App shell: sidebar (desktop ≥ 1024px), top bar / app bar, page head,
   help panel, phone tab bar, auth + error layouts.
   ===================================================================== */

/* ---- Brand ----------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-name {
  font-size: var(--text-lg);
  font-weight: 800;
}

.brand-sub {
  font-size: var(--text-xs);
  color: var(--text-3);
  font-weight: 500;
}

/* ---- Thin progress bar for htmx requests and navigations ---------------- */
.progress-top {
  position: fixed;
  inset-inline: 0;
  inset-block-start: 0;
  z-index: var(--z-progress);
  height: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}

.progress-top::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent-500), var(--brand-400), var(--brand-500));
  transform: scaleX(0);
  transform-origin: 100% 50%; /* grows from the start side (the page is always RTL) */
  transition: transform 8s cubic-bezier(0.1, 0.7, 0.1, 1);
}

.progress-top.is-active {
  opacity: 1;
}

.progress-top.is-active::before {
  transform: scaleX(0.9);
}

.progress-top.is-done::before {
  transform: scaleX(1);
  transition: transform var(--dur) var(--ease);
}

/* ---- Shell grid ------------------------------------------------------- */
.app {
  min-height: 100vh;
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Sidebar ---------------------------------------------------------- */
.sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: var(--z-sidebar);
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
  }

  .app-main {
    margin-inline-start: var(--sidebar-width);
  }
}

.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3) var(--space-4);
  scrollbar-width: thin;
}

.nav-section + .nav-section {
  margin-block-start: var(--space-4);
}

.nav-section-title {
  margin: 0 0 var(--space-1);
  padding-inline: var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-3);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-link .icon {
  color: var(--text-3);
  transition: color var(--dur-fast) var(--ease);
}

.nav-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 700;
}

.nav-link[aria-current="page"] .icon {
  color: var(--primary-text);
}

.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-inline-start: -12px;
  inset-block: 10px;
  width: 4px;
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  background: var(--primary);
}

.nav-label {
  flex: 1;
  min-width: 0;
}

.nav-badge {
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
}

.sidebar-foot {
  padding: var(--space-3);
  border-block-start: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
}

.sidebar-user:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.sidebar-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.4;
}

.sidebar-user-name {
  font-weight: 700;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: var(--text-xs);
  color: var(--text-3);
}

/* ---- Top bar (desktop) / app bar (phone) ------------------------------ */
.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--appbar-height);
  padding-inline: var(--space-4);
  padding-block: var(--space-2);
  background: var(--surface);
  border-block-end: 1px solid var(--border);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .topbar {
    background: hsl(var(--brand-hue) 20% 99% / 0.86);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
  }

  :root[data-theme="dark"] .topbar {
    background: hsl(var(--brand-hue) 16% 10% / 0.82);
  }

  @media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] .topbar {
      background: hsl(var(--brand-hue) 16% 10% / 0.82);
    }
  }
}

.topbar-brand {
  flex: none;
}

.topbar-brand .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.page-title {
  font-size: var(--text-lg);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-subtitle {
  color: var(--text-2);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.topbar .page-subtitle,
.topbar .topbar-search,
.topbar .user-menu-text,
.topbar .user-menu-chevron {
  display: none;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

@media (min-width: 1024px) {
  .topbar {
    min-height: var(--topbar-height);
    padding-inline: var(--space-8);
    gap: var(--space-5);
  }

  .topbar-brand {
    display: none;
  }

  .page-title {
    font-size: var(--text-xl);
  }

  .topbar .page-subtitle {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar .topbar-search {
    display: block;
    width: 260px;
  }

  .topbar .user-menu-text,
  .topbar .user-menu-chevron {
    display: flex;
  }

  .topbar-tools {
    gap: var(--space-3);
  }
}

@media (min-width: 1280px) {
  .topbar .topbar-search {
    width: 300px;
  }
}

/* Bell */
.bell {
  position: relative;
}

.bell-count:empty {
  display: none;
}

.bell-count {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
  pointer-events: none;
}

.bell-panel {
  width: min(380px, calc(100vw - 24px));
  padding: 0;
}

.bell-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-block-end: 1px solid var(--border);
  font-weight: 700;
}

.bell-panel-body {
  max-height: min(420px, 60vh);
  overflow-y: auto;
}

.bell-panel-foot {
  border-block-start: 1px solid var(--border);
  padding: var(--space-2);
}

/* User menu */
.user-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 2px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text);
}

@media (min-width: 1024px) {
  .user-menu-toggle {
    padding-block: 4px;
    padding-inline-start: 4px;
    padding-inline-end: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    transition: background-color var(--dur-fast) var(--ease);
  }

  .user-menu-toggle:hover {
    background: var(--surface-2);
  }
}

.user-menu-text {
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.35;
  text-align: start;
}

.user-menu-name {
  font-weight: 700;
  font-size: var(--text-sm);
  max-width: 140px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.user-menu-role {
  font-size: var(--text-xs);
  color: var(--text-3);
}

.user-menu-chevron {
  color: var(--text-3);
}

.user-menu-panel {
  width: 280px;
}

.user-menu-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
}

.user-menu-head-text {
  min-width: 0;
  line-height: 1.5;
}

/* ---- Page area -------------------------------------------------------- */
.page {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-4) var(--space-4) calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-8));
}

@media (min-width: 720px) {
  .page {
    padding-inline: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .page {
    padding: var(--space-6) var(--space-8) var(--space-12);
  }
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-block-end: var(--space-5);
}

.page-head:empty {
  display: none;
}

.page-head .page-subtitle {
  flex: 1 1 100%;
  font-size: var(--text-md);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex: 1 1 auto;
}

.page-head-help {
  margin-inline-start: auto;
}

@media (max-width: 719.98px) {
  .page-actions {
    flex: 1 1 100%;
  }

  .page-actions > .btn {
    flex: 1 1 100%;
  }
}

@media (min-width: 1024px) {
  .page-head .page-subtitle {
    display: none;
  }

  .page-head {
    justify-content: flex-end;
  }

  .page-actions {
    flex: 0 1 auto;
    order: 2;
  }

  .page-head-help {
    margin-inline-start: 0;
    margin-inline-end: auto;
    order: 1;
  }
}

/* Help panel («راهنمای این صفحه») */
.help-panel {
  position: relative;
  display: flex;
  gap: var(--space-4);
  margin-block-end: var(--space-5);
  padding: var(--space-5);
  padding-inline-end: var(--space-12);
  border-radius: var(--radius-lg);
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-2);
  animation: fade-down var(--dur-slow) var(--ease);
}

.help-panel-icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--accent-500);
  box-shadow: var(--shadow-xs);
}

.help-panel-title {
  font-weight: 800;
  margin-block-end: var(--space-2);
}

.help-panel ul {
  list-style: none;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.help-panel li {
  position: relative;
  padding-inline-start: var(--space-6);
  color: var(--text);
}

.help-panel li::before {
  content: "";
  position: absolute;
  inset-inline-start: 4px;
  inset-block-start: 0.7em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.help-panel-close {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-end: var(--space-2);
}

@media (max-width: 719.98px) {
  .help-panel {
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    padding-inline-end: var(--space-12);
  }
}

@keyframes fade-down {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---- Phone tab bar ------------------------------------------------------ */
.tabbar {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: var(--z-tabbar);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-block-end: var(--safe-bottom);
  background: var(--surface);
  border-block-start: 1px solid var(--border);
  box-shadow: 0 -4px 16px -8px hsl(var(--brand-hue) 30% 10% / 0.12);
}

@media (min-width: 1024px) {
  .tabbar {
    display: none;
  }
}

.tab-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 6px 2px 4px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
}

.tab-item:hover {
  text-decoration: none;
}

.tab-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 30px;
  border-radius: var(--radius-full);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.tab-item[aria-current="page"],
.tab-item.is-active {
  color: var(--primary-text);
  font-weight: 700;
}

.tab-item[aria-current="page"] .tab-icon,
.tab-item.is-active .tab-icon {
  background: var(--primary-soft-2);
}

.tab-label {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tab-badge {
  position: absolute;
  inset-block-start: -2px;
  inset-inline-end: 8px;
  min-width: 18px;
  height: 18px;
  padding-inline: 5px;
  border-radius: var(--radius-full);
  background: var(--accent-500);
  color: hsl(30 80% 12%);
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.tab-fab-slot {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.tab-fab {
  width: 58px;
  height: 58px;
  margin-block-start: -18px;
  display: grid;
  place-items: center;
  border: 4px solid var(--surface);
  border-radius: 50%;
  background: linear-gradient(160deg, var(--brand-500), var(--brand-700));
  color: #fff;
  box-shadow: var(--shadow-fab);
  transition: transform var(--dur) var(--ease);
}

.tab-fab:active {
  transform: scale(0.94);
}

/* Lists inside the phone sheets */
.sheet-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.sheet-section-title {
  margin: var(--space-4) 0 var(--space-1);
  padding-inline: var(--space-3);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-3);
}

.sheet-section-title:first-child {
  margin-block-start: 0;
}

.quick-grid {
  display: grid;
  gap: var(--space-3);
}

.quick-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}

.quick-card:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  text-decoration: none;
}

.quick-card-icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--primary-soft-2);
  color: var(--primary-text);
}

.quick-card .chevron {
  margin-inline-start: auto;
  color: var(--text-3);
}

/* ---- Auth / error layout ------------------------------------------------ */
.auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4) var(--space-10);
  background:
    radial-gradient(1000px 520px at 85% -10%, hsl(var(--brand-hue) 60% 50% / 0.16), transparent 60%),
    radial-gradient(800px 480px at 0% 110%, hsl(var(--accent-hue) 95% 55% / 0.12), transparent 60%),
    var(--bg);
}

@supports (min-height: 100dvh) {
  .auth {
    min-height: 100dvh;
  }
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: var(--space-8) var(--space-6);
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 479.98px) {
  .auth-card {
    padding: var(--space-6) var(--space-5);
  }
}

.auth-card-wide {
  max-width: 520px;
}

.auth-brand {
  display: flex;
  justify-content: center;
  margin-block-end: var(--space-6);
}

.auth-brand .brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
}

.auth-title {
  text-align: center;
  font-size: var(--text-2xl);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-2);
  margin-block: var(--space-2) var(--space-6);
}

.auth-foot {
  margin-block-start: var(--space-6);
  color: var(--text-3);
  font-size: var(--text-sm);
  text-align: center;
}

.auth-tools {
  position: fixed;
  inset-block-start: var(--space-3);
  inset-inline-end: var(--space-3);
}
