/* ==========================================================================
   App shell: sidebar, topbar, content area
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition);
}

.app-shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px var(--sp-4);
  flex-shrink: 0;
  overflow: hidden;
  background: #fff;
}
.sidebar-brand .logo-full-img {
  display: block;
  width: auto;
  max-width: 150px;
  max-height: calc(var(--topbar-h) - 16px);
  height: auto;
}
.sidebar-brand .logo-collapsed-img {
  display: none;
  width: 30px; height: 30px;
  object-fit: contain;
}
.logo-panel-label {
  flex-shrink: 0;
  text-align: center;
  padding: 6px var(--sp-4) 10px;
  border-bottom: 1px solid var(--sidebar-border);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}
.app-shell.collapsed .sidebar-brand { padding: 6px 8px; }
.app-shell.collapsed .logo-full-img { display: none; }
.app-shell.collapsed .logo-collapsed-img { display: block; }
.app-shell.collapsed .logo-panel-label { display: none; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}

.nav-group { margin-bottom: 16px; }
.nav-group-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  opacity: 0.55;
  padding: 0 10px;
  margin-bottom: 8px;
  white-space: nowrap;
}
.app-shell.collapsed .nav-group-title { opacity: 0; height: 0; margin: 0; overflow: hidden; }

.nav-item { position: relative; margin-bottom: 3px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.nav-link:hover { background: var(--sidebar-bg-elevated); color: #fff; }
.nav-link .nav-icon { width: 19px; height: 19px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.nav-link .nav-icon svg { width: 17px; height: 17px; stroke-width: 2.1; }
.nav-link .nav-label { flex: 1; }
.app-shell.collapsed .nav-label,
.app-shell.collapsed .nav-caret,
.app-shell.collapsed .nav-badge { display: none; }

.nav-item.active > .nav-link {
  background: var(--sidebar-active-bg);
  color: #fff;
  box-shadow: var(--sidebar-active-shadow);
}
.nav-item.active > .nav-link:hover { background: var(--sidebar-active-bg); }

.nav-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
}

.nav-caret { width: 14px; height: 14px; transition: transform var(--transition); color: var(--text-faint); }
.nav-item.expanded > .nav-link .nav-caret { transform: rotate(90deg); }

.nav-submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition);
  padding-left: 30px;
}
.nav-item.expanded .nav-submenu { max-height: 400px; }
.nav-submenu .nav-link { padding: 8px var(--sp-3); font-size: 13px; }
.app-shell.collapsed .nav-submenu { display: none; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-collapse-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--transition);
}
.sidebar-collapse-btn:hover { background: var(--sidebar-bg-elevated); color: #fff; }
.sidebar-collapse-btn svg { width: 16px; height: 16px; transition: transform var(--transition); }
.app-shell.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

/* ---------- Main area ---------- */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  transition: margin-left var(--transition);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-shell.collapsed .main-area { margin-left: var(--sidebar-w-collapsed); }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  gap: var(--sp-4);
}

.topbar-left { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; }

.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }

.topbar-title-block { min-width: 0; }
.topbar-breadcrumb { font-size: 12px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.topbar-page-title { font-size: var(--fs-lg); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

.notif-dot {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  width: 320px;
  color: var(--text-faint);
  cursor: pointer;
  transition: border var(--transition);
}
.topbar-search:hover { border-color: var(--border-strong); }
.topbar-search svg { width: 16px; height: 16px; flex-shrink: 0; }
.topbar-search span { font-size: var(--fs-sm); }
.topbar-search kbd {
  margin-left: auto;
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--text-faint);
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 8px 6px 6px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.user-menu-trigger:hover { background: var(--surface-hover); }
.user-menu-name { font-size: var(--fs-sm); font-weight: 600; line-height: 1.2; }
.user-menu-role { font-size: 11px; color: var(--text-faint); }
.user-menu-trigger .chevron { width: 14px; height: 14px; color: var(--text-faint); }

/* ---------- Dropdowns ---------- */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}
.dropdown-panel.open { opacity: 1; visibility: visible; transform: translateY(0); }

.dropdown-menu { width: 220px; padding: var(--sp-2); }
.dropdown-menu-header { padding: var(--sp-3); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-2); }
.dropdown-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--text);
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-hover); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-muted); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger svg { color: var(--danger); }

.notif-panel { width: 380px; max-height: 480px; display: flex; flex-direction: column; }
.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.notif-panel-header h4 { font-size: var(--fs-base); }
.notif-panel-header button { background: none; border: none; color: var(--primary); font-size: 12px; font-weight: 600; cursor: pointer; }
.notif-list { overflow-y: auto; flex: 1; }
.notif-row {
  display: flex; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}
.notif-row:hover { background: var(--surface-hover); }
.notif-row:last-child { border-bottom: none; }
.notif-row.unread { background: var(--primary-soft); }
.notif-row.unread:hover { background: var(--primary-soft-strong); }
.notif-icon {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.notif-icon svg { width: 16px; height: 16px; }
.notif-body { min-width: 0; flex: 1; }
.notif-msg { font-size: 13px; color: var(--text); line-height: 1.4; }
.notif-time { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.notif-panel-footer { padding: var(--sp-3); text-align: center; border-top: 1px solid var(--border); }
.notif-panel-footer a { font-size: 13px; font-weight: 600; color: var(--primary); }

/* ---------- Global search ---------- */
.search-modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 11, 20, 0.5);
  z-index: var(--z-modal-backdrop);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  opacity: 0; visibility: hidden; transition: opacity var(--transition), visibility var(--transition);
}
.search-modal-backdrop.open { opacity: 1; visibility: visible; }
.search-modal {
  width: 620px; max-width: 92vw;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(-10px);
  transition: transform var(--transition);
}
.search-modal-backdrop.open .search-modal { transform: translateY(0); }
.search-input-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.search-input-row svg { width: 20px; height: 20px; color: var(--text-faint); }
.search-input-row input { flex: 1; border: none; outline: none; background: transparent; font-size: var(--fs-md); color: var(--text); }
.search-input-row kbd { font-size: 11px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; }
.search-results { max-height: 420px; overflow-y: auto; padding: var(--sp-3); }
.search-group-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); padding: var(--sp-2) var(--sp-3); }
.search-result-item { display: flex; align-items: center; gap: var(--sp-3); padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer; }
.search-result-item:hover { background: var(--surface-hover); }
.search-result-item .srt { font-weight: 600; font-size: 13px; }
.search-result-item .srs { font-size: 12px; color: var(--text-faint); }
.search-empty { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- Page container ---------- */
.page-content {
  padding: var(--sp-6);
  flex: 1;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.page-header h1 { font-size: var(--fs-xl); }
.page-header p { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 4px; }
.page-header-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Mobile sidebar overlay */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 11, 20, 0.45);
  z-index: 45;
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}
.sidebar-overlay.open { opacity: 1; visibility: visible; }

.mobile-menu-btn { display: none; }
