/* ========================================
   STM32 辅助开发集成平台 - 全局样式
   ======================================== */

/* --- CSS 变量 --- */
:root {
  --primary: #009688;
  --primary-dark: #00796B;
  --primary-light: #E0F2F1;
  --sidebar-bg: #F5F5F5;
  --sidebar-border: #E0E0E0;
  --content-bg: #FFFFFF;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --code-bg: #F6F8FA;
  --code-border: #E9ECEF;
  --accent: #FF5722;
  --success: #4CAF50;
  --warning: #FFC107;
  --border-color: #E0E0E0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 4px;
  --header-height: 56px;
  --sidebar-width: 260px;
  --max-content-width: 960px;
  --font-sans: system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", "JetBrains Mono", "Consolas", monospace;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--content-bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

ul, ol { padding-left: 1.5em; }

img { max-width: 100%; height: auto; }

/* --- 顶栏 --- */
#site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--primary);
  color: #fff;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  color: #fff !important;
  text-decoration: none !important;
  white-space: nowrap;
}

.logo:hover { opacity: 0.9; }

.header-search {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

/* 搜索引擎切换标签 */
.search-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 2px;
  flex-shrink: 0;
}
.search-tab {
  padding: 4px 8px;
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
  user-select: none;
  white-space: nowrap;
}
.search-tab:hover { color: #fff; background: rgba(255,255,255,0.1); }
.search-tab.active { color: #fff; background: rgba(255,255,255,0.25); font-weight: 600; }

#search-input {
  width: 260px;
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-sans);
  background: rgba(255,255,255,0.9);
  color: var(--text-primary);
  outline: none;
  transition: background 0.2s;
}

#search-input:focus { background: #fff; }

#search-btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius);
  background: transparent;
  color: #fff;
  font-size: 14px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

#search-btn:hover { background: rgba(255,255,255,0.15); }

/* 搜索下拉结果 */
.search-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  width: 380px;
  max-height: 400px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: none;
  z-index: 999;
}

.search-dropdown.show { display: block; }

.search-dropdown-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none !important;
  color: var(--text-primary) !important;
  transition: background 0.15s;
}

.search-dropdown-item:last-child { border-bottom: none; }

.search-dropdown-item:hover { background: var(--primary-light); }

.search-dropdown-item .sdi-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

.search-dropdown-item .sdi-preview {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-no-results {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* --- 页面布局 --- */
.wrapper {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* --- 侧边栏 (由 sidebar.css 处理详细样式) --- */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
}

/* --- 内容区 --- */
#content {
  flex: 1;
  max-width: var(--max-content-width);
  padding: 24px 40px 48px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* --- 移动端菜单按钮 (默认隐藏) --- */
#mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

#sidebar-overlay { display: none; }

/* --- 返回顶部 --- */
#back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s, transform 0.2s;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

#back-to-top.show { opacity: 1; visibility: visible; }
#back-to-top:hover { transform: translateY(-2px); background: var(--primary-dark); }

/* --- 页脚 --- */
.site-footer {
  margin-top: 44px;
  padding: 22px 0 14px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.9;
}

.site-footer__title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.site-footer__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.site-footer__meta .sep { color: #CFCFCF; }

.site-footer__meta a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.site-footer__meta a:hover { color: var(--primary); }

@media (max-width: 768px) {
  .site-footer { margin-top: 32px; padding: 18px 0 12px; }
}

/* --- 响应式 --- */
@media (max-width: 1024px) {
  #content { padding: 20px 24px 40px; }
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -280px;
    top: var(--header-height);
    z-index: 900;
    transition: left 0.3s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }
  #sidebar.open { left: 0; }

  #sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 899;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
  }
  #sidebar-overlay.show { opacity: 1; visibility: visible; }

  #mobile-menu-btn { display: block; }

  #content {
    padding: 16px 16px 32px;
    max-width: 100%;
  }

  #search-input { width: 160px; }
  .search-dropdown { width: calc(100vw - 32px); right: -70px; }
  .search-tab { font-size: 10px; padding: 3px 5px; }
  .search-tabs { display: none; /* 手机端隐藏标签，保留用搜索按钮直接跳转 */ }
}
