/* 全局样式 */
:root {
  --primary-color: #1e40af;
  --secondary-color: #3b82f6;
  --accent-color: #60a5fa;
  --text-color: #1f2937;
  --light-text: #f3f4f6;
  --border-color: #e5e7eb;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --dark-bg: #1f2937;
  --dark-secondary: #374151;
}

body {
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  color: var(--text-color);
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

/* 用户信息隐藏 */
#user-name, 
#user-role, 
#user-info, 
header .fa-user-circle,
aside img[alt="用户头像"] {
  display: none !important;
}

/* 导航栏样式 */
header {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 40;
  background-color: var(--dark-bg);
  color: white;
}

/* 顶部导航栏布局 */
header .container {
  justify-content: start !important;
}

header .container > div:last-child {
  margin-left: auto;
}

header h1,
header .text-gray-800 {
  color: white !important;
}

header .text-gray-700,
header .text-gray-600,
header .text-gray-500 {
  color: #e5e7eb !important;
}

/* 侧边栏样式 */
aside {
  height: calc(100vh - 56px);
  position: fixed;
  transition: width 0.3s ease, transform 0.3s ease;
  z-index: 30;
  top: 56px;
  background-color: var(--dark-bg);
  color: white;
  display: flex;
  flex-direction: column;
  padding-top: 0;
  margin-top: 0;
}

/* 侧边栏切换按钮 - 顶栏位置 */
#sidebar-toggle {
  display: flex !important; /* 在所有屏幕尺寸都显示 */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 响应式调整 - 增强移动端支持 */
@media (max-width: 768px) {
  body {
    font-size: 14px; /* 默认字体更小 */
  }
  
  header {
    padding: 0 10px;
  }
  
  header h1 {
    font-size: 16px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  /* 改进的移动端侧边栏 */
  aside {
    position: fixed;
    z-index: 40;
    transform: translateX(-100%);
    width: 240px !important;
    max-width: 80%;
    height: 100vh;
    top: 56px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease-in-out;
  }
  
  /* 展开状态 */
  aside.expanded {
    transform: translateX(0);
  }
  
  /* 收缩状态 */
  aside.collapsed {
    width: 64px !important;
  }
  
  /* 特殊的手机模式 - 即使在折叠状态下也显示完整侧边栏 */
  aside.mobile-expanded {
    width: 240px !important;
    transform: translateX(0);
  }
  
  aside.mobile-expanded .nav-text {
    display: block !important;
  }
  
  aside.mobile-expanded .nav-item a {
    justify-content: flex-start;
  }
  
  aside.mobile-expanded .nav-item a i {
    margin-right: 0.5rem !important;
  }
  
  /* 优化在移动设备上的显示 */
  #sidebar-toggle {
    display: flex !important;
    margin-right: 0.5rem;
  }
  
  /* 移动端菜单遮罩 */
  .menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 35;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .menu-overlay.show {
    display: block;
    opacity: 1;
  }
}

/* 侧边栏导航项图标 */
.nav-item i {
  transition: margin 0.3s ease;
}

/* 侧边栏导航项激活状态 */
.nav-item.active a {
  background-color: var(--secondary-color);
  color: white;
  font-weight: 500;
  border-radius: 0.375rem;
}

.nav-item a {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  color: #e5e7eb;
  border-radius: 0.375rem;
  transition: all 0.2s ease;
}

.nav-item a:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

/* 侧边栏搜索框样式 */
aside > div:first-child {
  padding: 0;
  margin: 0;
  width: 100%;
}

aside > div:first-child .relative {
  margin: 0;
  padding: 0;
}

aside input[type="text"] {
  background-color: var(--dark-secondary);
  border-color: #4b5563;
  color: white;
  border-radius: 0;
  padding-top: 10px;
  padding-bottom: 10px;
}

aside input[type="text"]:focus {
  box-shadow: none;
  border-color: var(--secondary-color);
}

aside input[type="text"]::placeholder {
  color: #9ca3af;
}

aside .fa-search {
  color: #9ca3af !important;
}

aside nav {
  padding: 0.75rem 1rem 1rem 1rem;
}

aside nav ul {
  margin-top: 0;
}

aside .p-4 + nav.p-4 {
  padding-top: 0 !important;
}

/* 主内容区域样式 */
.page-content {
  animation: fadeIn 0.3s ease-in-out;
}

/* 主内容区域的响应式布局 */
@media (min-width: 1024px) {
  main {
    margin-left: 16rem; /* 64px */
    width: calc(100% - 16rem);
    transition: margin-left 0.3s, width 0.3s;
  }
  
  main.sidebar-collapsed {
    margin-left: 4rem; /* 64px */
    width: calc(100% - 4rem);
  }
}

@media (max-width: 1023px) {
  main {
    margin-left: 0;
    width: 100%;
  }
  
  aside.mobile-expanded + main {
    filter: blur(2px);
    pointer-events: none;
  }
}

/* iframe样式 */
#content-frame {
  width: 100%;
  height: calc(100vh - 80px);
  border: none;
  overflow: auto;
  opacity: 0; /* 初始隐藏 */
  transition: opacity 0.3s ease;
}

/* iframe加载指示器 */
.loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f9fafb;
  z-index: 10;
}

.loader-spinner {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: #3b82f6;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* iframe显示状态 */
#content-frame.loaded {
  opacity: 1;
}

/* iframe容器样式 */
.iframe-container {
  width: 100%;
  height: calc(100vh - 80px); 
  overflow: hidden;
  background-color: #f9fafb;
  position: relative;
}

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

/* 状态标签样式 */
.status-badge {
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-draft {
  background-color: #e5e7eb;
  color: #4b5563;
}

.status-review {
  background-color: #fef3c7;
  color: #92400e;
}

.status-published {
  background-color: #d1fae5;
  color: #065f46;
}

/* 模板卡片样式 */
.template-card {
  transition: transform 0.2s, box-shadow 0.2s;
}

.template-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* 按钮样式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: #1e3a8a;
}

.btn-secondary {
  background-color: white;
  color: var(--primary-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #f9fafb;
}

/* 表单样式 */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

/* 平板媒体查询 - 改进 */
@media (min-width: 769px) and (max-width: 1024px) {
  .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4,
  .grid-cols-2.sm\:grid-cols-2.md\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  aside {
    width: 220px !important;
  }
  
  main {
    margin-left: 220px !important;
  }
  
  aside.collapsed + main {
    margin-left: 64px !important;
  }
  
  /* 平板字体大小优化 */
  body {
    font-size: 15px;
  }
  
  .p-6 {
    padding: 1.25rem !important;
  }
}

/* 小型桌面媒体查询 */
@media (min-width: 1025px) and (max-width: 1280px) {
  .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 0.75rem !important;
  }
}

/* 页面覆盖层 */
#overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 20;
}

/* 移动设备菜单按钮样式 */
#mobile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 0.25rem;
  cursor: pointer;
  background-color: transparent;
  border: 1px solid #e5e7eb;
}

#mobile-menu-toggle:hover {
  background-color: #f9fafb;
}

/* 预防内容溢出 */
img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
}

/* 移除底部导航，使用侧边栏代替 */
.mobile-nav-bottom {
  display: none !important;
}

@media (max-width: 640px) {
  /* 调整主内容区域，为侧边栏留出空间 */
  main {
    margin-left: 64px !important;
    width: calc(100% - 64px) !important;
    padding-bottom: 0;
  }
  
  /* 调整iframe容器高度，不再为底部导航预留空间 */
  .iframe-container,
  #content-frame {
    height: calc(100vh - 60px);
  }
  
  /* 隐藏移动菜单切换按钮，因为侧边栏始终可见 */
  #mobile-menu-toggle {
    display: none !important;
  }
  
  /* 隐藏菜单遮罩层，因为不再需要 */
  .menu-overlay {
    display: none !important;
  }
}

/* 侧边栏收缩状态 */
aside.collapsed {
  width: 64px !important;
}

aside.collapsed .nav-text {
  display: none !important;
}

aside.collapsed .nav-item a {
  justify-content: center;
  padding: 0.5rem;
}

aside.collapsed .nav-item a i {
  margin-right: 0 !important;
}

/* 侧边栏搜索框 */
aside.collapsed .w-full > .relative {
  display: none;
}