/* ---------- tokens ---------- */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fafafa;
  --panel-3: #f1f2f4;
  --border: #e3e5e8;
  --border-strong: #d2d5d9;
  --text: #17181b;
  --text-2: #5b6067;
  --text-3: #979ba1;
  --accent: #0f766e;
  --accent-hover: #0d625b;
  --accent-soft: #e8f5f2;
  --danger: #c2410c;
  --danger-soft: #fdf1ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --radius-sm: 7px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e1012;
  --panel: #16181b;
  --panel-2: #1b1e21;
  --panel-3: #212428;
  --border: #2a2e33;
  --border-strong: #3a3f45;
  --text: #e8eaec;
  --text-2: #a1a7ae;
  --text-3: #6b7278;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #122e2b;
  --danger: #fb923c;
  --danger-soft: #2a1a12;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0e1012;
    --panel: #16181b;
    --panel-2: #1b1e21;
    --panel-3: #212428;
    --border: #2a2e33;
    --border-strong: #3a3f45;
    --text: #e8eaec;
    --text-2: #a1a7ae;
    --text-3: #6b7278;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-soft: #122e2b;
    --danger: #fb923c;
    --danger-soft: #2a1a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

button {
  cursor: pointer;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- topbar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.logo {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
}

[data-theme="dark"] .logo {
  color: #06201d;
}

.brand-text h1 {
  font-size: 15px;
  line-height: 1.3;
}

.brand-text p {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.3;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-chip {
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-family: var(--mono);
  white-space: nowrap;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--panel-3);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn.ghost:hover:not(:disabled) {
  background: var(--panel-3);
  color: var(--text);
}

.btn.icon {
  width: 34px;
  padding: 0;
  font-size: 15px;
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn.icon:hover:not(:disabled) {
  background: var(--panel-3);
  color: var(--text);
}

.btn.small {
  height: 29px;
  padding: 0 11px;
  font-size: 12.5px;
}

.btn.block {
  width: 100%;
  height: 38px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .btn.primary {
  color: #06201d;
}

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

.btn.danger-ghost {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.btn.danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.link.danger {
  color: var(--text-3);
  text-decoration: none;
  font-size: 12px;
}

.link.danger:hover {
  color: var(--danger);
  text-decoration: underline;
}

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  flex: 0 0 336px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  gap: 14px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

/* ---------- dropzone ---------- */
.dropzone {
  flex: 0 0 auto;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  border-style: solid;
}

.dz-icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 4px;
}

.dropzone:hover .dz-icon,
.dropzone.drag .dz-icon {
  stroke: var(--accent);
}

.dz-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 500;
}

.dz-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
}

.dz-hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--text-3);
}

/* ---------- file list ---------- */
.list-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.list-head b {
  color: var(--text);
  font-weight: 600;
}

.file-list {
  flex: 1 1 auto;
  overflow-y: auto;
  list-style: none;
  margin: 0 -6px;
  padding: 0 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.file-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.file-item:hover {
  background: var(--panel-2);
}

.file-item.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-sub {
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-3);
}

.file-del {
  grid-row: 1 / span 2;
  align-self: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.file-item:hover .file-del,
.file-item:focus-within .file-del {
  opacity: 1;
}

.file-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
}

.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.status-pill.is-pending {
  color: var(--text-3);
}

.status-pill.is-parsing {
  color: var(--accent);
}

.status-pill.is-parsing::before {
  animation: pulse 1.1s ease-in-out infinite;
}

.status-pill.is-done {
  color: var(--accent);
}

.status-pill.is-error {
  color: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

.sidebar-foot {
  flex: 0 0 auto;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}

.sidebar-foot {
  padding-top: 12px;
}

.foot-hint {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
}

/* ---------- content ---------- */
.content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 26px 60px;
}

.empty-state {
  height: 100%;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-3);
  gap: 2px;
}

.empty-state svg {
  width: 42px;
  height: 42px;
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 12px;
}

.empty-state h2 {
  font-size: 15px;
  color: var(--text-2);
  font-weight: 500;
}

.empty-state p {
  margin: 4px 0 0;
  font-size: 13px;
  max-width: 340px;
  line-height: 1.65;
}

.result {
  max-width: 980px;
  margin: 0 auto;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.result-title {
  min-width: 0;
}

.result-title h2 {
  font-size: 19px;
  line-height: 1.4;
  word-break: break-word;
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-3);
  flex-wrap: wrap;
}

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

.result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------- banner ---------- */
.banner {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.6;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-2);
}

.banner.is-error {
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.banner.is-info {
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
  background: var(--accent-soft);
  color: var(--text-2);
}

/* ---------- blocks ---------- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.block-head h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
}

.mark {
  width: 3px;
  height: 13px;
  border-radius: 2px;
  display: inline-block;
}

.mark-contrib {
  background: var(--accent);
}

.mark-limits {
  background: var(--danger);
}

.block-hint {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
  overflow: hidden;
  transition: border-color 0.14s ease, background 0.14s ease;
}

textarea:hover {
  background: var(--panel-3);
}

textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--panel);
}

textarea::placeholder {
  color: var(--text-3);
}

.meta-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}

.meta-col {
  min-width: 0;
}

.notes {
  min-height: 92px;
}

/* ---------- tags ---------- */
.tag-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid transparent;
  min-height: 40px;
  transition: border-color 0.14s ease, background 0.14s ease;
}

.tag-editor:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--panel);
}

.tag-list {
  display: contents;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.5;
}

[data-theme="dark"] .tag {
  color: var(--accent);
}

.tag button {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  font-size: 13px;
  line-height: 1;
  padding: 0 3px;
  border-radius: 50%;
}

.tag button:hover {
  opacity: 1;
}

#tagInput {
  flex: 1 1 80px;
  min-width: 80px;
  border: 0;
  background: transparent;
  padding: 2px 0;
  font-size: 12.5px;
  outline: none;
}

/* ---------- modal ---------- */
.modal {
  border: 0;
  padding: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(9, 12, 16, 0.45);
  backdrop-filter: blur(2px);
}

.modal.wide {
  width: min(1100px, calc(100vw - 32px));
  height: calc(100vh - 64px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-size: 14px;
}

.modal-head-actions {
  display: flex;
  gap: 6px;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 140px);
}

.modal-card {
  display: block;
}

.preview-body {
  padding: 0;
  height: calc(100vh - 128px);
  max-height: none;
  background: var(--panel-3);
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 18px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}

.field-value {
  font-size: 13px;
  font-family: var(--mono);
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  word-break: break-all;
}

.field-hint {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.55;
}

.field input {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel);
  font-size: 13px;
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
}

.field .btn {
  align-self: flex-start;
  margin-top: 4px;
}

/* ---------- 分段选择 ---------- */
.seg {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.seg label {
  position: relative;
  flex: 1 1 140px;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.seg label:hover span {
  background: var(--panel-3);
}

.seg input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.seg input:focus-visible + span {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--panel);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: min(440px, calc(100vw - 32px));
  text-align: center;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  body {
    overflow: auto;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .file-list {
    max-height: 240px;
  }

  .split,
  .meta-block {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 18px 16px 48px;
  }

  .result-head {
    flex-direction: column;
  }

  .result-actions {
    justify-content: flex-start;
  }

  .brand-text p {
    display: none;
  }
}

@media (max-width: 620px) {
  .model-chip {
    display: none;
  }

  .btn.ghost#btnExportAll {
    padding: 0 10px;
  }
}

/* ---------- scrollbars ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-track {
  background: transparent;
}
