/* =====================================================================
 *  自定义样式 · 商务正式风格
 *  ---------------------------------------------------------------------
 *  主题色集中在 :root 变量里，换肤只需改这里。
 *  设计原则：克制用色、矩形结构、清晰层级，去除卡通感。
 * ===================================================================== */

:root {
  color-scheme: light;

  --brand: #1f4e79;            /* 主色：藏青 */
  --brand-strong: #17395c;     /* 主色加深（悬停/激活） */
  --brand-soft: #e9eef5;       /* 主色浅底 */

  --bg: #f2f4f7;               /* 页面背景 */
  --bg-soft: #f5f7fa;          /* 次级浅色面（图标瓦片/角标/悬停底色） */
  --card-bg: #ffffff;          /* 卡片背景 */
  --input-bg: #ffffff;         /* 输入框/按钮背景 */

  --text: #1b2430;             /* 正文 */
  --text-sub: #43505f;         /* 次级文本 */
  --muted: #6b7686;            /* 弱化文本 */
  --placeholder: #9aa4b2;      /* 占位符文本 */

  --border: #dde3ec;           /* 边框 */
  --border-strong: #c3ccda;    /* 强边框（输入框等） */
  --border-hover: #b9c6d8;     /* 卡片悬停边框 */
  --tile-border: #e2e7ef;      /* 图标瓦片边框 */

  --on-brand: #ffffff;         /* 主色底上的文字/图标 */
  --img-bg: #ffffff;           /* favicon 瓦片底（保持浅色保证可读） */
  --empty-accent: #b6bfcc;     /* 空状态图标色 */
  --dot: #c4ccd8;              /* 页脚分隔点 */

  --focus-ring: rgba(31, 78, 121, 0.12);

  --radius: 6px;               /* 统一小圆角 */

  --shadow-xs: 0 1px 2px rgba(20, 34, 55, 0.05);
  --shadow-sm: 0 1px 2px rgba(20, 34, 55, 0.06);
  --shadow-card: 0 1px 2px rgba(20, 34, 55, 0.05), 0 2px 8px rgba(20, 34, 55, 0.04);
  --shadow-card-hover: 0 2px 4px rgba(20, 34, 55, 0.06), 0 10px 24px rgba(31, 78, 121, 0.12);
}

/* =====================================================================
 *  深色主题
 *  ---------------------------------------------------------------------
 *  - 未手动选择时（无 data-theme 属性）：跟随系统 prefers-color-scheme
 *  - js/theme.js 保存用户选择后，以 html[data-theme] 强制覆盖
 * ===================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --brand: #7fb0e2;
    --brand-strong: #9cc4ec;
    --brand-soft: #1e3248;

    --bg: #12161d;
    --bg-soft: #202736;
    --card-bg: #1a212b;
    --input-bg: #161c25;

    --text: #e6ebf2;
    --text-sub: #b9c4d1;
    --muted: #8b96a6;
    --placeholder: #5f6b7c;

    --border: #2a3340;
    --border-strong: #3b4757;
    --border-hover: #46566b;
    --tile-border: #2e3947;

    --on-brand: #ffffff;
    --img-bg: #ffffff;
    --empty-accent: #45525f;
    --dot: #39434f;

    --focus-ring: rgba(127, 176, 226, 0.22);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.28);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 2px 10px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.42);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;

  --brand: #7fb0e2;
  --brand-strong: #9cc4ec;
  --brand-soft: #1e3248;

  --bg: #12161d;
  --bg-soft: #202736;
  --card-bg: #1a212b;
  --input-bg: #161c25;

  --text: #e6ebf2;
  --text-sub: #b9c4d1;
  --muted: #8b96a6;
  --placeholder: #5f6b7c;

  --border: #2a3340;
  --border-strong: #3b4757;
  --border-hover: #46566b;
  --tile-border: #2e3947;

  --on-brand: #ffffff;
  --img-bg: #ffffff;
  --empty-accent: #45525f;
  --dot: #39434f;

  --focus-ring: rgba(127, 176, 226, 0.22);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 2px 10px rgba(0, 0, 0, 0.2);
  --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================ 顶部导航栏 ============================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  /* 顶部藏青强调线，突出企业门户气质 */
  box-shadow: inset 0 3px 0 var(--brand), var(--shadow-xs);
}

.topbar-inner {
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}

/* 第一行：站点标识（左） + 搜索栏（右对齐） */
.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 10px;
}

/* 站点标识 */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 auto;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 5px;
  background: var(--brand);
  color: var(--on-brand);
}
.brand-logo svg { display: block; }

.brand-name {
  display: inline-block;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 1.5px;
  color: var(--muted);
}

/* 第二行：分类标签（允许占多行换行排列） */
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
}

.nav-item { display: flex; align-items: center; }

.tab-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  white-space: nowrap;          /* 标签名内部不允许换行，放不下则整签换行 */
  cursor: pointer;
  transition: color 0.15s ease;
}
.tab-link:hover { color: var(--text); }

.tab-link.active {
  color: var(--brand);
  font-weight: 600;
}
/* 激活下划线 */
.tab-link.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 2px;
  background: var(--brand);
}

/* 搜索栏（矩形输入框，同行右对齐） */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 320px;
  min-width: 200px;
}

.search-ico {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 32px 0 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--input-bg);
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--placeholder); }
.search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  position: absolute;
  right: 7px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover { background: var(--bg-soft); color: var(--text); }

/* 第一行右侧操作区：主题切换 + 搜索栏 */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;                 /* 允许收缩，避免移动端溢出 */
  max-width: 100%;
}

/* 主题切换按钮（搜索栏左侧，指示当前主题） */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--brand);
}
.theme-toggle svg { width: 17px; height: 17px; }

/* 浅色模式显示月亮（点击切深色），深色模式显示太阳（点击切浅色） */
.theme-toggle .icon-sun { display: none; }
.theme-toggle.is-dark .icon-sun { display: block; }
.theme-toggle.is-dark .icon-moon { display: none; }

/* 第一行右侧操作区：主题切换 + 搜索栏 */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 auto;
  min-width: 0;                 /* 允许收缩，避免移动端溢出 */
  max-width: 100%;
}

/* 主题切换按钮（搜索栏左侧，指示当前主题） */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--brand);
}
.theme-toggle svg { width: 17px; height: 17px; }

/* 浅色模式显示月亮（点击切深色），深色模式显示太阳（点击切浅色） */
.theme-toggle .icon-sun { display: none; }
.theme-toggle.is-dark .icon-sun { display: block; }
.theme-toggle.is-dark .icon-moon { display: none; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ============================ 主体 ============================ */
.main-container {
  flex: 1 1 auto;
  width: 100%;
  padding-top: 26px;
  padding-bottom: 48px;
}

.category-section {
  margin-bottom: 34px;
}

/* 分类标题：左侧竖线 + 标题 + 数量 */
.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-left: 10px;
  border-left: 3px solid var(--brand);
  line-height: 1;
}

.category-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.5px;
  color: var(--text);
}

.category-count {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

/* ============================ 网站卡片 ============================ */
.site-col { display: flex; }

.site-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.site-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover);
  color: var(--text);
}
.site-card:active {
  transform: translateY(0);
}

.site-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
  background: var(--bg-soft);
  font-size: 20px;
  overflow: hidden;
}
.site-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--img-bg);
}

/* 无图标时自动生成的首字母标识（正式化：白底 + 藏青字） */
.site-letter {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  color: var(--brand);
  font-size: 17px;
  font-weight: 600;
  font-family: Georgia, "Times New Roman", "PingFang SC", "Microsoft YaHei", serif;
}

.site-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.site-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.site-desc {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================ 空状态 ============================ */
.empty-state {
  padding: 64px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--empty-accent);
  box-shadow: var(--shadow-xs);
}
.empty-icon svg { width: 26px; height: 26px; }
.empty-text { margin: 14px 0 4px; font-size: 15px; color: var(--text); }
.empty-tip { margin: 0; font-size: 13px; }

/* ============================ 页脚 ============================ */
.footer {
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  padding: 14px 0;
}
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.3px;
}
.footer-dot { color: var(--dot); }

/* ============================ 响应式 ============================ */
@media (max-width: 767.98px) {
  .topbar-main { padding: 10px 0 8px; gap: 10px; }
  .search-box { flex: 1 1 180px; min-width: 0; }
  .tab-link { padding: 7px 10px; }
  .tab-link.active::after { left: 10px; right: 10px; }
  .site-card { padding: 12px 13px; }
  .site-icon { width: 38px; height: 38px; }
}

/* 超窄屏：隐藏品牌副标题，避免挤压搜索栏 */
@media (max-width: 479.98px) {
  .brand-sub { display: none; }
}