/* ==========================================================================
   Layout — app shell, sidebar, header, grids
   ========================================================================== */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

/* --- sidebar ------------------------------------------------------------ */
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-4) var(--s-4);
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--line-1);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-2);
  color: var(--ink-1);
  font-size: var(--text-md);
  font-weight: 680;
  letter-spacing: var(--tracking-tighter);
}
.brand:hover {
  text-decoration: none;
  color: var(--ink-1);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--brand), var(--signal));
  color: #06090F;
  box-shadow: var(--glow-brand);
}
.brand-mark svg {
  width: 17px;
  height: 17px;
}
.brand .dim {
  color: var(--ink-3);
  font-weight: 560;
}

.site-switch {
  position: relative;
}
.site-switch select {
  background: var(--surface-3);
  border-color: var(--line-1);
  font-size: var(--text-sm);
  font-weight: 560;
  padding-left: 0.7rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  margin: 0 calc(var(--s-2) * -1);
  padding: 0 var(--s-2);
}

.nav-label {
  padding: var(--s-4) var(--s-3) var(--s-2);
  font-size: var(--text-3xs);
  font-weight: 680;
  letter-spacing: var(--tracking-kicker);
  text-transform: uppercase;
  color: var(--ink-4);
}
.nav-label:first-child {
  padding-top: var(--s-1);
}

.nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0.5rem var(--s-3);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 540;
  transition:
    background var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out);
}
.nav a:hover {
  background: var(--surface-3);
  color: var(--ink-1);
  text-decoration: none;
}
.nav a .icon {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--ink-3);
  transition: color var(--t-fast) var(--ease-out);
}
.nav a:hover .icon {
  color: var(--ink-2);
}
.nav a.active {
  background: var(--brand-soft);
  color: var(--ink-1);
  font-weight: 600;
}
.nav a.active .icon {
  color: var(--brand);
}
.nav a.active::before {
  content: "";
  position: absolute;
  left: -0.5rem;
  top: 50%;
  translate: 0 -50%;
  width: 3px;
  height: 18px;
  border-radius: var(--r-full);
  background: var(--brand);
  box-shadow: 0 0 10px -1px var(--brand);
}
.nav-count {
  margin-left: auto;
  min-width: 19px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: var(--text-3xs);
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}
.nav a.active .nav-count {
  background: var(--brand);
}

.sidebar-foot {
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  border: 1px solid var(--line-1);
  font-size: var(--text-xs);
  color: var(--ink-3);
  line-height: var(--leading-snug);
}
.sidebar-foot strong {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--ink-2);
  margin-bottom: 2px;
}

.live-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--good);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent);
  animation: pulse-dot 2.4s var(--ease-in-out) infinite;
}
@keyframes pulse-dot {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent);
  }
  55% {
    box-shadow: 0 0 0 5px transparent;
  }
}

/* --- shell -------------------------------------------------------------- */
.shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  height: var(--header-h);
  padding: 0 var(--s-6);
  background: color-mix(in srgb, var(--canvas) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-1);
}
.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.crumb {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--text-sm);
  min-width: 0;
}
.crumb .eyebrow {
  color: var(--ink-4);
  font-size: var(--text-2xs);
  font-weight: 640;
  letter-spacing: var(--tracking-kicker);
  text-transform: uppercase;
}
.crumb .sep {
  color: var(--ink-4);
}
.crumb strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 4px var(--s-3);
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line-1);
  font-size: var(--text-xs);
  color: var(--ink-2);
  font-weight: 540;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kbd {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line-2);
  background: var(--surface-3);
  font-family: var(--font-sans);
  font-size: var(--text-3xs);
  font-weight: 620;
  color: var(--ink-3);
  line-height: 1.4;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex: none;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease-out),
    color var(--t-fast) var(--ease-out),
    border-color var(--t-fast) var(--ease-out);
}
.icon-button:hover {
  background: var(--surface-3);
  border-color: var(--line-1);
  color: var(--ink-1);
}
.icon-button .icon {
  width: 16px;
  height: 16px;
}

.menu-toggle {
  display: none;
}

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--r-full);
  background: linear-gradient(140deg, var(--brand), var(--signal));
  color: #06090F;
  font-size: var(--text-xs);
  font-weight: 720;
}

/* --- main --------------------------------------------------------------- */
.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6) var(--s-6) var(--s-12);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
}
.main:focus {
  outline: none;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  align-items: center;
  padding: var(--s-5) var(--s-6);
  border-top: 1px solid var(--line-1);
  font-size: var(--text-xs);
  color: var(--ink-4);
}
.footer span {
  color: var(--ink-3);
}

/* --- grids -------------------------------------------------------------- */
.grid {
  display: grid;
  gap: var(--s-4);
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid-main {
  grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr);
}
.grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
}
.span-2 {
  grid-column: span 2;
}

@media (max-width: 1240px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-main,
  .grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2 {
    grid-column: auto;
  }
}

@media (max-width: 980px) {
  :root {
    --sidebar-w: 0px;
  }
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 272px;
    translate: -100% 0;
    transition: translate var(--t-base) var(--ease-out);
    background: var(--surface-1);
    box-shadow: var(--shadow-3);
  }
  body.menu-open .sidebar {
    translate: 0 0;
  }
  .menu-toggle {
    display: grid;
  }
  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    border: 0;
    padding: 0;
    background: #04070Ecc;
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) var(--ease-out);
  }
  body.menu-open .backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .main {
    padding: var(--s-4) var(--s-4) var(--s-10);
  }
  .header {
    padding: 0 var(--s-4);
  }
  .grid-2,
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (min-width: 981px) {
  .backdrop {
    display: none;
  }
}

@media (max-width: 860px) {
  /* The header must never be the thing that overflows the page. */
  .kbd,
  #add-site {
    display: none;
  }
  .host-chip {
    max-width: 150px;
  }
}

@media (max-width: 620px) {
  .host-chip,
  .crumb .eyebrow,
  .crumb .sep {
    display: none;
  }
  .header-right {
    gap: var(--s-2);
  }
  .crumb strong {
    max-width: 46vw;
  }
}
