/* ==========================================================================
   GMAP · چارچوب (AppShell): سایدبار راست، هدر، محتوا، شبکه
   دسکتاپ ≥۱۲۰۰: سایدبار ۲۴۰ | تبلت ۷۶۸–۱۱۹۹: ریل آیکنی ۷۲ | موبایل <۷۶۸: drawer
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--shell-pad);
  padding: var(--shell-pad);
  max-width: var(--shell-max);
  margin-inline: auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============================== Sidebar ============================== */
.sidebar {
  position: sticky;
  top: var(--shell-pad);
  height: calc(100vh - var(--shell-pad) * 2);
  height: calc(100dvh - var(--shell-pad) * 2);
  display: flex; flex-direction: column;
  background: var(--c-surface);
  border-radius: var(--r-2xl);
  padding: 20px 14px 14px;
  min-width: 0;
  z-index: var(--z-sticky);
}
:root[data-theme="dark"] .sidebar { border: 1px solid var(--c-border); }

.sb-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 10px 20px;
  color: var(--c-text); text-decoration: none !important;
  border-radius: var(--r-md);
}
.brand-mark { width: 40px; height: 40px; flex-shrink: 0; border-radius: 12px; }
.brand-text { min-width: 0; line-height: 1.15; }
.brand-name { display: block; direction: ltr; text-align: start; font-size: 22px; font-weight: 800; letter-spacing: .02em; }
.brand-tag { display: block; font-size: 11px; color: var(--c-muted); font-weight: 500; margin-top: 3px; white-space: nowrap; }

.sb-nav { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; margin-inline: -6px; padding-inline: 6px; scrollbar-width: none; }
.sb-nav::-webkit-scrollbar { display: none; }
.sb-group + .sb-group { margin-top: 18px; }
.sb-group-title {
  padding: 0 12px 8px; font-size: 12px; font-weight: 600; color: var(--c-muted);
  white-space: nowrap;
}
.sb-list { display: flex; flex-direction: column; gap: 2px; }
.sb-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  height: 46px; padding-inline: 12px;
  border-radius: var(--r-md);
  color: var(--c-text-2); font-size: 15px; font-weight: 500;
  text-decoration: none !important; white-space: nowrap;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.sb-link .icon { width: 22px; height: 22px; color: var(--c-muted); transition: color var(--t-fast) ease; }
.sb-link:hover { background: var(--c-surface-2); color: var(--c-text); }
.sb-link:hover .icon { color: var(--c-text-2); }
.sb-link[aria-current="page"] { background: var(--c-primary-soft); color: var(--c-primary-text); font-weight: 700; }
.sb-link[aria-current="page"] .icon { color: var(--c-primary-text); }
.sb-link .sb-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sb-link .count { flex-shrink: 0; }
.sb-link.is-danger, .sb-link.is-danger .icon { color: var(--c-danger); }
.sb-link.is-danger:hover { background: var(--c-danger-soft); }

.sb-foot { padding-top: 12px; margin-top: 8px; border-top: 1px solid var(--c-divider); display: flex; flex-direction: column; gap: 2px; }
.sb-storage { padding: 12px; margin-bottom: 8px; border-radius: var(--r-lg); background: var(--c-surface-2); }
.sb-storage-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--c-muted); margin-bottom: 8px; gap: 8px; }
.sb-storage-head strong { color: var(--c-text); font-weight: 700; }

.sb-close { display: none; }

/* ============================== Main column / Topbar ============================== */
.main-col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

.topbar {
  position: sticky; top: var(--shell-pad); z-index: var(--z-sticky);
  box-shadow: 0 calc(var(--shell-pad) * -1) 0 var(--c-bg); /* پوشاندن محتوای اسکرول‌شده بالای هدر */
  display: flex; align-items: center; gap: 12px;
  height: var(--header-h);
  padding-inline: 16px;
  background: var(--c-surface);
  border-radius: var(--r-xl);
  min-width: 0;
}
:root[data-theme="dark"] .topbar { border: 1px solid var(--c-border); }
.tb-icon.topbar-burger, .tb-icon.tb-search-icon-btn { display: none; }

.tb-search {
  flex: 1 1 auto; max-width: 560px; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding-inline: 16px 6px;
  border-radius: var(--r-lg);
  background: var(--c-surface-2);
  border: 1px solid transparent;
  color: var(--c-muted); font-size: 15px;
  cursor: text; text-align: start;
  transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.tb-search:hover { border-color: var(--c-border); }
.tb-search .tb-search-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-search .kbd-wrap { display: inline-flex; gap: 4px; direction: ltr; }
.tb-search-go {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--c-primary); color: var(--c-on-primary);
}
.tb-search-icon-btn { display: none; }

.tb-actions { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.tb-icon {
  position: relative;
  width: 44px; height: 44px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--c-surface-2); color: var(--c-text-2);
  transition: background-color var(--t-fast) ease;
}
.tb-icon:hover { background: var(--c-surface-3); color: var(--c-text); }
.tb-icon[aria-expanded="true"] { background: var(--c-primary-soft); color: var(--c-primary-text); }
.tb-dot {
  position: absolute; top: 9px; inset-inline-end: 10px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c-danger); border: 2px solid var(--c-surface-2);
}
.tb-sep { width: 1px; height: 32px; background: var(--c-divider); margin-inline: 6px; }

.tb-profile {
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 6px 6px 6px 10px;
  border-radius: var(--r-lg);
  max-width: 240px; min-width: 0;
  transition: background-color var(--t-fast) ease;
}
.tb-profile:hover, .tb-profile[aria-expanded="true"] { background: var(--c-surface-2); }
.tb-profile-text { display: flex; flex-direction: column; text-align: start; min-width: 0; line-height: 1.3; }
.tb-profile-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-profile-role { font-size: 12px; color: var(--c-muted); white-space: nowrap; }
.tb-profile .icon.chev { width: 16px; height: 16px; color: var(--c-muted); }

/* ============================== Content ============================== */
.content { min-width: 0; overflow-wrap: break-word; outline: none; }
.content:focus-visible { outline: none; }
.page { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; animation: page-in var(--t-slow) var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px;
  flex-wrap: wrap; min-width: 0;
}
.page-head-text { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.page-title { font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: 700; }
.page-desc { color: var(--c-muted); font-size: 14px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.page-head.in-card { align-items: flex-start; margin-bottom: var(--sp-5); }

.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); min-width: 0; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }
.span-3 { grid-column: span 3; }
.col-stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }

/* ============================== Offline banner ============================== */
.net-banner {
  position: fixed; z-index: var(--z-toast); top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 10px 10px; border-radius: var(--r-lg);
  background: var(--c-text); color: var(--c-surface);
  box-shadow: var(--shadow-pop); font-size: 14px; font-weight: 600;
  animation: pop-in var(--t-med) var(--ease);
  max-width: calc(100vw - 24px);
}

/* ============================== Command palette ============================== */
.cmdk-layer { position: fixed; inset: 0; z-index: var(--z-dialog); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk {
  width: min(640px, 100%);
  background: var(--c-surface); border-radius: var(--r-2xl);
  box-shadow: var(--shadow-pop-lg); overflow: hidden;
  animation: modal-in var(--t-slow) var(--ease);
  display: flex; flex-direction: column; max-height: 70vh;
}
:root[data-theme="dark"] .cmdk { border: 1px solid var(--c-border); }
.cmdk.is-leaving { animation: modal-out var(--t-med) ease forwards; }
.cmdk-input-wrap { display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--c-divider); }
.cmdk-input-wrap .icon { color: var(--c-muted); }
.cmdk-input { flex: 1; height: 64px; border: 0; outline: 0; background: transparent; font-size: 17px; min-width: 0; }
.cmdk-list { overflow-y: auto; padding: 8px; }
.cmdk-group { padding: 10px 12px 6px; font-size: 12px; color: var(--c-muted); font-weight: 600; }
.cmdk-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 12px; text-align: start; font-size: 15px; }
.cmdk-item .icon { color: var(--c-muted); }
.cmdk-item small { color: var(--c-muted); font-size: 12px; margin-inline-start: auto; }
.cmdk-item.is-active { background: var(--c-primary-soft); color: var(--c-primary-text); }
.cmdk-item.is-active .icon { color: var(--c-primary-text); }
.cmdk-foot { display: flex; gap: 16px; padding: 10px 20px; border-top: 1px solid var(--c-divider); font-size: 12px; color: var(--c-muted); flex-wrap: wrap; }
.cmdk-foot span { display: inline-flex; align-items: center; gap: 6px; }

/* ============================== Auth (login) layout ============================== */
.auth {
  min-height: 100vh; min-height: 100dvh;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  padding: var(--shell-pad); gap: var(--shell-pad);
  max-width: var(--shell-max); margin-inline: auto;
}
.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 24px; }
.auth-art {
  position: relative; overflow: hidden;
  border-radius: 28px; padding: 40px;
  background: linear-gradient(160deg, #1D4ED8 0%, #2563EB 45%, #6D5DF6 100%);
  color: #fff; display: flex; flex-direction: column; justify-content: space-between; gap: 24px;
}
.auth-art h2 { font-size: 30px; line-height: 46px; font-weight: 800; }
.auth-art p { opacity: .85; font-size: 15px; line-height: 28px; max-width: 420px; }

/* ============================== Responsive ============================== */
/* تبلت: ریل آیکنی ۷۲ */
@media (max-width: 1199px) {
  .shell { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr); gap: var(--gap); padding: var(--gap); }
  .sidebar { top: var(--gap); height: calc(100vh - var(--gap) * 2); height: calc(100dvh - var(--gap) * 2); padding: 16px 10px 10px; align-items: stretch; }
  .sb-brand { justify-content: center; padding: 0 0 16px; }
  .brand-text, .sb-group-title, .sb-link .sb-text, .sb-storage { display: none; }
  .sb-group + .sb-group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--c-divider); }
  .sb-link { justify-content: center; padding: 0; height: 48px; }
  .sb-link .count { position: absolute; top: 4px; inset-inline-end: 4px; min-width: 18px; height: 18px; font-size: 10px; padding-inline: 4px; }
  .topbar { top: var(--gap); }
  .span-8, .span-7, .span-6, .span-5, .span-4, .span-3 { grid-column: span 12; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tb-profile-text { display: none; }
  .tb-profile { padding: 6px; }
  .tb-profile .icon.chev { display: none; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-art { display: none; }
}
@media (min-width: 900px) and (max-width: 1199px) {
  .tb-profile-text { display: flex; }
  .tb-profile { padding: 6px 6px 6px 10px; }
}

/* موبایل: drawer از راست */
@media (max-width: 767px) {
  :root { --shell-pad: 12px; --gap: 16px; }
  .shell { grid-template-columns: minmax(0, 1fr); padding: 12px 12px 24px; gap: 16px; }
  .sidebar {
    position: fixed; z-index: var(--z-dialog);
    top: 0; bottom: 0; inset-inline-start: 0;
    height: 100vh; height: 100dvh;
    width: min(300px, 86vw);
    border-radius: 0 0 0 0;
    border-start-end-radius: 0; border-end-end-radius: 0;
    padding: 16px 14px;
    transform: translateX(105%);
    visibility: hidden;
    transition: transform var(--t-slow) var(--ease), visibility 0s linear var(--t-slow);
    box-shadow: var(--shadow-pop-lg);
  }
  .sidebar.is-open { transform: none; visibility: visible; transition: transform var(--t-slow) var(--ease), visibility 0s; }
  .sb-brand { justify-content: flex-start; padding: 4px 10px 16px; }
  .brand-text, .sb-group-title, .sb-link .sb-text, .sb-storage { display: block; }
  .sb-group + .sb-group { margin-top: 16px; padding-top: 0; border-top: 0; }
  .sb-link { justify-content: flex-start; padding-inline: 12px; }
  .sb-link .count { position: static; min-width: 22px; height: 22px; font-size: 11px; }
  .sb-close { display: grid; position: absolute; top: 16px; inset-inline-end: 12px; }

  .topbar { top: 12px; height: 64px; padding-inline: 8px; gap: 6px; border-radius: var(--r-lg); }
  .tb-icon.topbar-burger { display: grid; }
  .tb-search { display: none; }
  .tb-icon.tb-search-icon-btn { display: grid; }
  .tb-sep { display: none; }
  .tb-icon { width: 44px; height: 44px; }
  .tb-hide-sm { display: none; }
  .tb-profile { height: 48px; }

  .page-title { font-size: 22px; line-height: 34px; }
  .card { padding: var(--sp-4); border-radius: var(--r-lg); }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .page-actions { width: 100%; }
  .page-actions > .btn { flex: 1 1 auto; }
  .auth { padding: 12px; }
  .auth-form-side { padding: 12px; }
}

.sb-overlay { display: none; }
@media (max-width: 767px) {
  .sb-overlay.is-open { display: block; position: fixed; inset: 0; z-index: var(--z-backdrop); background: var(--backdrop); animation: fade-in var(--t-med) ease; }
}

/* دکمهٔ ثانویه روی زمینهٔ صفحه (بیرون از کارت) باید از زمینه متمایز باشد */
.page-actions .btn-secondary, .page-head .btn-secondary { --btn-bg: var(--c-surface); --btn-bg-hover: var(--c-surface-2); --btn-bg-active: var(--c-surface-3); --btn-border: var(--c-border); }
.page-head.in-card .btn-secondary { --btn-bg: var(--c-surface-3); --btn-bg-hover: var(--c-surface-3-hover); --btn-border: transparent; }
