/* ==========================================================================
   App shell: sidebar, header, content
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns var(--transition);
}
.app.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  overflow: hidden;
}
.sidebar-brand {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}
.brand-mark { width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 15px; color: var(--text); letter-spacing: -0.02em; white-space: nowrap; }
.brand-sub { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600; white-space: nowrap; }
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 10px 16px; }
.nav-section { margin-bottom: 6px; }
.nav-section-title {
  font-size: 10.5px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 12px 10px 6px; white-space: nowrap;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  height: 38px; padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500; font-size: 13.5px;
  white-space: nowrap;
  position: relative;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.nav-link.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
.nav-link .nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-footer { border-top: 1px solid var(--divider); padding: 10px; flex-shrink: 0; }
.sidebar-collapse-btn {
  display: flex; align-items: center; gap: 11px; width: 100%; height: 36px; padding: 0 10px;
  border-radius: var(--radius-sm); color: var(--text-3); font-size: 13px; font-weight: 500;
}
.sidebar-collapse-btn:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-collapse-btn svg { width: 18px; height: 18px; flex-shrink: 0; transition: transform var(--transition); }

.app.sidebar-collapsed .brand-text,
.app.sidebar-collapsed .nav-section-title,
.app.sidebar-collapsed .nav-link span,
.app.sidebar-collapsed .nav-link .nav-badge,
.app.sidebar-collapsed .sidebar-collapse-btn span { display: none; }
.app.sidebar-collapsed .nav-link { justify-content: center; padding: 0; }
.app.sidebar-collapsed .sidebar-brand { padding: 0; justify-content: center; }
.app.sidebar-collapsed .sidebar-collapse-btn { justify-content: center; padding: 0; }
.app.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.app.sidebar-collapsed .nav-section-title { height: 10px; padding: 0; }

/* ---------- Main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 var(--content-pad);
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.header-title { min-width: 0; }
.header-title h1 { font-size: 17px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.breadcrumb a { color: var(--text-3); }
.breadcrumb a:hover { color: var(--primary-600); text-decoration: none; }
.breadcrumb svg { width: 12px; height: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.mobile-menu-btn { display: none; }

.global-search { position: relative; width: 300px; }
.global-search input {
  width: 100%; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  padding: 0 64px 0 36px; font-size: 13px; color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.global-search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); background: var(--surface); }
.global-search > svg { position: absolute; left: 11px; top: 11px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.global-search kbd { position: absolute; right: 8px; top: 9px; }
.search-results {
  position: absolute; top: 44px; left: 0; right: 0; min-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 440px; overflow-y: auto; padding: 6px; z-index: 60;
}
.search-group-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); font-weight: 700; padding: 8px 10px 4px; }
.search-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.search-item:hover, .search-item.active { background: var(--surface-hover); }
.search-item svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.search-item .si-title { font-weight: 600; font-size: 13px; }
.search-item .si-sub { font-size: 12px; color: var(--text-3); }

.outlet-switcher { position: relative; }
.outlet-switcher select {
  appearance: none; -webkit-appearance: none;
  height: 38px; padding: 0 34px 0 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 13px;
  color: var(--text); cursor: pointer; max-width: 230px;
}
.outlet-switcher select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.outlet-switcher > svg { position: absolute; top: 11px; width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.outlet-switcher > svg.lead { left: 11px; color: var(--primary); }
.outlet-switcher > svg.trail { right: 11px; }
.outlet-locked {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  border-radius: var(--radius-sm); background: var(--primary-50); color: var(--primary-700);
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.outlet-locked svg { width: 15px; height: 15px; }

.header-icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); position: relative; border: 1px solid transparent;
}
.header-icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.header-icon-btn svg { width: 18px; height: 18px; }
.header-icon-btn .dot {
  position: absolute; top: 5px; right: 5px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface);
}
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px;
  border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface);
}
.user-chip:hover { border-color: var(--border-strong); }
.user-chip .uc-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-chip .uc-name { font-weight: 650; font-size: 12.5px; white-space: nowrap; }
.user-chip .uc-role { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.user-chip > svg { width: 14px; height: 14px; color: var(--text-3); }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 70;
  animation: pop-in 140ms ease-out;
}
.dropdown-header { padding: 10px 12px; border-bottom: 1px solid var(--divider); margin-bottom: 4px; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); text-align: left;
}
.dropdown-item:hover { background: var(--surface-hover); text-decoration: none; }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-3); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger svg { color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--divider); margin: 4px 0; }

.content { padding: var(--content-pad); flex: 1; min-width: 0; }
.content.flush { padding: 0; }
.demo-ribbon {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 11.5px; color: var(--text-3); padding: 14px var(--content-pad) 20px;
}
.demo-ribbon svg { width: 13px; height: 13px; }

@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.page-enter { animation: slide-up 220ms ease-out; }
