/* ============ App Shell: Sidebar + Topbar + Page ============ */
.app-shell { min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 70;
  transition: width .2s var(--ease-out);
}
.brand {
  height: var(--topbar-h); flex: none; display: flex; flex-direction: column;
  align-items: flex-start; justify-content: center; gap: 4px;
  padding: 0 16px; border-bottom: 1px solid var(--line-2);
}
.brand-logo { height: 21px; width: auto; display: block; }
.brand-logo-mark { display: none; height: 24px; width: 24px; }
.brand-sub { font-size: 10.5px; color: var(--ink-4); white-space: nowrap; letter-spacing: .1px; }
.nav { flex: 1; overflow-y: auto; padding: 12px 10px 8px; }
.nav-label {
  font-size: 10.5px; color: var(--ink-4); font-weight: 500;
  padding: 8px 10px 6px; letter-spacing: .06em;
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 10px; margin-bottom: 2px; border-radius: 7px;
  color: var(--ink-2); font-size: 13px; font-weight: 450; cursor: pointer;
  transition: background .15s, color .15s; user-select: none;
}
.nav-item .icon { color: var(--ink-4); flex: none; transition: color .15s; }
.nav-item:hover { background: #F5F8FD; color: var(--ink); }
.nav-item:hover .icon { color: var(--ink-2); }
.nav-item.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.nav-item.active .icon { color: var(--brand); }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 16px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.nav-item .nav-badge {
  margin-left: auto; min-width: 19px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #EEF2F8; color: var(--ink-3); font-size: 10.5px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}
.nav-item.active .nav-badge { background: #fff; color: var(--brand); }
.nav-item .nav-dot { margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--red); }
.nav-sub { margin-left: auto; font-size: 10px; color: var(--ink-4); font-weight: 400; }

.sidebar-foot { flex: none; padding: 10px 12px 14px; border-top: 1px solid var(--line-2); }
.role-card {
  border: 1px solid var(--brand-100); background: var(--brand-gradient-soft);
  border-radius: 9px; padding: 10px 11px;
}
.role-card-top { display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--brand-700); }
.role-card p { font-size: 10.5px; color: #5B7CAF; margin-top: 3px; line-height: 1.45; }
.role-card .role-switch {
  margin-top: 8px; width: 100%; height: 26px; border-radius: 5px; border: 1px solid var(--brand-100);
  background: #fff; color: var(--brand); font-size: 11px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; transition: .15s;
}
.role-card .role-switch:hover { background: var(--brand-50); border-color: var(--brand); }
.sidebar-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; padding: 0 2px; font-size: 10px; color: var(--ink-4); }
.sidebar-meta .ver { font-variant-numeric: tabular-nums; }

/* ---------- Main / Topbar ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .2s var(--ease-out); }
.topbar {
  position: sticky; top: 0; height: var(--topbar-h); flex: none; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar-toggle { display: none; }
.system-name { font-size: 15px; font-weight: 650; letter-spacing: -.2px; white-space: nowrap; flex: none; }
.topbar-logo-mark { display: none; height: 22px; width: 22px; flex: none; }
.system-name .sys-dot { color: var(--brand); }
.env-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px;
  border-radius: 4px; background: var(--brand-50); border: 1px solid var(--brand-100);
  color: var(--brand); font-size: 10.5px; font-weight: 500; white-space: nowrap;
}
.group-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
  border-radius: var(--r-pill); border: 1px solid var(--line); background: #fff;
  color: var(--ink-3); font-size: 11.5px; white-space: nowrap;
}
.group-chip .icon { color: var(--green); }
.group-chip b { color: var(--ink-2); font-weight: 600; }
.topbar-page { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12.5px; min-width: 0; overflow: hidden; white-space: nowrap; }
.topbar-page > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.topbar-page .slash { color: #D0D5DD; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.topbar-left { flex: 1 1 auto; overflow: hidden; }
.top-btn, .ai-entry, .env-chip, .group-chip, .user-chip .u-name, .user-chip .u-role { white-space: nowrap; }
.user-chip { flex: none; }
.top-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 9px;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--ink-2); font-size: 12.5px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.top-btn .icon { color: var(--ink-3); }
.top-btn:hover { background: #F3F6FB; color: var(--ink); }
.top-btn .top-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--red); color: #fff;
  font-size: 10px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums; margin-left: 1px;
}
.top-btn:hover .icon { color: var(--ink-2); }
.ai-entry {
  display: inline-flex; align-items: center; gap: 6px; height: 31px; padding: 0 12px;
  border: 0; border-radius: 7px; background: var(--brand-gradient); color: #fff;
  font-size: 12.5px; font-weight: 600; cursor: pointer; letter-spacing: .1px;
  box-shadow: var(--shadow-brand); transition: .18s var(--ease-out); margin-right: 2px;
}
.ai-entry:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -8px rgba(31, 107, 255, .65); }
.ai-entry:active { transform: none; }
.ai-entry .spark { opacity: .95; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 3px; margin-left: 6px;
  border-radius: var(--r-pill); cursor: pointer; transition: background .15s; border: 1px solid transparent;
}
.user-chip:hover { background: #F3F6FB; }
.user-chip .u-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip .u-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.user-chip .u-role { font-size: 10px; color: var(--ink-3); }
.user-chip .u-caret { color: var(--ink-4); margin-left: 1px; }

/* ---------- Page Root ---------- */
.page-root { flex: 1; padding: 20px var(--content-pad) 36px; width: 100%; max-width: 1560px; margin: 0 auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1400px) {
  .topbar-page { display: none; }
}
@media (max-width: 1320px) {
  .env-chip { display: none; }
}
@media (max-width: 1240px) {
  :root { --sidebar-w: 68px; --content-pad: 18px; }
  .brand { padding: 0; align-items: center; }
  .brand-logo, .brand-sub, .nav-label, .nav-item span, .nav-item .nav-badge, .nav-sub, .sidebar-foot { display: none; }
  .brand-logo-mark { display: block; }
  .nav { padding: 12px 10px; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item.active::before { left: -10px; }
  .topbar-page { display: none; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); width: 224px; transition: transform .22s var(--ease-out); }
  .sidebar.mobile-open { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar.mobile-open .brand { padding: 0 16px; align-items: flex-start; }
  .sidebar.mobile-open .brand-logo { display: block; }
  .sidebar.mobile-open .brand-logo-mark { display: none; }
  .sidebar.mobile-open .brand-sub, .sidebar.mobile-open .nav-label, .sidebar.mobile-open .nav-item span,
  .sidebar.mobile-open .nav-item .nav-badge, .sidebar.mobile-open .sidebar-foot { display: initial; }
  .sidebar.mobile-open .nav-item { justify-content: flex-start; padding: 0 10px; }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .system-name { display: none; }
  .topbar-logo-mark { display: block; }
  .topbar-left { gap: 8px; }
  .top-btn span { display: none; }
  .env-chip, .group-chip { display: none; }
  .user-chip .u-meta { display: none; }
  .page-root { padding: 14px 14px 28px; }
}
