.app {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  z-index: var(--z-drawer);
  transition: width var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--topbar-h);
  padding-inline: var(--s-5);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
}

.brand__mark {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--primary), var(--violet));
  color: #fff;
  box-shadow: 0 6px 18px var(--primary-ring);
}
.brand__mark svg {
  width: 21px;
  height: 21px;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  overflow: hidden;
}
.brand__title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.brand__sub {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.sidebar__scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--s-4) var(--s-3) var(--s-2);
}

.nav__label {
  padding: var(--s-4) var(--s-3) var(--s-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-3);
  white-space: nowrap;
}
.nav__label:first-child {
  padding-top: 0;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 44px;
  padding: 0 var(--s-3);
  margin-bottom: 2px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav__item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav__item svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  stroke-width: 1.8;
}

.nav__item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav__item.is-active::before {
  content: '';
  position: absolute;
  inset-inline-start: calc(var(--s-3) * -1);
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: 0 var(--r-full) var(--r-full) 0;
  background: var(--primary);
}

.nav__badge {
  margin-inline-start: auto;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
}

@media (min-width: 1025px) {
  .app.is-mini .sidebar {
    width: var(--sidebar-w-mini);
  }
  .app.is-mini .brand__text,
  .app.is-mini .nav__item span,
  .app.is-mini .nav__badge {
    display: none;
  }
  .app.is-mini .sidebar__brand {
    justify-content: center;
    padding-inline: 0;
  }
  .app.is-mini .nav__item {
    justify-content: center;
    padding: 0;
  }
  .app.is-mini .main {
    margin-inline-start: var(--sidebar-w-mini);
  }
  .app.is-mini .nav__label {
    height: 1px;
    padding: 0;
    margin: var(--s-3) var(--s-2);
    overflow: hidden;
    background: var(--border-soft);
    color: transparent;
  }
}

.main {
  flex: 1;
  min-width: 0;
  margin-inline-start: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin var(--dur) var(--ease);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding-inline: var(--s-6);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  color: var(--text-2);
  border: 1px solid transparent;
  transition: all var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.icon-btn svg {
  width: 19px;
  height: 19px;
  stroke-width: 1.8;
}
/* The sidebar carries the panel identity on desktop; once it is hidden the
   topbar would start with dead space, so the panel name moves up here. */
.topbar__brand {
  display: none;
  min-width: 0;
  flex: 1;
}
.topbar__brand-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__search {
  position: relative;
  flex: 1;
  max-width: 380px;
}
.topbar__search svg {
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-3);
  pointer-events: none;
}
.topbar__search input {
  width: 100%;
  height: 40px;
  padding-inline: 38px var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  transition: all var(--dur-fast) var(--ease);
}
.topbar__search input::placeholder {
  color: var(--text-3);
}
.topbar__search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.topbar__search kbd {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--text-3);
  border: 1px solid var(--border);
}

.topbar__spacer {
  flex: 1;
}

.userchip {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 44px;
  padding: 0 var(--s-2) 0 var(--s-3);
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: all var(--dur-fast) var(--ease);
}
.userchip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.userchip__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.3;
}
.userchip__name {
  font-size: 13px;
  font-weight: 600;
}
.userchip__role {
  font-size: 11px;
  color: var(--text-3);
}
.userchip svg.chev {
  width: 15px;
  height: 15px;
  color: var(--text-3);
}

.page {
  flex: 1;
  padding: var(--s-6);
  max-width: 1560px;
  width: 100%;
  margin-inline: auto;
}

.page__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
  margin-bottom: var(--s-6);
}

.page__title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.page__title h1 {
  font-size: 23px;
}
.page__title p {
  font-size: 13.5px;
  color: var(--text-2);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 12.5px;
  color: var(--text-3);
  margin-bottom: var(--s-2);
}
.breadcrumb a:hover {
  color: var(--primary);
}
.breadcrumb svg {
  width: 13px;
  height: 13px;
}

.page__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.bottomnav {
  display: none;
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-drawer);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -4px 20px rgba(15, 22, 13, 0.06);
}

.bottomnav__scroll {
  display: flex;
  align-items: stretch;
  height: var(--bottomnav-h);
}

.bottomnav__item {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 4px 6px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.bottomnav__item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bottomnav__item svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
  transition: transform var(--dur) var(--ease);
}
.bottomnav__item:active svg {
  transform: scale(0.9);
}
.bottomnav__item.is-active {
  color: var(--primary-deep);
  font-weight: 600;
}
.bottomnav__item.is-active svg {
  stroke-width: 2.1;
}
.bottomnav__item.is-active::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-start: 50%;
  transform: translateX(50%);
  width: 26px;
  height: 3px;
  border-radius: 0 0 var(--r-full) var(--r-full);
  background: var(--primary);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}
.sheet.is-open {
  opacity: 1;
  visibility: visible;
}
.sheet__box {
  width: 100%;
  max-height: 78dvh;
  overflow-y: auto;
  padding: var(--s-3) var(--s-4)
    calc(var(--s-5) + var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--sh-pop);
  transform: translateY(100%);
  transition: transform var(--dur) var(--ease);
}
.sheet.is-open .sheet__box {
  transform: none;
}
.sheet__grab {
  width: 42px;
  height: 4px;
  margin: 0 auto var(--s-4);
  border-radius: var(--r-full);
  background: var(--border-strong);
}
.sheet__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: var(--s-3);
}
.sheet__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-3);
}
.sheet__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 88px;
  padding: var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  transition: all var(--dur-fast) var(--ease);
}
.sheet__item svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}
.sheet__item:active {
  transform: scale(0.97);
}
.sheet__item.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-weight: 600;
}

@media (max-width: 1024px) {
  .sidebar {
    display: none;
  }
  .bottomnav {
    display: block;
  }
  .main {
    margin-inline-start: 0;
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  }
  .topbar {
    padding-inline: var(--s-4);
  }
  .page {
    padding: var(--s-5) var(--s-4);
  }
  #btnSidebar {
    display: none;
  }
  .topbar__brand {
    display: block;
  }

  /* A blurred backdrop on a sticky bar forces a full repaint every scroll frame,
     which is what makes scrolling feel heavy on phones. Solid fill instead. */
  .topbar,
  .bottomnav {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .topbar {
    background: var(--bg);
  }
  .bottomnav {
    background: var(--surface);
  }
}

@media (max-width: 720px) {
  .topbar__search {
    display: none;
  }
  .userchip__meta {
    display: none;
  }
  .userchip {
    padding: 0;
    width: 44px;
    justify-content: center;
  }
  .userchip svg.chev {
    display: none;
  }
  .page__head {
    margin-bottom: var(--s-5);
  }
  .page__title h1 {
    font-size: 20px;
  }
}

/* Keep the head on one line: title on the start edge, actions on the end edge.
   The title truncates rather than sliding underneath the buttons. */
@media (max-width: 720px) {
  .page__head {
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--s-3);
  }
  .page__title {
    flex: 1;
    min-width: 0;
  }
  .page__title h1 {
    font-size: 19px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* The subtitle and breadcrumb only crowd the row here — the bottom nav
     already shows where you are, and the h1 repeats the last crumb. */
  .page__title p,
  .page__title .breadcrumb {
    display: none;
  }
  .page__actions {
    justify-content: flex-end;
    gap: var(--s-2);
    max-width: 62%;
  }
  .page__actions .btn {
    min-height: 36px;
    padding-inline: var(--s-3);
    font-size: 12.5px;
  }
  .page__actions .btn svg {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 420px) {
  .page__actions .btn {
    padding-inline: var(--s-2);
    gap: 5px;
  }
}
