/* ==================== RESET & VARIABLES ==================== */
:root {
  --primary-50: #f0f9ff;
  --primary-100: #e0f2fe;
  --primary-200: #bae6fd;
  --primary-300: #7dd3fc;
  --primary-400: #38bdf8;
  --primary-500: #0ea5e9;
  --primary-600: #0284c7;
  --primary-700: #0369a1;
  --primary-800: #075985;
  --primary-900: #0c4a6e;

  --bg-main: #f4f7fc;
  --bg-card: #ffffff;
  --bg-sidebar: linear-gradient(180deg, #0f3460 0%, #1a4a7c 50%, #16609e 100%);

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;

  --border: #e8edf2;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 4px 10px rgba(0,0,0,0.04);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* 侧边栏略微加宽，避免标题过于拥挤 */
  --sidebar-width: 268px;

  --tab-height: 44px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #c5cdd8;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a0aab8;
}

/* ==================== LAYOUT ==================== */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 100;
  box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

/* ===== 顶部logo区域 ===== */
.sidebar-logo {
  padding: 24px 18px 20px;
  display: flex;
  justify-content: center;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: relative;
  width: 100%;
  overflow: hidden;
}

.sidebar-logo::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 18px;
  right: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

/* logo容器 - 垂直居中排列 */
.sidebar-logo .logo-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* logo图片 - 放大尺寸 */
.sidebar-logo .logo-img {
  width: 122px;
  height: 122px;
  flex-shrink: 0;
  object-fit: contain;
  display: block;
}

/* logo文字 - 居中显示在logo正下方 */
.sidebar-logo .logo-text {
  color: rgba(255,255,255,0.95);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
}

/* ==================== SIDEBAR NAV ==================== */
.sidebar-nav {
  flex: 1;
  padding: 10px 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  margin-bottom: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 10px 18px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  gap: 12px;
  font-size: 13.5px;
  user-select: none;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: linear-gradient(180deg, var(--primary-300), var(--primary-400));
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px rgba(125,211,252,0.5);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-item .nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-item .nav-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item .nav-arrow {
  display: flex;
  align-items: center;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.nav-item .nav-arrow svg {
  width: 14px;
  height: 14px;
  opacity: 0.5;
}

.nav-item.expanded .nav-arrow {
  transform: rotate(90deg);
}

.nav-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

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

.nav-sub .nav-item {
  padding-left: 48px;
  font-size: 13px;
}

.nav-sub .nav-item .nav-icon svg {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

/* ==================== SIDEBAR FOOTER ==================== */
.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.sidebar-footer .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.sidebar-footer .avatar.admin {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
}

.sidebar-footer .avatar.user {
  background: linear-gradient(135deg, #10b981, #34d399);
}

.sidebar-footer .avatar svg {
  width: 18px;
  height: 18px;
  color: rgba(255,255,255,0.9);
}

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

.sidebar-footer .user-name {
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  font-size: 13px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer .user-role-switch select {
  width: 100%;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
  font-size: 11px;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.sidebar-footer .user-role-switch select:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
}

.sidebar-footer .user-role-switch select option {
  background: #1e3a5f;
  color: #fff;
}

.sidebar-footer .logout-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.sidebar-footer .logout-btn svg {
  width: 16px;
  height: 16px;
  color: rgba(255,255,255,0.6);
}

.sidebar-footer .logout-btn:hover {
  background: rgba(239,68,68,0.2);
}

.sidebar-footer .logout-btn:hover svg {
  color: #f87171;
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-main);
}

/* ==================== TAB BAR ==================== */
.tab-bar {
  height: var(--tab-height);
  min-height: var(--tab-height);
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 6px 10px 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 3px;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  background: transparent;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
  min-width: 100px;
  max-width: 180px;
  position: relative;
  border: 1px solid transparent;
  border-bottom: none;
  animation: tabSlideIn 0.3s ease;
}

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

.tab-item:hover {
  background: var(--primary-50);
  color: var(--text-primary);
}

.tab-item.active {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: #ffffff;
  font-weight: 500;
  border-color: var(--primary-500);
  box-shadow: 0 -2px 8px rgba(14,165,233,0.15), 0 2px 4px rgba(0,0,0,0.05);
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: -1px;
  right: -1px;
  height: 2px;
  background: var(--primary-500);
}

.tab-item .tab-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.tab-item .tab-icon svg {
  width: 15px;
  height: 15px;
}

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

.tab-item .tab-close {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  opacity: 0;
  transition: var(--transition);
  flex-shrink: 0;
}

.tab-item:hover .tab-close {
  opacity: 0.6;
}

.tab-item.active .tab-close {
  opacity: 0.8;
  color: #ffffff;
}

.tab-item .tab-close:hover {
  background: rgba(255,255,255,0.25);
  opacity: 1;
}

.tab-item:not(.active) .tab-close:hover {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
  opacity: 1;
}

/* ==================== PAGE CONTAINER ==================== */
.page-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  background: var(--bg-main);
}

.page-frame.active {
  display: block;
  animation: frameIn 0.3s ease;
}

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

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1280px) {
  :root {
    --sidebar-width: 252px;
  }

  .sidebar-logo .logo-text {
    font-size: 15px;
  }
}

@media (max-width: 1100px) {
  :root {
    --sidebar-width: 240px;
  }

  .sidebar-logo {
    padding: 14px 16px;
    gap: 10px;
  }

  .sidebar-logo .logo-img {
    width: 40px;
    height: 40px;
  }

  .sidebar-logo .logo-text {
    font-size: 14px;
    line-height: 1.3;
  }

  .nav-item {
    padding: 9px 16px;
    font-size: 13px;
  }

  .nav-sub .nav-item {
    padding-left: 42px;
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-width: 220px;
  }

  .sidebar-logo .logo-text {
    font-size: 13px;
  }

  .sidebar-footer {
    padding: 14px 14px;
  }
}