.app-shell-main {
  max-width: var(--container);
  margin: 0 auto;
  padding: 16px 24px 20px;
}

.app-shell-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.app-shell-layout.full-width {
  grid-template-columns: minmax(0, 1fr);
}

.page-sidebar {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 14px;
  background: var(--surface-recessed);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.sidebar-card {
  padding: 16px;
  min-width: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.sidebar-card + .sidebar-card {
  border-top: 1px solid var(--border-subtle);
  padding-top: 16px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sidebar-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-action {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.theme-filter-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.theme-filter-link,
.theme-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: transparent;
  min-width: 0;
  overflow: hidden;
}

.theme-filter-link:hover,
.theme-filter-pill:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.theme-filter-link.active,
.theme-filter-pill.active {
  color: var(--accent);
  background: rgba(108, 99, 255, 0.1);
  border-color: rgba(108, 99, 255, 0.24);
}

.theme-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.theme-filter-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-stats {
  display: grid;
  gap: 10px;
}

.sidebar-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  border-radius: var(--radius-inset);
  background: var(--ambient-accent);
  border: 1px solid var(--border-subtle);
}

.sidebar-stat-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.sidebar-stat-copy {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.sidebar-progress {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}

.sidebar-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(138, 144, 168, 0.18);
}

.sidebar-progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--danger);
}

.sidebar-progress-copy {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-progress-copy strong {
  font-size: 24px;
  line-height: 1;
}

.page-content {
  min-width: 0;
}

/* Desktop: collapse trigger hidden, body always visible */
.sidebar-collapse-trigger {
  display: none;
}

/* On mobile, the sidebar-header inside collapse-body is hidden (title is in the trigger) */
@media (max-width: 1100px) {
  .sidebar-header-desktop {
    display: none;
  }
}

.list-page,
.form-page,
.stats-page,
.dashboard-page,
.message-page,
.auth-page {
  display: grid;
  gap: 20px;
}

/* ── Page Hero ── */

.page-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 32px;
  border-radius: var(--radius-lg);
  color: #fff;
  background: linear-gradient(135deg, var(--navy) 0%, #2f2d72 58%, #3d1e6e 100%);
  box-shadow: var(--shadow-md);
}

.page-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 80% 10%, rgba(255, 255, 255, 0.12), transparent 22%),
    radial-gradient(circle at 0% 100%, rgba(0, 201, 167, 0.14), transparent 30%);
  pointer-events: none;
}

.page-hero-copy {
  position: relative;
  z-index: 1;
  max-width: 620px;
}

.page-hero-title {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 46px;
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.page-hero-lead {
  margin: 10px 0 0;
  max-width: 540px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  line-height: 1.65;
}

.page-hero .page-header-actions {
  position: relative;
  z-index: 1;
}

.page-hero-btn {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.page-hero-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.34);
}

/* Hero variants */
.page-hero--tasks {
  background: linear-gradient(135deg, var(--navy) 0%, #2f2d72 58%, #3d1e6e 100%);
}

.page-hero--tasks::before {
  background:
    radial-gradient(circle at 85% 15%, rgba(108, 99, 255, 0.2), transparent 28%),
    radial-gradient(circle at 5% 90%, rgba(0, 201, 167, 0.12), transparent 30%);
}

.page-hero--habits {
  background: linear-gradient(135deg, #065a4e 0%, #039c82 50%, var(--mint) 100%);
}

.page-hero--habits::before {
  background:
    radial-gradient(circle at 85% 15%, rgba(255, 255, 255, 0.14), transparent 24%),
    radial-gradient(circle at 5% 90%, rgba(0, 100, 80, 0.2), transparent 30%);
}

.page-hero--themes {
  background: linear-gradient(135deg, #3d1e6e 0%, #7b4bb5 50%, #c06040 100%);
}

.page-hero--themes::before {
  background:
    radial-gradient(circle at 85% 15%, rgba(255, 179, 71, 0.16), transparent 26%),
    radial-gradient(circle at 5% 90%, rgba(108, 99, 255, 0.14), transparent 30%);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-filter-pill {
  width: auto;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
}

.filter-card {
  display: grid;
  gap: 16px;
  padding: 18px 20px;
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.filters-grid.habits {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.filter-field {
  display: grid;
  gap: 6px;
}

.filter-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.input-control,
.textarea-control,
.select-control {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface-2);
  outline: 0;
}

.textarea-control {
  min-height: 118px;
  padding: 14px;
  resize: vertical;
}

.input-control:focus,
.textarea-control:focus,
.select-control:focus {
  border-color: rgba(108, 99, 255, 0.34);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.1);
}

.order-toggle {
  display: inline-flex;
  gap: 8px;
}

.btn-order.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 0;
}

.page-link.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.page-link.disabled {
  opacity: 0.5;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .app-shell-layout {
    grid-template-columns: 1fr;
  }

  .page-sidebar {
    position: static;
    order: 2;
  }

  .page-content {
    order: 1;
  }

  /* Collapsible sidebar sections on mobile */
  .sidebar-collapse-body {
    display: none;
  }

  .sidebar-collapse.open .sidebar-collapse-body {
    display: block;
  }

  .sidebar-collapse.open .sidebar-chevron {
    transform: rotate(180deg);
  }

  .sidebar-card {
    padding: 0;
  }

  .sidebar-card + .sidebar-card {
    border-top: 1px solid var(--border-subtle);
    padding-top: 0;
  }

  .sidebar-collapse-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
  }

  .sidebar-collapse-right {
    display: inline-flex;
    align-items: center;
    gap: 12px;
  }

  .sidebar-collapse-trigger .sidebar-chevron {
    color: var(--muted);
    font-size: 12px;
    transition: transform 200ms ease;
  }

  .sidebar-collapse[open] .sidebar-chevron {
    transform: rotate(180deg);
  }

  .sidebar-collapse-body {
    padding: 0 16px 14px;
  }
}

@media (max-width: 760px) {
  .app-shell-main {
    padding: 14px 16px 16px;
  }

  .page-hero {
    padding: 22px 18px;
    flex-direction: column;
  }

  .page-hero-title {
    font-size: 34px;
    line-height: 1;
  }

  .page-header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .page-header-actions .btn {
    width: 100%;
  }

  .filters-grid,
  .filters-grid.habits {
    grid-template-columns: 1fr;
  }

  .sidebar-progress-copy {
    align-items: center;
  }
}
