/* ============================================================
 * AI 打印管理器 · 在线对接文档
 * 独立静态样式（不依赖主应用构建产物）
 * ============================================================ */

/* Latin subset Web Font，与主应用共用同一份 woff2，保证数字/字母字形一致 */
@font-face {
  font-family: 'AIPrint Sans';
  src: url('/fonts/aiprint-sans.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF,
    U+FFFD;
}

:root {
  --brand: #1677ff;
  --brand-soft: rgba(22, 119, 255, 0.08);
  --brand-line: rgba(22, 119, 255, 0.28);

  --bg: #fff;
  --bg-panel: #fbfcfe;
  --bg-soft: #f6f8fb;
  --bg-code: #f7f9fc;

  --text: #232323;
  --text-strong: #101828;
  --text-muted: #6b7785;
  --text-faint: #98a2b3;

  --border: #e7ecf2;
  --border-soft: #f0f3f7;

  --tk-kw: #a626a4;
  --tk-str: #0a7c47;
  --tk-num: #b7541a;
  --tk-cmt: #98a2b3;
  --tk-key: #1a56b0;
  --tk-ann: #b7541a;

  --topbar-h: 56px;
  --sidebar-w: 288px;
  --content-max: 900px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --font-sans: 'AIPrint Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei',
    'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono',
    'Liberation Mono', 'Courier New', monospace;
}

[data-theme='dark'] {
  --brand: #55a0ff;
  --brand-soft: rgba(85, 160, 255, 0.14);
  --brand-line: rgba(85, 160, 255, 0.36);

  --bg: #15181e;
  --bg-panel: #1a1e25;
  --bg-soft: #1f242c;
  --bg-code: #1b2028;

  --text: #d6dce6;
  --text-strong: #f2f5f9;
  --text-muted: #8e9aab;
  --text-faint: #6b7686;

  --border: #2a303a;
  --border-soft: #23282f;

  --tk-kw: #d78cf0;
  --tk-str: #7ddba6;
  --tk-num: #f0a97c;
  --tk-cmt: #6b7686;
  --tk-key: #7fb4ff;
  --tk-ann: #f0a97c;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: none;
}

input {
  font: inherit;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: rgba(128, 140, 160, 0.28);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(128, 140, 160, 0.48);
}

/* ── 顶栏 ── */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text-strong);
  white-space: nowrap;
}

.topbar__logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 62%, #7a5cff));
  border-radius: 7px;
}

.topbar__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.topbar__sub {
  padding: 2px 7px;
  font-size: 11px;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid var(--brand-line);
  border-radius: 5px;
}

.topbar__spacer {
  flex: 1;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  border-radius: 6px;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}

.icon-btn:hover {
  color: var(--brand);
  background: var(--brand-soft);
}

/* 主题图标：浅色下展示“切换到深色”的月亮，反之展示太阳 */
.theme-icon--sun {
  display: none;
}

[data-theme='dark'] .theme-icon--sun {
  display: block;
}

[data-theme='dark'] .theme-icon--moon {
  display: none;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.16s var(--ease);
}

.ghost-btn:hover {
  color: var(--brand);
  border-color: var(--brand-line);
  background: var(--brand-soft);
}

.topbar__menu {
  display: none;
}

/* ── 主体布局 ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  padding-top: var(--topbar-h);
}

/* ── 侧边栏 ── */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 10px 40px 18px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.sidebar__search {
  position: relative;
  margin-bottom: 16px;
}

.sidebar__search svg {
  position: absolute;
  top: 50%;
  left: 9px;
  color: var(--text-faint);
  transform: translateY(-50%);
  pointer-events: none;
}

.sidebar__search input {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 30px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.sidebar__search input::placeholder {
  color: var(--text-faint);
}

.sidebar__search input:focus {
  border-color: var(--brand-line);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.sidebar__clear {
  position: absolute;
  top: 50%;
  right: 4px;
  display: none;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--text-faint);
  border-radius: 5px;
  transform: translateY(-50%);
}

.sidebar__clear:hover {
  color: var(--text);
  background: var(--bg-soft);
}

.sidebar__search.has-value .sidebar__clear {
  display: grid;
}

.sidebar__label {
  padding: 0 8px;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

.doc-switch {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-soft);
}

.doc-switch a {
  padding: 7px 10px;
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}

.doc-switch a small {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
}

.doc-switch a:hover {
  background: var(--bg-soft);
}

.doc-switch a.is-active {
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
}

.doc-switch a.is-active small {
  color: color-mix(in srgb, var(--brand) 72%, var(--text-muted));
}

/* 目录树 */
.toc {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc a {
  display: block;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 5px 5px 0;
  transition: color 0.14s var(--ease), background 0.14s var(--ease),
    border-color 0.14s var(--ease);
}

.toc a:hover {
  color: var(--text-strong);
  background: var(--bg-soft);
}

.toc a.is-active {
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-left-color: var(--brand);
}

.toc a[data-level='2'] {
  padding-left: 10px;
  font-weight: 500;
  color: var(--text);
}

.toc a[data-level='3'] {
  padding-left: 22px;
}

.toc a[data-level='4'] {
  padding-left: 34px;
  font-size: 12.5px;
}

.toc a[data-level='5'],
.toc a[data-level='6'] {
  padding-left: 46px;
  font-size: 12.5px;
}

.toc a.is-hidden {
  display: none;
}

.toc__empty {
  padding: 10px;
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ── 正文 ── */
.main {
  min-width: 0;
  padding: 30px 40px 96px;
}

.doc {
  max-width: var(--content-max);
  margin: 0 auto;
}

.doc__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 26px;
  font-size: 12.5px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border-soft);
}

.doc__meta .dot {
  color: var(--border);
}

.doc__status {
  padding: 40px 0;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.doc__status--error {
  color: #d92d20;
}

.doc__status code {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* ── Markdown 排版 ── */
.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  scroll-margin-top: calc(var(--topbar-h) + 16px);
  color: var(--text-strong);
  line-height: 1.4;
}

.md h1 {
  margin: 0 0 18px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.md h2 {
  margin: 44px 0 16px;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.2px;
}

.md h3 {
  margin: 32px 0 12px;
  font-size: 18px;
  font-weight: 600;
}

.md h4 {
  margin: 26px 0 10px;
  font-size: 15.5px;
  font-weight: 600;
}

.md h5,
.md h6 {
  margin: 22px 0 8px;
  font-size: 14.5px;
  font-weight: 600;
}

/* 以行内代码命名的接口小标题（如 `POST /api/print-tasks`）单独强化 */
.md h4 > code {
  padding: 3px 9px;
  font-size: 14.5px;
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand-line);
}

.md .md-anchor {
  padding-left: 8px;
  font-weight: 400;
  color: var(--text-faint);
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.16s var(--ease);
}

.md h1:hover .md-anchor,
.md h2:hover .md-anchor,
.md h3:hover .md-anchor,
.md h4:hover .md-anchor,
.md h5:hover .md-anchor,
.md h6:hover .md-anchor {
  opacity: 1;
}

.md .md-anchor:hover {
  color: var(--brand);
}

.md p {
  margin: 0 0 14px;
}

.md a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px solid var(--brand-line);
  transition: border-color 0.16s var(--ease);
}

.md a:hover {
  border-bottom-color: var(--brand);
}

.md strong {
  font-weight: 600;
  color: var(--text-strong);
}

.md ul,
.md ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.md li {
  margin-bottom: 5px;
}

.md li > ul,
.md li > ol {
  margin: 5px 0 0;
}

.md li::marker {
  color: var(--text-faint);
}

.md hr {
  height: 1px;
  margin: 34px 0;
  background: var(--border);
  border: none;
}

.md blockquote {
  padding: 12px 16px;
  margin: 0 0 16px;
  background: var(--bg-soft);
  border-left: 3px solid var(--brand-line);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.md blockquote > :last-child {
  margin-bottom: 0;
}

.md img {
  max-width: 100%;
  border-radius: var(--radius);
  outline: 1px solid var(--border-soft);
  box-shadow: 0 4px 18px rgba(16, 24, 40, 0.14);
}

.md :not(pre) > code {
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.875em;
  color: color-mix(in srgb, var(--text-strong) 82%, var(--brand));
  word-break: break-word;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
}

/* 表格 */
.md .md-table-wrap {
  margin: 0 0 18px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.md table {
  width: 100%;
  font-size: 13.5px;
  border-collapse: collapse;
}

.md th,
.md td {
  padding: 9px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-soft);
}

.md th {
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}

.md tbody tr:last-child td {
  border-bottom: none;
}

.md tbody tr:hover {
  background: color-mix(in srgb, var(--bg-soft) 60%, transparent);
}

.md td :not(pre) > code {
  white-space: nowrap;
}

/* 代码块 */
.md .md-code {
  margin: 0 0 18px;
  overflow: hidden;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.md .md-code__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 14px;
  background: color-mix(in srgb, var(--bg-soft) 70%, var(--bg-code));
  border-bottom: 1px solid var(--border-soft);
}

.md .md-code__lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.4px;
}

.md .md-code__copy {
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: 5px;
  transition: color 0.16s var(--ease), background 0.16s var(--ease);
}

.md .md-code__copy:hover {
  color: var(--brand);
  background: var(--brand-soft);
}

.md .md-code__copy.is-done {
  color: #0a7c47;
}

.md pre {
  padding: 14px 16px;
  overflow-x: auto;
}

.md pre code {
  font-family: var(--font-mono);
  font-size: 12.8px;
  line-height: 1.72;
  color: var(--text);
  white-space: pre;
  tab-size: 2;
}

.md .tk-kw {
  color: var(--tk-kw);
}

.md .tk-str {
  color: var(--tk-str);
}

.md .tk-num {
  color: var(--tk-num);
}

.md .tk-cmt {
  font-style: italic;
  color: var(--tk-cmt);
}

.md .tk-key {
  color: var(--tk-key);
}

.md .tk-ann {
  color: var(--tk-ann);
}

/* ── 回到顶部 ── */
.to-top {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--text-muted);
  visibility: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s var(--ease), visibility 0.2s var(--ease), color 0.16s var(--ease);
}

.to-top.is-visible {
  visibility: visible;
  opacity: 1;
}

.to-top:hover {
  color: var(--brand);
  border-color: var(--brand-line);
}

/* ── 移动端 ── */
.scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  z-index: 24;
  display: none;
  background: rgba(16, 24, 40, 0.45);
}

@media (max-width: 1024px) {
  :root {
    --sidebar-w: 260px;
  }

  .main {
    padding: 26px 28px 96px;
  }
}

@media (max-width: 820px) {
  .topbar {
    gap: 10px;
    padding: 0 12px;
  }

  .topbar__menu {
    display: grid;
  }

  .topbar__sub,
  .ghost-btn span {
    display: none;
  }

  .ghost-btn {
    width: 32px;
    padding: 0;
    justify-content: center;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 25;
    width: 84vw;
    max-width: 320px;
    box-shadow: var(--shadow-lg);
    transition: transform 0.24s var(--ease);
    transform: translateX(-100%);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.nav-open .scrim {
    display: block;
  }

  .main {
    padding: 20px 16px 80px;
  }

  .md h1 {
    font-size: 25px;
  }

  .md h2 {
    margin-top: 34px;
    font-size: 20px;
  }

  .md h3 {
    font-size: 17px;
  }
}

/* ── 图片放大预览 ── */
.md img {
  cursor: zoom-in;
}

.image-viewer[hidden] {
  display: none !important;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 3vh 3vw;
}

.image-viewer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 25, 0.82);
  backdrop-filter: blur(5px);
  animation: imageViewerFadeIn 0.16s ease-out;
}

.image-viewer__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: fit-content;
  max-width: 100%;
  height: auto;
  max-height: 94vh;
  overflow: hidden;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  animation: imageViewerPanelIn 0.18s var(--ease);
}

.image-viewer__header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 50px;
  padding: 0 12px 0 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
}

.image-viewer__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-viewer__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 0;
  outline: none;
  box-shadow: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.image-viewer__close:hover {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.24);
}

.image-viewer__scroll {
  display: flex;
  flex: 0 1 auto;
  min-height: 0;
  padding: 16px;
  overflow: hidden;
  background: var(--bg-code);
  overscroll-behavior: contain;
}

.image-viewer__image {
  display: block;
  flex: none;
  max-width: 100%;
  max-height: calc(94vh - 114px);
  width: auto;
  height: auto;
  margin: auto;
  object-fit: contain;
  cursor: default;
  box-shadow: 0 2px 16px rgba(16, 24, 40, 0.12);
}

.image-viewer__footer {
  padding: 7px 12px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  background: var(--bg);
  border-top: 1px solid var(--border-soft);
}

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

@keyframes imageViewerPanelIn {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 640px) {
  .image-viewer {
    padding: 0;
  }

  .image-viewer__panel {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .image-viewer__header {
    padding-left: 12px;
  }

  .image-viewer__scroll {
    padding: 8px;
  }

  .image-viewer__image {
    max-height: calc(100dvh - 98px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .image-viewer__backdrop,
  .image-viewer__panel {
    animation: none;
  }
}

/* ── 打印 ── */
@media print {
  .topbar,
  .sidebar,
  .to-top,
  .scrim,
  .image-viewer,
  .md .md-anchor,
  .md .md-code__copy {
    display: none !important;
  }

  .layout {
    display: block;
    padding-top: 0;
  }

  .main {
    padding: 0;
  }

  .md .md-code,
  .md .md-table-wrap,
  .md blockquote {
    page-break-inside: avoid;
  }
}
