/*!
 * iohow Design System — Components v1.0
 * 依赖 tokens.css，必须先引入 tokens.css 再引入本文件。
 * CDN 建议路径：https://www.iohow.com/ds/v1/components.css
 */

/* ============ Reset & Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--ds-font-sans);
  font-size: var(--ds-text-base);
  line-height: var(--ds-leading-normal);
  color: var(--ds-text);
  background: var(--ds-bg);
  transition: background var(--ds-transition-base), color var(--ds-transition-base);
}
:focus-visible {
  outline: 2px solid var(--ds-focus-ring);
  outline-offset: 2px;
}
a { color: var(--ds-link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .ds-mono { font-family: var(--ds-font-mono); }

.ds-container {
  max-width: var(--ds-container-width);
  margin-inline: auto;
  padding-inline: var(--ds-space-4);
}
.ds-container--wide { max-width: var(--ds-container-wide); }

/* ============ 顶部导航 Header ============ */
.ds-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-4);
  padding: var(--ds-space-4) var(--ds-space-6);
  border-bottom: 1px solid var(--ds-border);
  background: var(--ds-bg-elevated);
}
.ds-header__brand {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-weight: 700;
  font-size: var(--ds-text-lg);
  color: var(--ds-text);
}
.ds-header__brand:hover { text-decoration: none; opacity: 0.85; }
.ds-header__back {
  /* 每个子站都放这个组件，指回导航页，形成反向导流 */
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-1);
  font-size: var(--ds-text-sm);
  color: var(--ds-text-muted);
}
.ds-header__nav { display: flex; gap: var(--ds-space-5); align-items: center; }

/* ============ Footer（所有子站统一） ============ */
.ds-footer {
  border-top: 1px solid var(--ds-border);
  padding: var(--ds-space-8) var(--ds-space-6);
  text-align: center;
  color: var(--ds-text-muted);
  font-size: var(--ds-text-sm);
}
.ds-footer__links { display: inline-flex; gap: var(--ds-space-3); flex-wrap: wrap; justify-content: center; }
.ds-footer__links a { color: var(--ds-text-muted); }
.ds-footer__note {
  margin-top: var(--ds-space-2);
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
}
/* 备案信息行：大陆合规强制项，所有子站 footer 必须包含 */
.ds-footer__beian {
  margin-top: var(--ds-space-3);
  font-size: var(--ds-text-xs);
  color: var(--ds-text-muted);
  display: flex; gap: var(--ds-space-2); justify-content: center; align-items: center; flex-wrap: wrap;
}
.ds-footer__beian img { height: 14px; vertical-align: middle; }

/* 深色模式切换按钮（header 右侧，与语言切换并列） */
.ds-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--ds-radius-sm);
  background: transparent; border: 1px solid var(--ds-border);
  cursor: pointer; color: var(--ds-text-muted); font-size: var(--ds-text-base);
}
.ds-theme-toggle:hover { background: var(--ds-bg-subtle); }

/* ============ 文档/教程站布局（对应 nb.iohow.com 这类侧栏阅读型站点）============
 * 与单功能工具页（.ds-container 单栏）不同，文档站是双栏：侧边章节目录 + 阅读区。
 * 移动端侧栏收起为抽屉，用 ☰ 触发。内容排版本身不强制套用 tokens 字号，
 * 只统一外壳（header/footer/侧栏底色/链接色）。 */
.ds-docs-layout { display: flex; min-height: 100vh; }
.ds-docs-sidebar {
  width: 280px; flex-shrink: 0;
  background: var(--ds-bg-subtle);
  border-right: 1px solid var(--ds-border);
  overflow-y: auto;
  padding: var(--ds-space-4);
}
.ds-docs-sidebar__group { margin-bottom: var(--ds-space-4); }
.ds-docs-sidebar__group-title {
  font-size: var(--ds-text-xs); font-weight: 700; text-transform: uppercase;
  color: var(--ds-text-muted); letter-spacing: 0.04em; margin-bottom: var(--ds-space-2);
}
.ds-docs-sidebar__link {
  display: block; padding: var(--ds-space-2) var(--ds-space-3);
  font-size: var(--ds-text-sm); color: var(--ds-text); border-radius: var(--ds-radius-sm);
}
.ds-docs-sidebar__link:hover { background: var(--ds-bg-elevated); text-decoration: none; }
.ds-docs-sidebar__link--active { background: var(--ds-brand-600); color: var(--ds-text-inverse); }
.ds-docs-content {
  flex: 1; max-width: 760px; margin-inline: auto;
  padding: var(--ds-space-10) var(--ds-space-6);
  line-height: var(--ds-leading-normal);
}
.ds-docs-toc-toggle { display: none; } /* 移动端显示，桌面端隐藏，具体断点见响应式区块 */
@media (max-width: 900px) {
  .ds-docs-sidebar { position: fixed; inset: 0 20% 0 0; z-index: 30; transform: translateX(-100%); transition: transform var(--ds-transition-base); }
  .ds-docs-sidebar--open { transform: translateX(0); box-shadow: var(--ds-shadow-lg); }
  .ds-docs-toc-toggle { display: inline-flex; }
}

/* ============ 按钮 Button ============ */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-3) var(--ds-space-5);
  font-size: var(--ds-text-sm);
  font-weight: 600;
  border-radius: var(--ds-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--ds-transition-fast), border-color var(--ds-transition-fast), transform var(--ds-transition-fast);
  user-select: none;
}
.ds-btn:active { transform: scale(0.98); }
.ds-btn--primary { background: var(--ds-brand-600); color: var(--ds-text-inverse); }
.ds-btn--primary:hover { background: var(--ds-brand-700); text-decoration: none; }
.ds-btn--secondary { background: var(--ds-bg-subtle); color: var(--ds-text); border-color: var(--ds-border); }
.ds-btn--secondary:hover { background: var(--ds-border); text-decoration: none; }
.ds-btn--ghost { background: transparent; color: var(--ds-text-muted); }
.ds-btn--ghost:hover { background: var(--ds-bg-subtle); text-decoration: none; }
.ds-btn--icon { padding: var(--ds-space-2); border-radius: var(--ds-radius-sm); }
.ds-btn--sm { padding: var(--ds-space-2) var(--ds-space-3); font-size: var(--ds-text-xs); }
.ds-btn--block { width: 100%; }
.ds-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ 卡片 Card ============ */
.ds-card {
  background: var(--ds-bg-elevated);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-sm);
  padding: var(--ds-space-6);
}
.ds-card--hover { transition: box-shadow var(--ds-transition-base), transform var(--ds-transition-base); }
.ds-card--hover:hover { box-shadow: var(--ds-shadow-md); transform: translateY(-2px); }

/* 结果展示卡片：IP / 哈希值等技术数据展示（对应 ip.iohow.com 的 IPv4/IPv6 展示块） */
.ds-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-3);
  padding: var(--ds-space-4) var(--ds-space-5);
  background: var(--ds-bg-subtle);
  border-radius: var(--ds-radius-md);
  margin-bottom: var(--ds-space-3);
}
.ds-result__label { font-size: var(--ds-text-xs); color: var(--ds-text-muted); margin-bottom: var(--ds-space-1); }
.ds-result__value { font-family: var(--ds-font-mono); font-size: var(--ds-text-lg); font-weight: 600; word-break: break-all; }
.ds-result__actions { display: flex; gap: var(--ds-space-2); flex-shrink: 0; }

/* ============ 工具箱首页：分类 + 工具卡片网格 ============ */
.ds-tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--ds-space-5);
}
.ds-tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-2);
  padding: var(--ds-space-5);
  background: var(--ds-bg-elevated);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  transition: box-shadow var(--ds-transition-base), transform var(--ds-transition-base), border-color var(--ds-transition-base);
}
.ds-tool-card:hover {
  text-decoration: none;
  box-shadow: var(--ds-shadow-md);
  transform: translateY(-3px);
  border-color: var(--ds-border-strong);
}
.ds-tool-card__icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-text-lg);
  /* 图标背景色用 --ds-cat-* 变量，按分类区分，见下方 category-pill 用法一致 */
}
.ds-tool-card__title { font-weight: 700; color: var(--ds-text); font-size: var(--ds-text-base); }
.ds-tool-card__desc { font-size: var(--ds-text-sm); color: var(--ds-text-muted); flex-grow: 1; }

/* 分类色工具类：icon 底色 + 文字色，用 data-cat 属性驱动，agent 生成卡片时按分类打标 */
[data-cat="network"]   .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-network) 15%, transparent);   color: var(--ds-cat-network); }
[data-cat="design"]    .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-design) 15%, transparent);    color: var(--ds-cat-design); }
[data-cat="security"]  .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-security) 15%, transparent);  color: var(--ds-cat-security); }
[data-cat="generator"] .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-generator) 15%, transparent); color: var(--ds-cat-generator); }
[data-cat="convert"]   .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-convert) 15%, transparent);   color: var(--ds-cat-convert); }
[data-cat="lookup"]    .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-lookup) 15%, transparent);    color: var(--ds-cat-lookup); }
[data-cat="docs"]      .ds-tool-card__icon { background: color-mix(in srgb, var(--ds-cat-docs) 15%, transparent);      color: var(--ds-cat-docs); }

/* 分类筛选 Pill（导航页顶部分类切换） */
.ds-pill-group { display: flex; gap: var(--ds-space-2); flex-wrap: wrap; }
.ds-pill {
  padding: var(--ds-space-2) var(--ds-space-4);
  border-radius: var(--ds-radius-full);
  border: 1px solid var(--ds-border);
  background: var(--ds-bg-elevated);
  font-size: var(--ds-text-sm);
  color: var(--ds-text-muted);
  cursor: pointer;
}
.ds-pill:hover { border-color: var(--ds-border-strong); }
.ds-pill[aria-pressed="true"] { background: var(--ds-brand-600); border-color: var(--ds-brand-600); color: var(--ds-text-inverse); }

/* ============ 徽标 Badge（New / Beta / Popular） ============ */
.ds-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--ds-space-2);
  font-size: var(--ds-text-xs);
  font-weight: 700;
  border-radius: var(--ds-radius-full);
  line-height: 1.4;
}
.ds-badge--new     { background: color-mix(in srgb, var(--ds-success-500) 15%, transparent); color: var(--ds-success-600); }
.ds-badge--beta    { background: color-mix(in srgb, var(--ds-info-500) 15%, transparent);    color: var(--ds-info-500); }
.ds-badge--popular { background: color-mix(in srgb, var(--ds-warning-500) 15%, transparent); color: var(--ds-warning-600); }

/* ============ 搜索框（导航页工具搜索） ============ */
.ds-search {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-3) var(--ds-space-4);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-bg-elevated);
}
.ds-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--ds-text-base);
  color: var(--ds-text);
}

/* ============ 表单控件 Form ============ */
.ds-field { margin-bottom: var(--ds-space-5); }
.ds-field__label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: var(--ds-text-sm); font-weight: 600; margin-bottom: var(--ds-space-2);
}
.ds-field__value { font-family: var(--ds-font-mono); color: var(--ds-brand-600); }

/* 滑块（密码长度等），原生 range 定制 */
.ds-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--ds-radius-full);
  background: var(--ds-bg-subtle);
  outline: none;
}
.ds-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ds-brand-600);
  cursor: pointer;
  border: 3px solid var(--ds-bg-elevated);
  box-shadow: var(--ds-shadow-sm);
}
.ds-slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ds-brand-600); cursor: pointer; border: 3px solid var(--ds-bg-elevated);
}

/* 复选框 / 开关 */
.ds-checkbox { display: inline-flex; align-items: center; gap: var(--ds-space-2); font-size: var(--ds-text-sm); cursor: pointer; }
.ds-checkbox input { width: 16px; height: 16px; accent-color: var(--ds-brand-600); cursor: pointer; }

.ds-switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.ds-switch input { opacity: 0; width: 0; height: 0; }
.ds-switch__track {
  position: absolute; inset: 0; background: var(--ds-border-strong);
  border-radius: var(--ds-radius-full); transition: background var(--ds-transition-fast); cursor: pointer;
}
.ds-switch__track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
  background: var(--ds-bg-elevated); border-radius: 50%; transition: transform var(--ds-transition-fast);
}
.ds-switch input:checked + .ds-switch__track { background: var(--ds-brand-600); }
.ds-switch input:checked + .ds-switch__track::before { transform: translateX(18px); }

/* 强度计（密码强度 / 安全评分类工具通用） */
.ds-strength { display: flex; gap: 4px; margin-top: var(--ds-space-2); }
.ds-strength__bar { flex: 1; height: 4px; border-radius: var(--ds-radius-full); background: var(--ds-bg-subtle); }
.ds-strength__bar--weak   { background: var(--ds-strength-weak); }
.ds-strength__bar--fair   { background: var(--ds-strength-fair); }
.ds-strength__bar--good   { background: var(--ds-strength-good); }
.ds-strength__bar--strong { background: var(--ds-strength-strong); }

/* ============ 提示 Alert / 隐私声明条 ============ */
.ds-alert {
  display: flex; gap: var(--ds-space-2); align-items: flex-start;
  padding: var(--ds-space-3) var(--ds-space-4);
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-text-sm);
  background: var(--ds-bg-subtle);
  color: var(--ds-text-muted);
  border: 1px solid var(--ds-border);
}
.ds-alert--info    { border-color: color-mix(in srgb, var(--ds-info-500) 30%, var(--ds-border)); }
.ds-alert--success { border-color: color-mix(in srgb, var(--ds-success-500) 30%, var(--ds-border)); }

/* ============ 语言切换器 ============ */
.ds-lang-switch { position: relative; display: inline-block; }
.ds-lang-switch__menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--ds-bg-elevated); border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md); box-shadow: var(--ds-shadow-md);
  min-width: 140px; padding: var(--ds-space-2); display: none; z-index: 20;
}
.ds-lang-switch:hover .ds-lang-switch__menu,
.ds-lang-switch__menu:focus-within { display: block; }
.ds-lang-switch__item {
  display: block; padding: var(--ds-space-2) var(--ds-space-3);
  border-radius: var(--ds-radius-sm); font-size: var(--ds-text-sm); color: var(--ds-text);
}
.ds-lang-switch__item:hover { background: var(--ds-bg-subtle); text-decoration: none; }

/* ============ 广告位（固定尺寸容器，避免 CLS 抖动） ============ */
.ds-ad-slot {
  display: flex; align-items: center; justify-content: center;
  min-height: 90px;
  border: 1px dashed var(--ds-border-strong);
  border-radius: var(--ds-radius-md);
  color: var(--ds-text-muted);
  font-size: var(--ds-text-xs);
  background: var(--ds-bg-subtle);
  margin-block: var(--ds-space-4);
}

/* ============ 面包屑（工具书/教程页用） ============ */
.ds-breadcrumb { font-size: var(--ds-text-sm); color: var(--ds-text-muted); margin-bottom: var(--ds-space-4); }
.ds-breadcrumb a { color: var(--ds-text-muted); }
.ds-breadcrumb__sep { margin-inline: var(--ds-space-2); }

/* 文章卡片（docs 列表用） */
.ds-article-card {
  display: block; padding: var(--ds-space-5);
  border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md);
  margin-bottom: var(--ds-space-3);
}
.ds-article-card:hover { text-decoration: none; border-color: var(--ds-brand-400); }
.ds-article-card__title { font-weight: 600; color: var(--ds-text); margin-bottom: var(--ds-space-1); }
.ds-article-card__desc { font-size: var(--ds-text-sm); color: var(--ds-text-muted); }

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  .ds-header { padding: var(--ds-space-3) var(--ds-space-4); }
  .ds-text-3xl { font-size: var(--ds-text-2xl) !important; }
  .ds-tool-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
