/* Shell: sidebar + topbar + content, mobile off-canvas drawer, minimal layout. */

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* --- Sidebar --------------------------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-3);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text-1);
  padding: var(--sp-1) var(--sp-2);
  margin-bottom: var(--sp-4);
}
.wordmark:hover { text-decoration: none; }
.wordmark .dot {
  width: 10px; height: 10px; border-radius: var(--r-full);
  background: var(--accent); flex: none;
}

.nav-section { margin-bottom: var(--sp-4); }
.nav-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-1);
}
.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 0.375rem var(--sp-2);
  border-radius: var(--r-md);
  border-left: 2px solid transparent;
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 120ms ease, color 120ms ease;
}
.nav-link:hover { background: var(--bg-inset); color: var(--text-1); text-decoration: none; }
.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
}
.nav-btn {
  width: 100%;
  border-top: 0; border-right: 0; border-bottom: 0;
  background: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  justify-content: flex-start;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* --- Topbar + content ------------------------------------------------- */
.main-col { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  min-height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-app);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title {
  font-size: var(--text-base);
  font-weight: 600;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-spacer { flex: 1; min-width: 0; }

.hamburger { display: none; }

.menu { position: relative; }
.menu > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.375rem var(--sp-2);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  color: var(--text-2);
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary:hover { background: var(--bg-inset); color: var(--text-1); }
.menu[open] > summary { background: var(--bg-inset); }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 12rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  padding: var(--sp-1);
  z-index: 30;
}
.menu-panel a, .menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.375rem var(--sp-2);
  border-radius: var(--r-md);
  color: var(--text-1);
  font-size: var(--text-sm);
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.menu-panel a:hover, .menu-panel button:hover {
  background: var(--bg-inset);
  text-decoration: none;
}

.content {
  width: 100%;
  max-width: 1200px;
  padding: var(--sp-5);
  margin: 0 auto;
  flex: 1;
}

.shell-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: var(--text-xs);
}

.backdrop { display: none; }

/* --- Mobile drawer ----------------------------------------------------- */
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 85vw);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: none;
  }
  .sidebar[data-open="true"] {
    transform: translateX(0);
    box-shadow: var(--shadow-pop);
  }

  .backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 0.4);
    z-index: 40;
    border: 0;
    padding: 0;
  }
  .backdrop[data-open="true"] { display: block; }

  .hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: 0;
    border-radius: var(--r-md);
    color: var(--text-1);
    cursor: pointer;
    font-size: var(--text-lg);
  }
  .hamburger:hover { background: var(--bg-inset); }

  .topbar { padding: var(--sp-2) var(--sp-3); }
  /* Longer page titles ("Assignments") plus the quick-add "+ Add" button
     plus a long signed-in email in the user menu can overflow a narrow
     (~390px) viewport. The title above already truncates; here the user
     menu's email summary also truncates so it yields space rather than
     pushing "+ Add" (which must stay fully visible/tappable) off-screen.
     The quick-add menu is excluded and kept at its intrinsic width. */
  .topbar > .menu:not(.quick-add-menu) { min-width: 0; flex-shrink: 1; }
  .topbar > .menu:not(.quick-add-menu) > summary {
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .quick-add-menu { flex-shrink: 0; }
  .content { padding: var(--sp-4) var(--sp-3); }
}

/* --- Minimal layout (login, token pages) ------------------------------- */
.minimal-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-size: var(--text-md);
}
.minimal-main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
}
.minimal-card {
  width: 100%;
  max-width: 26rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--sp-6) var(--sp-5);
  margin-top: var(--sp-8);
}
.minimal-card h1 { font-size: var(--text-2xl); margin-bottom: var(--sp-3); }
.minimal-card p { font-size: var(--text-md); }
.minimal-footer {
  text-align: center;
  padding: var(--sp-4);
  color: var(--text-3);
  font-size: var(--text-xs);
}
.minimal-ok {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem; height: 3rem;
  border-radius: var(--r-full);
  background: var(--ok-soft);
  color: var(--ok);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--sp-3);
}
@media (max-width: 480px) {
  .minimal-main { padding: var(--sp-4) var(--sp-3); }
  .minimal-card { margin-top: var(--sp-4); padding: var(--sp-5) var(--sp-4); }
}

@media (display-mode: standalone) {
  html, body {
    overscroll-behavior-y: contain;
  }
}

/* --- Pull to refresh (standalone PWA, touch only) ---------------------- */
.pull-refresh {
  --pull-travel: 0px;
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 60;
  display: none;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  padding-top: calc(var(--sp-2) + env(safe-area-inset-top, 0px));
  transform: translate(-50%, calc(-100% + var(--pull-travel)));
  transition: transform 200ms ease;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  box-shadow: var(--shadow-pop);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 500;
  pointer-events: none;
  white-space: nowrap;
}
.pull-refresh:not([hidden]) { display: flex; }
.pull-refresh[data-dragging="true"] { transition: none; }
.pull-refresh[data-state="ready"] { color: var(--accent); }
.pull-refresh[data-state="refreshing"] { color: var(--accent); }

.pull-refresh-spinner {
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: var(--r-full);
  border: 2px solid var(--border-strong);
  border-top-color: var(--text-3);
}
.pull-refresh[data-state="ready"] .pull-refresh-spinner {
  border-color: var(--accent-soft);
  border-top-color: var(--accent);
}
.pull-refresh[data-state="refreshing"] .pull-refresh-spinner {
  border-color: var(--accent-soft);
  border-top-color: var(--accent);
  animation: pull-refresh-spin 700ms linear infinite;
}
@keyframes pull-refresh-spin {
  to { transform: rotate(360deg); }
}
