/* ==========================================================================
   App shell — sidebar, sticky topbar, content grid, responsive behaviour
   Breakpoints: 1440 desktop · 1024 tablet · 390 mobile
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns var(--t-base) var(--ease);
}
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--z-sticky);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-5);
  height: var(--topbar-h);
  flex: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--s-4) var(--s-3);
}
.nav-group + .nav-group { margin-top: var(--s-5); }
.nav-group-label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 var(--s-3) var(--s-2);
  white-space: nowrap;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  min-height: 46px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item .nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.nav-item.is-active {
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: var(--fw-semibold);
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--s-3));
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 22px;
  border-radius: 0 3px 3px 0;
  background: var(--brand-primary);
}

.nav-badge {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  padding: 1px 7px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  flex: none;
}

.sidebar-foot { padding: var(--s-3); flex: none; border-top: 1px solid var(--border); }

.upgrade-card {
  border-radius: var(--r-md);
  padding: var(--s-4);
  background: var(--grad-accent);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.upgrade-card::after {
  content: "";
  position: absolute;
  width: 130px; height: 130px;
  right: -50px; bottom: -60px;
  border-radius: 50%;
  background: rgba(255,255,255,.16);
}

/* Collapsed state — icons only */
.shell.is-collapsed .nav-label,
.shell.is-collapsed .nav-group-label,
.shell.is-collapsed .logo span,
.shell.is-collapsed .nav-badge,
.shell.is-collapsed .sidebar-foot { display: none; }
.shell.is-collapsed .nav-item { justify-content: center; padding: var(--s-3) 0; }
.shell.is-collapsed .sidebar-head { justify-content: center; padding: var(--s-5) 0; }

/* --------------------------------------------------------------------------
   Main column & topbar
   -------------------------------------------------------------------------- */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: calc(var(--z-sticky) - 1);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-6);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.topbar-search { flex: 1; max-width: 460px; }
.topbar-search .input { min-height: 42px; background: var(--surface-2); }

.kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-3);
}

.notif-btn { position: relative; }
.notif-dot {
  position: absolute;
  top: 7px; right: 8px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
}

.page {
  padding: var(--s-6);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  animation: page-in var(--t-slow) var(--ease-out);
}
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: var(--s-6); }
.page-title { font-size: var(--fs-h2); font-weight: var(--fw-bold); letter-spacing: -.03em; }
.page-sub { color: var(--text-2); margin-top: var(--s-2); }

/* Mobile drawer scrim */
.scrim {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: calc(var(--z-drawer) - 1);
  animation: fade var(--t-base) var(--ease);
}

/* --------------------------------------------------------------------------
   Section helpers
   -------------------------------------------------------------------------- */

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
  flex-wrap: wrap;
}
.section-title { font-size: var(--fs-h3); font-weight: var(--fw-semibold); letter-spacing: -.02em; }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.toolbar .grow { min-width: 220px; }

/* --------------------------------------------------------------------------
   Responsive — 1024 tablet
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .col-3 { grid-column: span 6; }
  .col-4 { grid-column: span 6; }
  .col-8 { grid-column: span 12; }
  .col-9 { grid-column: span 12; }
  .col-5, .col-7 { grid-column: span 12; }
}

@media (max-width: 1024px) {
  .shell, .shell.is-collapsed { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--t-base) var(--ease);
    box-shadow: var(--e-4);
    z-index: var(--z-drawer);
  }
  .shell.is-open .sidebar { transform: none; }
  /* the drawer always shows full labels, even if collapsed on desktop */
  .shell.is-collapsed .nav-label,
  .shell.is-collapsed .nav-group-label,
  .shell.is-collapsed .logo span,
  .shell.is-collapsed .sidebar-foot { display: revert; }
  .shell.is-collapsed .nav-item { justify-content: flex-start; padding: var(--s-3); }
  .shell.is-collapsed .sidebar-head { justify-content: flex-start; padding: var(--s-5); }

  .page { padding: var(--s-5); }
  .topbar { padding: 0 var(--s-5); }
  .topbar-search { max-width: none; }
}

/* --------------------------------------------------------------------------
   Responsive — 390 mobile
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .grid { gap: var(--s-4); }
  .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9 { grid-column: span 12; }

  .page { padding: var(--s-4); }
  .topbar { padding: 0 var(--s-4); gap: var(--s-2); }
  .topbar-search { display: none; }
  .topbar-search.is-mobile-open {
    display: block;
    position: absolute;
    left: var(--s-4); right: var(--s-4);
  }

  .card { padding: var(--s-4); border-radius: var(--r-md); }
  .stat-value { font-size: 1.75rem; }
  .page-title { font-size: 1.5rem; }

  .fab { right: var(--s-4); bottom: var(--s-4); width: 54px; height: 54px; }
  .toast-region { left: var(--s-4); right: var(--s-4); bottom: var(--s-4); }
  .toast { min-width: 0; max-width: none; }
  .modal { padding: var(--s-5); border-radius: var(--r-lg); }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
  .sidebar, .topbar, .fab, .toast-region { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .page { padding: 0; max-width: none; }
}
