/* Shell: sidebar + topbar + content layout */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  grid-area: sidebar;
  background: var(--sidebar);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid oklch(0% 0 0 / 0.2);
}
.sidebar__brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: oklch(96% 0.01 250);
  border-bottom: 1px solid oklch(0% 0 0 / 0.2);
}
.sidebar__brand-mark {
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--sidebar-active), oklch(72% 0.15 200));
  border-radius: 5px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
  color: white;
}
.sidebar__nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.sidebar__group-label {
  font-size: 11px;
  color: var(--sidebar-fg-dim);
  letter-spacing: 0.08em;
  padding: 12px 12px 6px;
  text-transform: uppercase;
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-fg);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 2px;
  position: relative;
}
.sidebar__item:hover { background: oklch(100% 0 0 / 0.05); color: oklch(95% 0.005 250); }
.sidebar__item.is-active {
  background: oklch(100% 0 0 / 0.08);
  color: white;
}
.sidebar__item.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--sidebar-active);
  border-radius: 0 2px 2px 0;
}
.sidebar__icon {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  flex: 0 0 16px;
  color: var(--sidebar-fg-dim);
}
.sidebar__item.is-active .sidebar__icon,
.sidebar__item:hover .sidebar__icon { color: white; }
.sidebar__chevron { margin-left: auto; opacity: 0.6; font-size: 11px; }

/* ===== Topbar ===== */
.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}
.topbar__crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.topbar__crumbs strong { color: var(--fg); font-weight: 600; }
.topbar__spacer { flex: 1; }
.topbar__search {
  position: relative;
  width: 260px;
}
.topbar__search input {
  width: 100%;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 0 12px 0 32px;
  font-size: 13px;
  color: var(--fg);
  outline: none;
}
.topbar__search input:focus { border-color: var(--primary); background: white; }
.topbar__search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
}
.topbar__icon-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
}
.topbar__icon-btn:hover { color: var(--fg); border-color: var(--border-strong); }
.topbar__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, oklch(70% 0.14 35), oklch(60% 0.18 350));
  display: grid; place-items: center;
  color: white;
  font-size: 11px;
  font-weight: 700;
}

/* ===== Main content area ===== */
.main {
  grid-area: main;
  padding: 16px 24px 24px;
  overflow-x: auto;
}

/* Page header (sits inside main) */
.page-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}
.page-head__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg-strong);
  margin: 0;
}
.page-head__sub {
  color: var(--muted);
  font-size: 12px;
}
.page-head__actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Tabs (under page-head, used on detail page) */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--fg); }
.tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab__count {
  background: var(--surface-alt);
  color: var(--muted);
  border-radius: 9px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 500;
}
.tab.is-active .tab__count {
  background: var(--primary-soft);
  color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* Responsive: at <=900px collapse sidebar to icon-only, hide search */
@media (max-width: 980px) {
  .app {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  }
  .sidebar__item span:not(.sidebar__chevron),
  .sidebar__group-label { display: none; }
  .sidebar__item { justify-content: center; padding: 10px 0; }
  .sidebar__brand { justify-content: center; padding: 0; }
  .sidebar__brand span { display: none; }
  .topbar__search { display: none; }
  .main { padding: 12px 16px 20px; }
}
