/* App shell: full-viewport grid, narrow collapsible sidebar, panels scroll internally. */

.root { height: 100vh; height: 100dvh; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns var(--dur-slow) var(--ease);
}
.shell.is-collapsed { --sidebar-w: var(--sidebar-w-collapsed); }

.skip-link {
  position: fixed;
  left: var(--sp-2);
  top: var(--sp-2);
  z-index: var(--z-toast);
  transform: translateY(-200%);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
}
.skip-link:focus-visible { transform: none; }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-2);
  gap: var(--sp-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2) var(--sp-2);
  min-height: 40px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--r);
  background: var(--primary);
  color: var(--on-primary);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: var(--fs-md); }
.brand-text small { color: var(--muted); font-size: var(--fs-xs); }

.nav-list { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 38px;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary-text);
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.sidebar-sep { width: 100%; border: 0; border-top: 1px solid var(--border); margin: var(--sp-2) 0; }

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 34px;
  padding: 0 var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.user-chip .icon { flex: none; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; padding: 4px 0; }
.user-name { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; }
.nav-logout, .nav-password { color: var(--text-2); }

.mock-flag {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
  padding: 6px var(--sp-3);
  border: 1px dashed var(--warning-border);
  border-radius: var(--r);
  background: var(--warning-soft);
  color: var(--warning-text);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.mock-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; margin: 0 5px; }

.shell.is-collapsed .nav-label { display: none; }
.shell.is-collapsed .nav-link,
.shell.is-collapsed .user-chip,
.shell.is-collapsed .mock-flag { justify-content: center; padding: 0; }
.shell.is-collapsed .mock-flag { padding: 6px 0; }
.shell.is-collapsed .brand { justify-content: center; padding-inline: 0; }
.shell.is-collapsed .sidebar-toggle svg { transform: scaleX(-1); }

/* ------------------------------------------------------------------- main */
.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
}
.page > * { flex: none; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.page-title { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
.page-title:focus-visible { outline-offset: 4px; }
.page-sub { color: var(--muted); font-size: var(--fs-sm); }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* Panels */
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  position: relative;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 46px;
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.panel-title { font-size: var(--fs-md); font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); }
.panel-tools { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); flex: none; }
.panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; }

/* Master–detail split */
.split {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: var(--sp-3);
}

/* -------------------------------------------------------- narrow screens */
@media (max-width: 1099px) {
  body { overflow: auto; }
  .root, .shell { height: auto; min-height: 100dvh; }
  .shell { min-height: 100vh; }
  .sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; }
  .main { overflow: visible; }
  .page { min-height: auto; }
  .split { grid-template-columns: 1fr; }
  .panel-list .panel-body { max-height: 40vh; }
}

@media (max-width: 760px) {
  .shell { --sidebar-w: var(--sidebar-w-collapsed); }
  .shell .nav-label { display: none; }
  .shell .nav-link, .shell .user-chip { justify-content: center; padding: 0; }
  .shell .mock-flag { justify-content: center; padding: 6px 0; }
  .shell .brand { justify-content: center; padding-inline: 0; }
  .sidebar-toggle { display: none; }
  .page { padding: var(--sp-3); }
}
