/* PDF 小工具的全部样式。颜色都走自定义属性，浅色 / 深色跟随系统。 */

:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --panel: #ffffff;
  --text: #1c1e21;
  --muted: #5f656c;
  --line: #d7d9dc;
  --line-strong: #aeb2b7;
  --accent: #1a5fb4;
  --accent-hover: #164f96;
  --accent-text: #ffffff;
  --accent-soft: #e3edf9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #1b6e30;
  --ok-soft: #e4f3e7;
  --warn: #6a4a00;
  --warn-soft: #fff3cf;
  --stage: #c6c8cb;
  --code-bg: #eeeeec;
  /* 页面图片永远是白纸，所以画在它上面的框用固定的颜色，不跟主题变 */
  --paper-field: #1a5fb4;
  --paper-prop: #b85300;
  --paper-exist: #6d6d6d;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --header-h: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1b1d;
    --panel: #232527;
    --text: #e3e4e6;
    --muted: #9da2a8;
    --line: #393c40;
    --line-strong: #5a5e64;
    --accent: #7db3f7;
    --accent-hover: #9cc5f9;
    --accent-text: #0b1a2c;
    --accent-soft: #1f3550;
    --danger: #f2877f;
    --danger-soft: #45211e;
    --ok: #7fd093;
    --ok-soft: #1c3a24;
    --warn: #f0cf7a;
    --warn-soft: #40340f;
    --stage: #47494d;
    --code-bg: #2c2e31;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 6px;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 8px;
}

p {
  margin: 0 0 8px;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

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

/* 看不见但键盘和读屏软件能用 */
.vh {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0 !important;
}

/* ---------------- 控件 ---------------- */

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
}

.btn:hover,
button:hover {
  border-color: var(--accent);
}

button:disabled,
fieldset:disabled .btn {
  opacity: 0.5;
  cursor: default;
  border-color: var(--line-strong);
}

fieldset:disabled .btn,
fieldset:disabled .seg label {
  pointer-events: none;
}

fieldset:disabled .seg {
  opacity: 0.6;
}

button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:hover:not(:disabled),
.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
}

button.danger {
  color: var(--danger);
}

button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 28px;
  padding: 3px 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.6;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
  margin: 0;
}

label {
  display: block;
}

.field {
  margin-bottom: 10px;
}

.field > label,
.field > .label {
  font-weight: 600;
  margin-bottom: 3px;
}

.field .hint,
.hint {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* 只填几个字符的输入框，不用占满一行 */
input.short {
  max-width: 220px;
}

/* 两个控件并排，放不下就上下排 */
.pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0 12px;
}

.check,
.field > label.check {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-weight: 400;
  margin-bottom: 0;
}

.check input {
  margin-top: 3px;
  flex: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

/* 竖着排的单选组：选项的字多、排不成一排的时候用 */
.choices {
  margin-bottom: 10px;
}

.choices legend {
  padding: 0;
  font-weight: 600;
  margin-bottom: 3px;
}

.choices .check {
  padding: 2px 0;
}

.choices + .hint {
  margin: -4px 0 10px;
}

/* 几个选项排成一排的单选组 */
.seg {
  margin-bottom: 10px;
}

.seg legend {
  padding: 0;
  font-weight: 600;
  margin-bottom: 3px;
}

.seg .opts {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.seg label {
  position: relative;
  margin: 0;
}

.seg input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.seg span {
  display: block;
  padding: 4px 12px;
  border-right: 1px solid var(--line);
}

.seg label:last-child span {
  border-right: 0;
}

.seg input:checked + span {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.seg input:checked:focus-visible + span {
  outline-color: var(--accent-text);
}

/* ---------------- 状态行、提示 ---------------- */

.status {
  margin: 8px 0;
  padding: 6px 9px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.status:empty {
  display: none;
}

/* 说明后面跟着的链接（比如“去设置”）不要从中间断开 */
.status a {
  white-space: nowrap;
}

.status[data-kind="error"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.status[data-kind="ok"] {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

.status[data-kind="warn"],
.notice {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}

.notice {
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

#toasts {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  padding: 7px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

.toast[data-kind="error"] {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------------- 页头 ---------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  gap: 14px;
  min-height: var(--header-h);
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
}

.tabs a {
  display: flex;
  align-items: center;
  padding: 0 11px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  border-top: 2px solid transparent;
}

.tabs a:hover {
  color: var(--text);
}

.tabs a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.tabs a:focus-visible {
  outline-offset: -2px;
}

.top .side {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.top .side .user {
  color: var(--muted);
}

/* ---------------- 普通的单栏页面（摘要、设置、登录） ---------------- */

.col {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 14px;
}

.drop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
}

.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop input[type="file"]:focus-visible + .btn {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.drop .file-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* 登录页 */
.login {
  max-width: 320px;
  margin: 12vh auto 0;
  padding: 0 16px;
}

.login h1 {
  margin-bottom: 14px;
}

.login button {
  width: 100%;
  min-height: 32px;
}

/* ---------------- 摘要与问答 ---------------- */

#sum-form {
  margin-bottom: 14px;
}

.progress {
  margin: 10px 0;
}

.progress progress {
  display: block;
  width: 100%;
  height: 8px;
  accent-color: var(--accent);
}

.progress .msg {
  margin-top: 4px;
  color: var(--muted);
}

.entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.entry > h2 {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.entry .meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.entry .actions {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ---------------- 翻译 ---------------- */

#tr-form {
  margin-bottom: 14px;
}

#tr-job .file-title {
  overflow-wrap: anywhere;
}

#tr-job .file-title:focus-visible {
  outline-offset: 3px;
}

/* 进度条下面一行：左边是现在做到哪一步，右边是百分比 */
.progress .msg.split {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#tr-pct {
  flex: none;
  font-variant-numeric: tabular-nums;
}

#tr-actions {
  margin-top: 10px;
}

#tr-job > .hint {
  margin-top: 8px;
}

/* 模型回答（服务器已经把 Markdown 转成安全的 HTML） */
.md {
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 14px 0 6px;
  line-height: 1.35;
}

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

.md h2 {
  font-size: 16px;
}

.md h3,
.md h4 {
  font-size: 14px;
}

.md > :first-child {
  margin-top: 0;
}

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

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

.md table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 8px 0;
}

.md th,
.md td {
  border: 1px solid var(--line-strong);
  padding: 3px 9px;
  text-align: left;
}

.md th {
  background: var(--code-bg);
}

.md code,
.md pre {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--code-bg);
  border-radius: 3px;
}

.md code {
  padding: 1px 4px;
}

.md pre {
  padding: 8px 10px;
  overflow-x: auto;
}

.md pre code {
  padding: 0;
  background: none;
}

.md blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
}

.md img {
  max-width: 100%;
}

/* ---------------- 设置 ---------------- */

details.adv {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
}

details.adv > summary {
  cursor: pointer;
  font-weight: 600;
}

details.adv[open] > summary {
  margin-bottom: 8px;
}

details.adv .field:last-child {
  margin-bottom: 4px;
}

/* ---------------- 新建表单域 ---------------- */

.tab-forms {
  height: calc(100vh - var(--header-h) - 1px);
  height: calc(100dvh - var(--header-h) - 1px);
}

.narrow-note {
  display: none;
}

#fm-work {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.fm-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.fm-toolbar .group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.fm-toolbar button {
  padding: 2px 7px;
}

.fm-toolbar .group > .cap {
  color: var(--muted);
  margin-right: 3px;
  white-space: nowrap;
}

.fm-toolbar .doc {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.fm-toolbar .zoom-val {
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fm-toolbar .push {
  margin-left: auto;
}

.fm-statusbar {
  padding: 0 10px;
  background: var(--panel);
}

.fm-statusbar .status {
  margin: 6px 0;
}

.fm-statusbar .confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.fm-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 270px;
}

.fm-pages {
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.fm-pages .docinfo {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.fm-pages .docinfo b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fm-pages ol {
  list-style: none;
  margin: 0;
  padding: 4px;
}

.fm-pages li button {
  display: grid;
  grid-template-columns: 1fr auto;
  width: 100%;
  min-height: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  background: none;
  text-align: left;
  justify-items: start;
  gap: 0 6px;
  white-space: normal;
}

.fm-pages li button:hover {
  background: var(--accent-soft);
}

.fm-pages li button[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}

.fm-pages .n-new {
  font-variant-numeric: tabular-nums;
}

.fm-pages .n-new[data-n="0"] {
  color: var(--muted);
  font-weight: 400;
}

.fm-pages .extra {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.fm-pages .extra:empty {
  display: none;
}

.fm-stage {
  position: relative;
  overflow: auto;
  scrollbar-gutter: stable;
  padding: 16px;
  background: var(--stage);
  user-select: none;
  -webkit-user-select: none;
}

.fm-stage:focus-visible {
  outline-offset: -2px;
}

/* 有文件拖到页面上方时 */
.fm-stage.over {
  outline: 3px dashed var(--accent);
  outline-offset: -8px;
}

.fm-wrap {
  position: relative;
  margin: 0 auto;
  background: #ffffff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.fm-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}

.fm-wrap[data-ready="0"] img {
  visibility: hidden;
}

.fm-wrap .loading {
  position: absolute;
  left: 0;
  right: 0;
  top: 40px;
  text-align: center;
  color: #666;
  display: none;
}

.fm-wrap[data-ready="0"] .loading {
  display: block;
}

.fm-overlay {
  position: absolute;
  inset: 0;
  --zoom: 1;
  touch-action: none;
}

.fm-overlay.drawing {
  cursor: crosshair;
}

/* 框的位置和大小存的是 PDF 的点，乘上 --zoom 就是屏幕像素。改缩放只要改一个变量 */
.box {
  position: absolute;
  left: calc(var(--x) * var(--zoom) * 1px);
  top: calc(var(--y) * var(--zoom) * 1px);
  width: calc(var(--w) * var(--zoom) * 1px);
  height: calc(var(--h) * var(--zoom) * 1px);
}

.fld {
  border: 1px solid var(--paper-field);
  background: rgba(26, 95, 180, 0.13);
  cursor: move;
}

.fld .nm {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 0 2px;
  font-size: clamp(9px, calc(8px * var(--zoom)), 13px);
  line-height: 1.25;
  color: #0e3d78;
  white-space: nowrap;
  pointer-events: none;
}

.fld.t-checkbox .nm {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.fld.sel {
  z-index: 3;
  border-width: 2px;
  background: rgba(26, 95, 180, 0.24);
}

.exist {
  border: 1px solid var(--paper-exist);
  background: rgba(110, 110, 110, 0.28);
  cursor: not-allowed;
}

.prop {
  border: 1.5px dashed var(--paper-prop);
  background: rgba(184, 83, 0, 0.1);
  cursor: pointer;
  z-index: 1;
}

.prop:hover {
  background: rgba(184, 83, 0, 0.28);
}

.band,
.ghost {
  pointer-events: none;
  z-index: 4;
  border: 1px solid var(--paper-field);
  background: rgba(26, 95, 180, 0.18);
}

.ghost {
  border-style: dotted;
  background: rgba(26, 95, 180, 0.08);
}

.drawing .fld,
.drawing .prop,
.drawing .exist {
  pointer-events: none;
}

/* 画新域的时候，选中的那个域的手柄照样能拖，方便画完马上调大小 */
.drawing .fld.sel .hd {
  pointer-events: auto;
}

/* 八个手柄都放在框的外面，框再小，里面也留着地方可以拖动整个框 */
.hd {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #ffffff;
  border: 1px solid var(--paper-field);
}

.h-nw { left: -9px; top: -9px; cursor: nwse-resize; }
.h-n { left: calc(50% - 4px); top: -9px; cursor: ns-resize; }
.h-ne { right: -9px; top: -9px; cursor: nesw-resize; }
.h-e { right: -9px; top: calc(50% - 4px); cursor: ew-resize; }
.h-se { right: -9px; bottom: -9px; cursor: nwse-resize; }
.h-s { left: calc(50% - 4px); bottom: -9px; cursor: ns-resize; }
.h-sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.h-w { left: -9px; top: calc(50% - 4px); cursor: ew-resize; }

.fm-props {
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 10px;
}

.fm-props .xywh {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
}

.fm-props .xywh label {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  font-weight: 400;
}

.fm-props .xywh input {
  font-variant-numeric: tabular-nums;
}

.fm-props .hint.problem {
  color: var(--danger);
}

.fm-props dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  font-size: 12px;
}

.fm-props dt {
  font-family: var(--mono);
  white-space: nowrap;
}

.fm-props dd {
  margin: 0;
  color: var(--muted);
}

kbd {
  font-family: var(--mono);
  font-size: 11px;
}

/* ---------------- 窄屏 ---------------- */

@media (max-width: 860px) {
  .narrow-note {
    display: block;
    margin: 12px 16px 0;
  }

  #fm-work,
  #fm-empty {
    display: none;
  }

  .tab-forms {
    height: auto;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  /* 手机上输入框小于 16px 的话，点进去页面会自动放大 */
  input[type="text"],
  input[type="password"],
  input[type="url"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px;
    min-height: 36px;
  }

  .btn,
  button {
    min-height: 36px;
  }

  button.link {
    min-height: 0;
  }

  .top {
    flex-wrap: wrap;
    gap: 0 10px;
    padding: 0 10px;
  }

  .brand {
    min-height: 36px;
  }

  .top .side {
    min-height: 36px;
  }

  .tabs {
    order: 3;
    width: 100%;
    min-height: 36px;
  }

  .col {
    padding: 12px 12px 40px;
  }

  .seg span {
    padding: 7px 12px;
  }

  .choices .check {
    padding: 6px 0;
  }
}
