/* ============================================================
 * layout.css — 布局系统
 * 融合 Bootstrap 栅格 + Layui 后台布局 + Tailwind 响应式
 * 依赖：design-tokens.css, utilities.css
 * ============================================================ */

/* ----------------------------------------------------------
 * 1. 应用整体布局
 * ---------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ----------------------------------------------------------
 * 2. 侧边栏（Layui 风格）
 * ---------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: #0e0e0e;
  border-right: 1px solid var(--dark-border-light);
  display: flex;
  flex-direction: column;
  z-index: var(--z-fixed);
  transition: width var(--transition-base), transform var(--transition-base);
  overflow: hidden;
}

/* 侧边栏折叠状态 */
.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-section-title,
.sidebar.collapsed .nav-item-text,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-footer-info {
  display: none;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .nav-item-icon {
  margin-right: 0;
}

/* 品牌区域 */
.sidebar-brand {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--dark-border-light);
  flex-shrink: 0;
  gap: var(--space-3);
}

.sidebar-brand-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: var(--font-bold);
  font-size: var(--text-lg);
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--dark-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 导航区域 */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-2);
}

/* 滚动条美化 */
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background-color: var(--dark-border);
  border-radius: var(--radius-full);
}

/* 导航分组 */
.nav-section {
  margin-bottom: var(--space-4);
}

.nav-section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--dark-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
  white-space: nowrap;
}

/* 导航项 */
.nav-item {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--dark-text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  gap: var(--space-3);
  position: relative;
}

.nav-item:hover {
  background-color: var(--dark-bg-hover);
  color: var(--dark-text);
}

.nav-item.active {
  background-color: rgba(247, 164, 29, 0.1);
  color: var(--color-primary-400);
  font-weight: var(--font-medium);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background-color: var(--color-primary-500);
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-base);
}

.nav-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 导航徽标 */
.nav-badge {
  font-size: var(--text-xs);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background-color: var(--color-danger-500);
  color: #fff;
  font-weight: var(--font-medium);
  line-height: 1.4;
  flex-shrink: 0;
}

.nav-badge.info {
  background-color: var(--color-info-500);
}

.nav-badge.success {
  background-color: var(--color-success-500);
}

/* 导航子菜单 */
.nav-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--transition-base);
}

.nav-submenu.open {
  max-height: 500px;
}

.nav-submenu .nav-item {
  padding-left: calc(var(--space-3) + 28px);
  font-size: var(--text-sm);
}

/* 侧边栏底部用户信息 */
.sidebar-footer {
  border-top: 1px solid var(--dark-border-light);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

.sidebar-footer-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.sidebar-footer-user:hover {
  background-color: var(--dark-bg-hover);
}

.sidebar-footer-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-400), var(--color-primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.sidebar-footer-info {
  flex: 1;
  min-width: 0;
}

.sidebar-footer-name {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--dark-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-role {
  font-size: var(--text-xs);
  color: var(--dark-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----------------------------------------------------------
 * 3. 主内容区
 * ---------------------------------------------------------- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition-base);
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed);
}

/* ----------------------------------------------------------
 * 4. 顶部栏（Bootstrap Navbar 风格）
 * ---------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background-color: #111111;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  z-index: var(--z-sticky);
  backdrop-filter: blur(8px);
}

.dark .topbar {
  background-color: rgba(17, 17, 17, 0.85);
  border-bottom-color: var(--dark-border-light);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

/* 侧边栏折叠按钮 */
.topbar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.topbar-toggle:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text);
}

/* 搜索框（顶部栏内） */
.topbar-search {
  position: relative;
  width: 280px;
}

.topbar-search-input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3) 0 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-tertiary);
  color: var(--color-text);
  font-size: var(--text-sm);
  outline: none;
  transition: all var(--transition-fast);
}

.topbar-search-input:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(247, 164, 29, 0.15);
}

.topbar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* 顶部栏图标按钮 */
.topbar-icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.topbar-icon-btn:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text);
}

.topbar-icon-btn .badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background-color: var(--color-danger-500);
  border: 2px solid var(--color-bg-secondary);
}

/* 顶部栏用户头像 */
.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.topbar-user:hover {
  background-color: var(--color-bg-tertiary);
}

.topbar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-400), var(--color-primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: var(--font-semibold);
  font-size: var(--text-xs);
}

/* ----------------------------------------------------------
 * 5. 页面内容区
 * ---------------------------------------------------------- */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

/* 页面视图（SPA 切换动画） */
.page-view {
  display: none;
  animation: pageFadeIn 0.3s ease-out;
}

.page-view.active {
  display: block;
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ----------------------------------------------------------
 * 6. 容器
 * ---------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--content-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

.container-sm {
  max-width: 640px;
}

.container-md {
  max-width: 768px;
}

.container-lg {
  max-width: 1024px;
}

.container-xl {
  max-width: 1280px;
}

.container-fluid {
  width: 100%;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

/* ----------------------------------------------------------
 * 7. Bootstrap 12 列栅格系统
 * ---------------------------------------------------------- */
.row {
  display: flex;
  flex-wrap: wrap;
  margin-left: calc(var(--space-2) * -1);
  margin-right: calc(var(--space-2) * -1);
}

.row > [class*="col-"] {
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

/* 列宽 */
.col-1  { flex: 0 0 8.333333%;  max-width: 8.333333%;  }
.col-2  { flex: 0 0 16.666667%; max-width: 16.666667%; }
.col-3  { flex: 0 0 25%;        max-width: 25%;        }
.col-4  { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-5  { flex: 0 0 41.666667%; max-width: 41.666667%; }
.col-6  { flex: 0 0 50%;        max-width: 50%;        }
.col-7  { flex: 0 0 58.333333%; max-width: 58.333333%; }
.col-8  { flex: 0 0 66.666667%; max-width: 66.666667%; }
.col-9  { flex: 0 0 75%;        max-width: 75%;        }
.col-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
.col-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
.col-12 { flex: 0 0 100%;       max-width: 100%;       }

.col-auto { flex: 0 0 auto; width: auto; }

/* 响应式列 — sm: >= 640px */
@media (min-width: 640px) {
  .col-sm-1  { flex: 0 0 8.333333%;  max-width: 8.333333%;  }
  .col-sm-2  { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-sm-3  { flex: 0 0 25%;        max-width: 25%;        }
  .col-sm-4  { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-sm-5  { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-sm-6  { flex: 0 0 50%;        max-width: 50%;        }
  .col-sm-7  { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-sm-8  { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-sm-9  { flex: 0 0 75%;        max-width: 75%;        }
  .col-sm-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-sm-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-sm-12 { flex: 0 0 100%;       max-width: 100%;       }
  .col-sm-auto { flex: 0 0 auto; width: auto; }
}

/* 响应式列 — md: >= 768px */
@media (min-width: 768px) {
  .col-md-1  { flex: 0 0 8.333333%;  max-width: 8.333333%;  }
  .col-md-2  { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-md-3  { flex: 0 0 25%;        max-width: 25%;        }
  .col-md-4  { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-md-5  { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-md-6  { flex: 0 0 50%;        max-width: 50%;        }
  .col-md-7  { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-md-8  { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-md-9  { flex: 0 0 75%;        max-width: 75%;        }
  .col-md-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-md-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-md-12 { flex: 0 0 100%;       max-width: 100%;       }
  .col-md-auto { flex: 0 0 auto; width: auto; }
}

/* 响应式列 — lg: >= 1024px */
@media (min-width: 1024px) {
  .col-lg-1  { flex: 0 0 8.333333%;  max-width: 8.333333%;  }
  .col-lg-2  { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-lg-3  { flex: 0 0 25%;        max-width: 25%;        }
  .col-lg-4  { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-lg-5  { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-lg-6  { flex: 0 0 50%;        max-width: 50%;        }
  .col-lg-7  { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-lg-8  { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-lg-9  { flex: 0 0 75%;        max-width: 75%;        }
  .col-lg-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-lg-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-lg-12 { flex: 0 0 100%;       max-width: 100%;       }
  .col-lg-auto { flex: 0 0 auto; width: auto; }
}

/* 响应式列 — xl: >= 1280px */
@media (min-width: 1280px) {
  .col-xl-1  { flex: 0 0 8.333333%;  max-width: 8.333333%;  }
  .col-xl-2  { flex: 0 0 16.666667%; max-width: 16.666667%; }
  .col-xl-3  { flex: 0 0 25%;        max-width: 25%;        }
  .col-xl-4  { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-xl-5  { flex: 0 0 41.666667%; max-width: 41.666667%; }
  .col-xl-6  { flex: 0 0 50%;        max-width: 50%;        }
  .col-xl-7  { flex: 0 0 58.333333%; max-width: 58.333333%; }
  .col-xl-8  { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-xl-9  { flex: 0 0 75%;        max-width: 75%;        }
  .col-xl-10 { flex: 0 0 83.333333%; max-width: 83.333333%; }
  .col-xl-11 { flex: 0 0 91.666667%; max-width: 91.666667%; }
  .col-xl-12 { flex: 0 0 100%;       max-width: 100%;       }
  .col-xl-auto { flex: 0 0 auto; width: auto; }
}

/* 栅格偏移 */
.offset-1  { margin-left: 8.333333%;  }
.offset-2  { margin-left: 16.666667%; }
.offset-3  { margin-left: 25%;        }
.offset-4  { margin-left: 33.333333%; }
.offset-5  { margin-left: 41.666667%; }
.offset-6  { margin-left: 50%;        }

/* 栅格排序 */
.order-first  { order: -1; }
.order-last   { order: 13; }
.order-0      { order: 0; }
.order-1      { order: 1; }
.order-2      { order: 2; }
.order-3      { order: 3; }
.order-4      { order: 4; }
.order-5      { order: 5; }
.order-6      { order: 6; }
.order-7      { order: 7; }
.order-8      { order: 8; }
.order-9      { order: 9; }
.order-10     { order: 10; }
.order-11     { order: 11; }
.order-12     { order: 12; }

/* ----------------------------------------------------------
 * 8. 侧边栏遮罩（移动端）
 * ---------------------------------------------------------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-fixed) - 1);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ----------------------------------------------------------
 * 9. 响应式布局 — 移动端适配
 * ---------------------------------------------------------- */
@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: var(--z-fixed);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .page-content {
    padding: var(--space-4);
  }

  .topbar-search {
    display: none;
  }
}

@media (max-width: 639px) {
  .page-content {
    padding: var(--space-3);
  }

  .topbar {
    padding: 0 var(--space-3);
  }

  .container {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

/* ----------------------------------------------------------
 * 10. 分隔线
 * ---------------------------------------------------------- */
.divider {
  height: 1px;
  background-color: var(--color-border);
  border: none;
  margin: var(--space-4) 0;
}

.divider-vertical {
  display: inline-block;
  width: 1px;
  height: 1em;
  background-color: var(--color-border);
  vertical-align: middle;
  margin: 0 var(--space-2);
}

/* ----------------------------------------------------------
 * 11. 页面头部
 * ---------------------------------------------------------- */
.page-header {
  margin-bottom: var(--space-6);
}

.page-header-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.page-header-desc {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: 0;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ----------------------------------------------------------
 * 12. 内容分隔（Tab 面板布局）
 * ---------------------------------------------------------- */
.tab-content {
  position: relative;
}

.tab-pane {
  display: none;
  animation: tabFadeIn 0.25s ease-out;
}

.tab-pane.active {
  display: block;
}

@keyframes tabFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
