/* ============================================================
   DiagramHub · 现代简约样式
   亮/暗主题通过 :root[data-theme] 切换
   ============================================================ */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f9;
  --bg-sunken: #f1f1f5;
  --text: #16161a;
  --text-2: #5c5c6b;
  --text-3: #6f6f80;
  --border: #e6e6ec;
  --border-2: #d4d4dd;
  --accent: #534ab7;
  --accent-hover: #443c9e;
  --accent-soft: #eeedfe;
  --accent-text: #3c3489;
  --ok: #1d9e75;
  --err: #e24b4a;
  --warn: #ba7517;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 16, 24, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 16, 24, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, Helvetica,
    Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --maxw: 1140px;
  --header-h: 58px;
}

:root[data-theme='dark'] {
  --bg: #17171c;
  --bg-soft: #1e1e24;
  --bg-sunken: #131317;
  --text: #f2f2f5;
  --text-2: #a8a8b6;
  --text-3: #8d8da2;
  --border: #2c2c34;
  --border-2: #3a3a45;
  --accent: #8b84e0;
  --accent-hover: #a49de8;
  --accent-soft: #26224a;
  --accent-text: #cecbf6;
  --ok: #5dcaa5;
  --err: #f09595;
  --warn: #ef9f27;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3 { font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 0.6rem; }
h2 { font-size: 1.35rem; margin: 2.4rem 0 0.8rem; }
h3 { font-size: 1.05rem; margin: 1.6rem 0 0.5rem; }
p { margin: 0 0 1rem; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }

/* ── 顶栏 ───────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15.5px;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark {
  width: 22px; height: 22px;
  flex-shrink: 0;
  display: block;
}
.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.nav a {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
}
.nav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav a[aria-current='page'] { color: var(--text); background: var(--bg-soft); font-weight: 500; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* 语言切换 */
.lang-switch { position: relative; }
.lang-switch > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  user-select: none;
}
.lang-switch > summary::-webkit-details-marker { display: none; }
.lang-switch > summary:hover { border-color: var(--text-3); }
.lang-switch .caret {
  width: 0; height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid var(--text-3);
}
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 168px;
  max-height: 62vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 60;
}
.lang-menu a {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-2);
  text-decoration: none;
}
.lang-menu a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.lang-menu a[aria-current='true'] { color: var(--accent-text); background: var(--accent-soft); font-weight: 500; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}
.icon-btn:hover { border-color: var(--text-3); color: var(--text); }

/* 主题图标：太阳/月亮由 CSS 按 data-theme 切换。
   不用字符 ◐ —— 那个字形依赖系统字体，缺字环境里就是个豆腐块。 */
#themeBtn .ico-moon { display: none; }
:root[data-theme='dark'] #themeBtn .ico-sun { display: none; }
:root[data-theme='dark'] #themeBtn .ico-moon { display: block; }

/* ── 按钮 ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--text-3); text-decoration: none; color: var(--text); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-sm { padding: 5px 11px; font-size: 13px; }

.badge-beta {
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  white-space: nowrap;
}

/* ── 编辑器 ─────────────────────────────────────────────── */
.ed {
  --types-w: 176px;
  --code-w: 320px;
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ed-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.ed-bar .spacer { flex: 1; }
.ed-title { font-size: 14px; font-weight: 500; }
/* 移动端抽屉开关：默认隐藏，≤1024px 才出现 */
.ed-types-toggle { display: none; }
.ed-backdrop { display: none; }
.ed-body {
  flex: 1;
  display: grid;
  grid-template-columns: var(--types-w) 5px minmax(0, 1fr) 5px var(--code-w);
  min-height: 0;
}
.ed-types {
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  overflow-y: auto;
  padding: 8px 7px;
}
/* 抽屉头：桌面端隐藏，≤1024px 抽屉打开时显示 */
.ed-types-head { display: none; }
.ed-types-title { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.ed-types-head .btn { flex-shrink: 0; }
.ed-search {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  margin-bottom: 8px;
}
.ed-group { font-size: 11px; font-weight: 500; color: var(--text-3); padding: 8px 8px 3px; letter-spacing: 0.03em; }
.ed-type {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.ed-type:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.ed-type[aria-current='true'] { background: var(--accent); color: #fff; font-weight: 500; }
.ed-type .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--warn); flex-shrink: 0; margin-left: auto;
}
.ed-type[aria-current='true'] .dot { background: #fff; opacity: 0.75; }

.ed-gutter {
  cursor: col-resize;
  background: transparent;
  position: relative;
}
.ed-gutter:hover { background: var(--accent); opacity: 0.35; }

.ed-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-sunken); }
.ed-panel-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
  background: var(--bg);
  flex-shrink: 0;
}
.ed-panel-bar .spacer { flex: 1; }
.ed-canvas {
  flex: 1;
  overflow: auto;
  padding: 20px;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.ed-canvas > .mm-host {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  min-width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ed-canvas svg { max-width: 100%; height: auto; }

.ed-code {
  border-left: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.ed-code-body { flex: 1; display: flex; min-height: 0; position: relative; }
.ed-lines {
  padding: 12px 6px 12px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  /* 与 .ed-textarea 保持一致，否则行号会错位 */
  line-height: 1.65;
  color: var(--text-3);
  text-align: right;
  white-space: pre;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
}
.ed-lines .is-err {
  color: var(--err);
  font-weight: 700;
  background: color-mix(in srgb, var(--err) 16%, transparent);
  border-radius: 3px;
}
.ed-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 12px 12px 12px 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  /* 行高必须显式写死：报错行跳转靠 fontSize * 1.65 算位移 */
  line-height: 1.65;
  background: transparent;
  color: var(--text);
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: auto;
}
.ed-status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
  flex-shrink: 0;
  background: var(--bg);
}
.ed-status .st { display: inline-flex; align-items: center; gap: 5px; }
.ed-status .st-ok { color: var(--ok); }
.ed-status .st-err { color: var(--err); }
.ed-status .led { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ed-status .spacer { flex: 1; }
.ed-status .ed-local-note {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ed-error {
  display: none;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--err) 10%, var(--bg));
  border-top: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  color: var(--err);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  max-height: 96px;
  overflow: auto;
}
.ed-error[data-show='1'] { display: block; }
/* 能定位到行时，报错提示可以点 */
.ed-error[data-line='1'] { cursor: pointer; }

.ed-notice {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: color-mix(in srgb, var(--warn) 9%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
  color: var(--warn);
  font-size: 12.5px;
  flex-shrink: 0;
}
.ed-notice[data-show='1'] { display: flex; }

.ed-canvas.is-full {
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: 45;
  background: var(--bg-sunken);
}

/* ── 落地页 / 文档 ──────────────────────────────────────── */
.page { padding: 40px 0 64px; }
.page-head { max-width: 44em; }
.page-head h1 { font-size: 1.9rem; }
.page-head .lead { font-size: 1rem; color: var(--text-2); }

.crumbs { font-size: 13px; color: var(--text-3); margin-bottom: 18px; }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--text); }

.code-block {
  position: relative;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 1rem;
}
.code-block pre { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; white-space: pre; }
.code-block .kw { color: var(--accent); font-weight: 500; }
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11.5px;
  padding: 3px 9px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
}
.copy-btn:hover { color: var(--text); border-color: var(--text-3); }

.demo-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  padding: 24px;
  overflow: auto;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.demo-frame svg { max-width: 100%; height: auto; }
.demo-loading { color: var(--text-3); font-size: 13px; }

.cta-band {
  margin-top: 40px;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  text-align: center;
}
.cta-band h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.cta-band p { color: var(--text-2); margin: 0 0 1.2rem; }

.related { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-top: 12px; }
.related a {
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-2);
  text-decoration: none;
}
.related a:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); text-decoration: none; }

.faq details {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.faq details:first-of-type { border-top: 1px solid var(--border); }
.faq summary { cursor: pointer; font-weight: 500; font-size: 14.5px; }
.faq summary:hover { color: var(--accent-text); }
.faq details p { margin: 10px 0 0; color: var(--text-2); font-size: 14px; }

/* ── 语言自动跳转页 ─────────────────────────────────────── */
.redirect-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
}
.redirect-page h1 { font-size: 1.3rem; margin: 0; }
.redirect-page .brand-mark { width: 40px; height: 40px; }
.redirect-page .lang-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 30em; }

/* ── 响应式 ─────────────────────────────────────────────── */
/* ≤1024px：三栏放不下，类型面板改成可滑出的抽屉。
   注意：这里【不能】display:none 掉类型面板 —— 否则移动端用户
   就永远换不了图表类型。之前的版本就是吃了这个亏。 */
@media (max-width: 1024px) {
  .ed { --types-w: 0px; --code-w: 0px; }
  .ed-body { grid-template-columns: minmax(0, 1fr); }
  .ed-gutter { display: none; }

  .ed-types-toggle { display: inline-flex; }
  .ed-types-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 6px 10px; }

  .ed-types {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(82vw, 330px);
    z-index: 60;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    padding-top: 14px;
  }
  .ed-types.is-open { transform: none; }

  .ed-backdrop:not([hidden]) {
    display: block;
    position: fixed; inset: 0; z-index: 55;
    background: rgba(16, 16, 24, 0.45);
    border: none; padding: 0; cursor: default;
  }
  .ed-backdrop[hidden] { display: none; }

  .ed-code {
    position: fixed;
    inset: auto 0 0 0;
    height: 46vh;
    z-index: 44;
    border-left: none;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .ed-canvas { padding-bottom: 47vh; }
}

/* 手机上工具栏放不下：换行显示，而不是横向滚（滚了用户也看不见「分享」） */
@media (max-width: 720px) {
  .nav { display: none; }
  .wrap { padding: 0 16px; }
  .ed-bar { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .ed-title { flex-shrink: 0; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ed-bar .btn { white-space: nowrap; }
  .ed-status { gap: 10px; }
}

/* 屏幕阅读器专用 */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* 系统开启「减弱动效」时：去掉所有过渡/动画，只留结果 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .site-header, .ed-bar, .ed-types, .ed-code, .ed-status { display: none; }
}
