.app-shell {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 52px;
  display: grid;
  grid-template-columns: minmax(0, var(--sidebar-width)) minmax(0, 1fr);
  grid-template-rows: minmax(52px, auto) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

.app-shell.sidebar-is-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 5px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar-leading {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.topbar-primary {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.topbar-title {
  min-width: 0;
}

.sidebar-toggle {
  flex: 0 0 auto;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--blue);
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
}

.sidebar-toggle [data-sidebar-toggle-arrow] {
  transform-origin: 10px 10px;
  transition: transform 140ms ease;
}

.sidebar-is-collapsed .sidebar-toggle [data-sidebar-toggle-arrow] {
  transform: scaleX(-1);
}

.topbar h1,
.workspace-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

.topbar h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
}

.brand-logo {
  display: block;
  height: 16px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  margin-bottom: 2px;
}

.login-panel .brand-logo {
  height: 20px;
  max-width: 180px;
}

.brand-wordmark {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  grid-column: 2;
  justify-content: center;
}

.topbar-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  grid-column: 3;
  justify-self: end;
  justify-content: flex-end;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  min-height: 28px;
  padding: 0 9px;
  font-size: 0.78rem;
}

.icon-only-button,
.icon-only-link {
  width: 30px;
  min-width: 30px;
  padding: 0;
}

.topbar-menu {
  position: relative;
}

.topbar-menu summary {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  list-style: none;
}

.topbar-menu summary::-webkit-details-marker {
  display: none;
}

.topbar-menu form {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: 240px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgb(21 25 34 / 16%);
}

.topbar-primary .topbar-menu form {
  right: auto;
  left: 0;
}

.topbar-menu .stacked-form.compact {
  margin-top: 0;
}

.metric {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.metric.healthy {
  color: var(--green);
}

.metric.warning {
  color: var(--amber);
}

.metric.checking {
  color: var(--blue);
}

.metric.danger {
  color: var(--red);
}

button.metric-filter {
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

button.metric-filter:hover {
  filter: none;
  border-color: #b7c6db;
  background: #edf3fc;
}

button.metric-filter.is-active,
button.metric-filter[aria-pressed="true"] {
  box-shadow: 0 0 0 2px rgba(39, 95, 159, 0.2);
}

button.metric-filter.healthy[aria-pressed="true"] {
  background: #eaf7f1;
  border-color: #97d5bc;
  box-shadow: 0 0 0 2px rgba(29, 127, 95, 0.18);
}

button.metric-filter.warning[aria-pressed="true"] {
  background: #fff4df;
  border-color: #e4c082;
  box-shadow: 0 0 0 2px rgba(165, 103, 24, 0.18);
}

button.metric-filter.checking[aria-pressed="true"] {
  background: #eaf2ff;
  border-color: #9bbce8;
  box-shadow: 0 0 0 2px rgba(39, 95, 159, 0.2);
}

button.metric-filter.danger[aria-pressed="true"] {
  background: #ffebeb;
  border-color: #e9a3a3;
  box-shadow: 0 0 0 2px rgba(184, 50, 50, 0.18);
}

.sidebar-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 8px 6px;
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: #e6eefc;
  font-size: 0.72rem;
  font-weight: 600;
}

.sidebar-clear-btn {
  min-height: 22px;
  padding: 0 7px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 600;
}

.sidebar-clear-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  filter: none;
}

.sidebar-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 18px 12px;
  text-align: center;
  color: var(--nav-muted);
  font-size: 0.76rem;
}

.sidebar-empty p {
  margin: 0;
}

.sidebar-is-collapsed .sidebar-filter-banner,
.sidebar-is-collapsed .sidebar-empty {
  display: none !important;
}

/* ── Sidebar shell ─────────────────────────────────────────────── */
.sidebar {
  grid-row: 2;
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: visible;
  background: var(--nav);
  color: var(--nav-ink);
  border-right: 1px solid var(--nav-border);
}

.sidebar-content {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar-content::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.sidebar-is-collapsed .app-tree-name,
.sidebar-is-collapsed .app-tree-chevron,
.sidebar-is-collapsed .app-add-link,
.sidebar-is-collapsed .environment-list {
  display: none;
}

.sidebar-is-collapsed .sidebar-content {
  padding-top: 7px;
}

.sidebar-is-collapsed .sidebar-search {
  justify-content: center;
  padding-right: 10px;
  padding-left: 10px;
}

.sidebar-is-collapsed .sidebar-search input {
  display: none;
}

.sidebar-is-collapsed .app-tree-header {
  justify-content: center;
  min-height: 40px;
  padding: 5px;
}

.sidebar-is-collapsed .app-mark {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  font-size: 0.68rem;
}

.sidebar-is-collapsed .app-tree + .app-tree {
  margin-top: 2px;
  padding-top: 2px;
}

.sidebar-is-collapsed .app-tree > summary {
  cursor: e-resize;
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -5px;
  bottom: 0;
  z-index: 12;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  right: 4px;
  bottom: 0;
  width: 2px;
  background: transparent;
  transition: background-color 120ms ease;
}

.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after,
.sidebar-is-resizing .sidebar-resizer::after {
  background: #82a9df;
}

.sidebar-resizer:focus-visible {
  outline: 2px solid #9bbce8;
  outline-offset: -3px;
}

.sidebar-is-resizing,
.sidebar-is-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

/* ── App group (project) ──────────────────────────────────────── */
.app-tree {
  position: relative;
  margin: 0;
}

.app-tree + .app-tree {
  border-top: 1px solid var(--nav-border);
  margin-top: 4px;
  padding-top: 4px;
}

/* project header row */
.app-tree-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  min-height: 28px;
  cursor: pointer;
  user-select: none;
}

.app-tree-header:hover {
  background: var(--nav-soft);
  border-radius: 5px;
}

.app-tree > summary {
  list-style: none;
  padding: 0;
}

.app-tree > summary::-webkit-details-marker {
  display: none;
}

.app-tree > summary {
  display: block;
}

/* chevron */
.app-tree-chevron {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  padding: 3px;
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  transition: transform 160ms ease;
}

.app-tree[open] .app-tree-chevron {
  transform: rotate(90deg);
}

.app-tree summary span:last-child,
.sidebar-panel summary span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* project avatar badge */
.app-mark {
  flex: 0 0 auto;
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* project name */
.app-tree-name {
  flex: 1 1 0;
  min-width: 0;
  margin-right: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--nav-ink);
  letter-spacing: 0em;
}

/* ── Add-endpoint inline button + popover ────────────────────── */
.app-add-link {
  position: absolute;
  top: 4px;
  right: 34px;
  z-index: 5;
}

.app-add-link > summary {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  min-height: 0;
  border-radius: 4px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
  list-style: none;
  transition: background 120ms;
}

.app-add-link > summary:hover {
  background: rgba(255,255,255,0.22);
}

.app-add-link > summary::-webkit-details-marker {
  display: none;
}

.app-add-link > form {
  position: absolute;
  top: calc(100% + 6px);
  right: -28px;
  left: auto;
  z-index: 30;
  width: 210px;
  border: 1px solid var(--nav-border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.app-add-link .stacked-form.compact {
  margin-top: 0;
}

/* ── Environment sections ─────────────────────────────────────── */
.environment-list {
  padding: 0;
}

.environment-group {
  margin: 0;
}

/* ── Endpoint links ───────────────────────────────────────────── */
.endpoint-link {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  margin: 1px 4px;
  border-radius: 4px;
  padding: 2px 5px;
  color: rgba(255,255,255,0.7);
  font-size: 0.74rem;
  font-weight: 400;
  transition: color 100ms, background 100ms;
}

.endpoint-env-tag {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 16px;
  padding: 0 5px;
  border-radius: 10px;
  border: 1px solid var(--nav-border);
  background: var(--nav-soft);
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--nav-muted);
  text-transform: uppercase;
}

.endpoint-url {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.endpoint-link:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.08);
}

.endpoint-link.active {
  background: rgba(255,255,255,0.14);
  color: #ffffff;
  font-weight: 500;
}

/* status text badge */
.status-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 15px;
  border-radius: 3px;
  padding: 0 5px;
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
}

.status-badge.healthy  { background: rgba(29,127,95,0.3);  color: #6de0b0; }
.status-badge.warning  { background: rgba(200,140,40,0.3); color: #ffc96e; }
.status-badge.expired  { background: rgba(200,60,60,0.3);  color: #ff8f8f; }
.status-badge.error    { background: rgba(200,60,60,0.3);  color: #ff8f8f; }
.status-badge.checking { background: rgba(60,120,210,0.3); color: #90bcf5; }

.dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.dot.healthy,
.status-block.healthy {
  background: #eaf7f1;
  color: var(--green);
}

.dot.warning,
.status-block.warning {
  background: #fff4df;
  color: var(--amber);
}

.dot.checking,
.status-block.checking {
  background: #eef5ff;
  color: var(--blue);
}

.dot.expired,
.dot.error,
.status-block.expired,
.status-block.error {
  background: #ffebeb;
  color: var(--red);
}

.dot.healthy {
  background: var(--green);
}

.dot.warning {
  background: var(--amber);
}

.dot.checking {
  background: var(--blue);
}

.dot.expired,
.dot.error {
  background: var(--red);
}

.sidebar-panel {
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 8px;
}

/* ── + APP / + endpoint / Import open as a centred overlay ───────────── */
/* The open summary's ::after is the backdrop: clicking it toggles the <details> shut. */
details.topbar-menu[open] > summary::after,
details.app-add-link[open] > summary::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1090;
  background: rgba(21, 25, 34, 0.45);
  cursor: default;
}
details.topbar-menu[open] > form,
details.app-add-link[open] > form,
.topbar-primary details.topbar-menu[open] > form {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  z-index: 1100;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(125vh - 64px); /* html is zoomed to 0.8 */
  overflow-y: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(21, 25, 34, 0.3);
}
details.app-add-link[open] > form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
  width: min(720px, calc(100vw - 32px));
}
details.app-add-link[open] > form > label { margin: 0; }
details.app-add-link[open] > form > .wide,
details.app-add-link[open] > form > .modal-head,
details.app-add-link[open] > form > button[type="submit"] { grid-column: 1 / -1; }
details.app-add-link[open] > form > button[type="submit"],
details.topbar-menu[open] > form > button[type="submit"] { justify-self: end; min-width: 120px; }
details.topbar-menu[open] > form { display: grid; gap: 12px; }
details.topbar-menu[open] > form input,
details.app-add-link[open] > form input:not([type="checkbox"]),
details.app-add-link[open] > form select { min-height: 34px; font-size: 0.86rem; }
details.app-add-link[open] > form label,
details.topbar-menu[open] > form label { font-size: 0.78rem; }
details.app-add-link[open] > form .check-label { align-self: end; min-height: 34px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 1.05rem; color: var(--ink); }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }
.modal-close { min-height: 0; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
details.topbar-menu > form > .modal-head, details.app-add-link > form > .modal-head { display: none; }
details.topbar-menu[open] > form > .modal-head, details.app-add-link[open] > form > .modal-head { display: flex; }
@media (max-width: 640px) {
  details.app-add-link[open] > form { grid-template-columns: minmax(0, 1fr); }
}
