.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100%;
  overflow: hidden;
}

/* ---------- Barre latérale ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: var(--header-height);
  padding: 0 0.625rem 0 0.875rem;
  flex: none;
}

.sidebar-title {
  flex: 1;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 20px;
}

.sidebar-footer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}

.category {
  margin-bottom: 2px;
}

.category-head {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  padding: 0.31rem 0.375rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.category-head:hover {
  background: var(--bg-hover);
}

.category-head .chevron {
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s ease;
}

.category[data-collapsed="true"] .chevron {
  transform: rotate(-90deg);
}

.category[data-collapsed="true"] .category-lists {
  display: none;
}

.category-name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-lists {
  padding: 1px 0 6px;
}

.list-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.44rem 0.625rem 0.44rem 1.5rem;
  border-radius: var(--radius);
  text-align: left;
  font-size: 0.875rem;
  color: var(--text);
}

.list-link:hover {
  background: var(--bg-hover);
}

.list-link[aria-current="true"] {
  background: var(--bg-selected);
  font-weight: 500;
}

.list-link .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-link .count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.list-link .grip {
  display: grid;
  place-items: center;
  width: 18px;
  margin-right: -4px;
  color: var(--text-faint);
  opacity: 0;
  cursor: grab;
  touch-action: none;
  transition: opacity 0.15s ease;
}

.list-link .grip svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.list-link:hover .grip {
  opacity: 1;
}

.add-list .grip {
  display: none;
}

/* ---------- Tri par glissement ---------- */

body.sorting {
  user-select: none;
  cursor: grabbing;
}

.list-link.dragging {
  opacity: 0.4;
}

.category-lists {
  position: relative;
}

.category-lists.drop-into {
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: var(--radius);
}

.list-link.drop-before::before,
.list-link.drop-after::after {
  content: "";
  position: absolute;
  left: 24px;
  right: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.list-link {
  position: relative;
}

.list-link.drop-before::before {
  top: -1px;
}

.list-link.drop-after::after {
  bottom: -1px;
}

.category-head .icon-button {
  width: 22px;
  height: 22px;
  opacity: 0;
}

.category-head .icon-button svg {
  width: 15px;
  height: 15px;
}

.category-head:hover .icon-button,
.category-head .icon-button:focus-visible {
  opacity: 1;
}

.add-list {
  color: var(--text-faint);
}

.add-list:hover {
  color: var(--text-muted);
}

.inline-edit {
  flex: 1;
  min-width: 0;
  padding: 2px 5px;
  margin: -2px 0;
  border-radius: 5px;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  font-size: 0.875rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.profile-button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 4px 6px;
  border-radius: var(--radius);
  text-align: left;
}

.profile-button:hover {
  background: var(--bg-hover);
}

.profile-button .avatar {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  border: none;
  font-size: 0.625rem;
}

.profile-gear {
  display: grid;
  place-items: center;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.profile-gear svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.profile-button:hover .profile-gear {
  opacity: 1;
}

@media (hover: none) {
  .profile-gear {
    opacity: 0.5;
  }
}

.profile-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84375rem;
  color: var(--text-muted);
}

/* ---------- Entrée « Ce qui reste » ---------- */

.overview-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.44rem 0.625rem;
  margin-bottom: 0.5rem;
  border-radius: var(--radius);
  text-align: left;
  font-size: 0.875rem;
  font-weight: 500;
}

.overview-link:hover {
  background: var(--bg-hover);
}

.overview-link[aria-current="true"] {
  background: var(--bg-selected);
}

.overview-link .name {
  flex: 1;
}

.overview-link .count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.overview-icon {
  width: 1rem;
  height: 1rem;
  flex: none;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Tiroir des catégories masquées ---------- */

.drawer {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  padding: 0.31rem 0.375rem;
  border-radius: var(--radius);
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.drawer-head:hover {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.drawer-head .chevron {
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s ease;
}

.drawer[data-open="false"] .chevron {
  transform: rotate(-90deg);
}

.drawer[data-open="false"] .drawer-body {
  display: none;
}

.drawer-label {
  flex: 1;
  text-align: left;
}

.drawer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.44rem 0.625rem 0.44rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-faint);
}

.drawer-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-show {
  flex: none;
  padding: 0.125rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
}

.drawer-show:hover {
  background: var(--bg-hover);
}

.sidebar-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-faint);
}

/* ---------- Panneau principal ---------- */

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--header-height);
  padding: 0 10px;
  flex: none;
}

.panel-header .back {
  display: none;
}

.panel-header .spacer {
  flex: 1;
}

.presence {
  display: flex;
  align-items: center;
  gap: -4px;
  padding-right: 4px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  margin-left: -6px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  font-size: 0.6875rem;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
}

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.panel-inner {
  max-width: 45rem;
  margin: 0 auto;
  padding: 0.25rem 1.5rem 0;
}

.list-title {
  width: 100%;
  padding: 0.75rem 0 0.25rem;
  font-size: 1.5625rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  resize: none;
  overflow: hidden;
}

.list-meta {
  padding-bottom: 0.875rem;
  font-size: 0.78125rem;
  color: var(--text-faint);
}

/* ---------- Écran vide ---------- */

.blank {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--text-faint);
}

.blank svg {
  width: 46px;
  height: 46px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.blank p {
  font-size: 0.875rem;
  max-width: 34ch;
}

/* ---------- Menu contextuel ---------- */

.menu {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  padding: 5px;
  border-radius: 11px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  text-align: left;
  font-size: 0.875rem;
}

.menu button:hover {
  background: var(--bg-hover);
}

.menu button.danger {
  color: var(--danger);
}

.menu hr {
  height: 1px;
  margin: 5px 6px;
  border: none;
  background: var(--line);
}

/* ---------- Bandeau hors-ligne ---------- */

.offline-bar {
  flex: none;
  padding: 5px 12px;
  text-align: center;
  font-size: 0.78125rem;
  font-weight: 500;
  color: #4a3a12;
  background: var(--accent-soft);
}

/* ---------- Responsive ---------- */

@media (max-width: 780px) {
  .shell {
    grid-template-columns: 100%;
    grid-template-rows: 100%;
    /* Le balayage horizontal appartient à l'application, pas au navigateur. */
    touch-action: pan-y pinch-zoom;
    overscroll-behavior-x: none;
  }

  .sidebar,
  .panel {
    grid-area: 1 / 1;
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* Pendant un glissement, le panneau suit le doigt : aucune transition. */
  .shell.swiping .sidebar,
  .shell.swiping .panel {
    transition: none;
  }

  .panel {
    transform: translateX(100%);
    box-shadow: -1px 0 0 var(--line);
  }

  .shell[data-view="list"] .sidebar {
    transform: translateX(-22%);
  }

  .shell[data-view="list"] .panel {
    transform: translateX(0);
  }

  .panel-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  }

  .sidebar-header {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  }

  .panel-header .back {
    display: flex;
    align-items: center;
    gap: 2px;
    padding-right: 6px;
    color: var(--accent);
    font-size: 0.9375rem;
  }

  .panel-header .back svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .panel-inner {
    padding: 4px 18px 0;
  }

  .list-title {
    font-size: 1.4375rem;
  }
}
