:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #f8f9fb;
  --text: #1d232b;
  --muted: #69717d;
  --line: #d9dee6;
  --accent: #2f63d3;
  --accent-strong: #214ba5;
  --nav-bg: #24262d;
  --nav-bg-2: #30333b;
  --nav-text: #f4f6f9;
  --nav-muted: #bcc4d0;
  --blue: #2f63d3;
  --amber: #a45f13;
  --danger: #b42318;
  --mask: #dadada;
  --mask-stroke: #6a707b;
  --selected: #2f63d3;
  --shadow: 0 8px 26px rgba(29, 35, 43, 0.14);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input,
select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfc;
}

input:focus,
select:focus,
.custom-rules:focus {
  outline: 2px solid rgba(47, 99, 211, 0.18);
  border-color: var(--accent);
}

.hidden {
  display: none !important;
}

.file-input-proxy {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.auth-screen,
.pending-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  grid-template-columns: minmax(300px, 1fr) minmax(420px, 520px);
  gap: clamp(72px, 9vw, 180px);
  padding: 48px 64px;
  background: linear-gradient(135deg, #f3f5f9 0%, #eef2fb 48%, #f8f7f2 100%);
}

.pending-screen {
  grid-template-columns: minmax(320px, 480px);
}

.auth-brand,
.pending-panel {
  width: 100%;
}

.auth-brand {
  justify-self: start;
  max-width: 430px;
  margin-left: clamp(92px, 9vw, 180px);
}

.auth-brand .brand-mark,
.pending-panel .brand-mark {
  width: 56px;
  height: 56px;
  margin-bottom: 18px;
  font-size: 24px;
}

.auth-brand h1,
.pending-panel h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.auth-brand p,
.pending-panel p {
  margin: 10px 0 0;
  color: var(--muted);
}

.auth-panel,
.pending-panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.auth-panel {
  justify-self: end;
  width: min(100%, 460px);
  min-height: 360px;
  padding: 30px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.auth-tabs button,
.nav-btn,
.secondary-btn,
.text-btn {
  min-height: 38px;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
}

.auth-tabs button {
  min-height: 44px;
  font-size: 15px;
}

.auth-tabs button.active,
.nav-btn.active {
  color: #fff;
  background: var(--accent);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.auth-form input {
  min-height: 46px;
  padding: 0 14px;
  font-size: 15px;
}

.password-field {
  position: relative;
  display: block;
  width: 100%;
}

.password-field input {
  padding-right: 62px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  min-height: 30px;
  border-radius: 7px;
  color: var(--accent);
  background: #edf3ff;
  font-size: 12px;
  font-weight: 700;
  transform: translateY(-50%);
}

.password-toggle:hover {
  color: #fff;
  background: var(--accent);
}

.auth-form .primary-btn {
  min-height: 48px;
  margin-top: 2px;
  font-size: 16px;
}

.auth-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
  white-space: pre-wrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 304px minmax(0, 1fr) 280px;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.admin-mode {
  grid-template-columns: 240px minmax(0, 1fr);
}

.app-shell.nav-collapsed {
  grid-template-columns: 72px 304px minmax(0, 1fr) 280px;
}

.app-shell.admin-mode.nav-collapsed {
  grid-template-columns: 72px minmax(0, 1fr);
}

.nav-sidebar {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  padding: 24px 18px 18px;
  overflow: hidden;
  color: var(--nav-text);
  background: var(--nav-bg);
}

.nav-brand {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 12px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-title-block {
  min-width: 0;
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.nav-brand h1 {
  margin: 0;
  overflow: hidden;
  color: #fff;
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-brand p {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--nav-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-brand-mark {
  width: 4px;
  height: 38px;
  border-radius: 999px;
  background: linear-gradient(180deg, #6fa0ff 0%, #2f63d3 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.collapse-nav-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: var(--nav-bg);
  background: #fff;
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.nav-sidebar .account-box {
  margin: -4px 0 2px;
  padding: 0 0 16px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  background: transparent;
}

.nav-sidebar .account-box strong {
  color: #fff;
  font-size: 15px;
}

.nav-sidebar .account-box span {
  color: var(--nav-muted);
  line-height: 1.5;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}

.account-link-btn {
  min-height: 24px;
  padding: 0;
  color: #dbe7ff;
  background: transparent;
  font-size: 13px;
}

.account-link-btn:hover,
.account-link-btn.active {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.nav-sidebar .text-btn {
  min-height: 24px;
  padding: 0;
  color: #dbe7ff;
  font-size: 13px;
}

.nav-list {
  align-content: start;
  display: grid;
  gap: 8px;
}

.nav-btn {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--nav-text);
  background: transparent;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-btn.active {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  font-weight: 700;
}

.nav-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #173d8f;
  background: #dbe7ff;
  font-size: 13px;
  font-weight: 800;
}

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell.nav-collapsed .nav-sidebar {
  padding: 18px 12px;
}

.app-shell.nav-collapsed .nav-brand {
  grid-template-columns: 42px;
  grid-auto-rows: auto;
  justify-content: center;
  justify-items: center;
  gap: 10px;
  padding-bottom: 10px;
}

.app-shell.nav-collapsed .nav-title-block,
.app-shell.nav-collapsed .account-box,
.app-shell.nav-collapsed .nav-label {
  display: none;
}

.app-shell.nav-collapsed .collapse-nav-btn {
  position: static;
  width: 42px;
  height: 32px;
  box-shadow: none;
}

.app-shell.nav-collapsed .nav-btn {
  justify-content: center;
  padding: 0;
}

.sidebar,
.inspector {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.app-shell.admin-mode .inspector {
  display: none;
}

.app-shell.admin-mode .sidebar {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.account-box {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  margin-bottom: 12px;
}

.account-box strong {
  font-size: 14px;
}

.account-box span {
  color: var(--muted);
  font-size: 12px;
}

.text-btn {
  justify-self: start;
  min-height: 28px;
  padding: 0 10px;
  color: var(--accent-strong);
  background: transparent;
}

.nav-list {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 0 12px;
}

.drop-zone {
  display: grid;
  gap: 8px;
  place-items: center;
  padding: 22px 14px;
  border: 1px dashed #99b0ab;
  border-radius: 8px;
  background: #f8fbfa;
  margin-bottom: 14px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #e9f5f3;
}

.drop-zone input {
  display: none;
}

.drop-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 24px;
}

.drop-zone small,
.section-head p {
  color: var(--muted);
}

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

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

.panel-head h2,
.panel-block h3 {
  margin: 0;
  font-size: 14px;
}

.panel-block h3 {
  margin-bottom: 12px;
}

.panel-toggle-btn {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  color: var(--accent-strong);
  background: #edf3ff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.panel-toggle-btn:hover {
  background: #dbe7ff;
}

.rules-panel.collapsed {
  padding-bottom: 10px;
}

.rules-panel.collapsed .panel-head {
  margin-bottom: 0;
}

.rule-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.rule-list label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  min-height: 38px;
  padding: 0 11px 0 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.rule-list label:has(input:checked) {
  border-color: rgba(47, 99, 211, 0.38);
  background: #eef4ff;
  color: #214ba5;
}

.rule-list label[data-custom-label="true"] {
  padding-right: 38px;
}

.rule-list span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-list input {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  left: 10px;
  top: 50%;
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  border: 1.5px solid #a8b6b3;
  border-radius: 5px;
  background: #fff;
  transform: translateY(-50%);
}

.rule-list input:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.rule-list input:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.rule-delete-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  min-height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 7px;
  color: var(--danger);
  background: #fbecea;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.rule-delete-btn:hover {
  color: #fff;
  background: var(--danger);
}

.custom-rule-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 8px;
  margin-top: 10px;
}

.exclude-targets {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.exclude-title {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.exclude-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.exclude-list.empty {
  display: none;
}

.exclude-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid #e3c7a4;
  border-radius: 8px;
  color: #6f410e;
  background: #fff8ed;
  font-size: 12px;
  font-weight: 700;
}

.exclude-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exclude-chip strong {
  margin-left: 6px;
  font-size: 13px;
  line-height: 1;
}

.exclude-rule-wrap {
  margin-top: 8px;
}

.custom-rules {
  min-height: 38px;
  height: 38px;
  resize: none;
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 13px;
}

.add-rule-btn {
  min-height: 38px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.add-rule-btn:hover,
.primary-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.toggle-row {
  display: flex;
  gap: 12px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.toggle-row input {
  width: 15px;
  min-height: 15px;
}

.ocr-source {
  margin: 10px 0 12px;
}

.ocr-source-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ocr-provider-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.ocr-provider-row.is-muted {
  opacity: 0.64;
}

.ocr-provider-btn {
  min-height: 32px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.ocr-provider-btn.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(47, 99, 211, 0.2);
}

.primary-btn,
.ghost-btn,
.tool-btn,
.mini-btn,
.secondary-btn {
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
}

.primary-btn {
  width: 100%;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.secondary-btn {
  color: #fff;
  background: var(--blue);
  white-space: nowrap;
}

.ghost-btn {
  width: 100%;
  margin: 10px 0;
  color: var(--text);
  background: #edf1f0;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.tool-btn {
  color: var(--text);
  background: #edf1f0;
}

.tool-btn.active {
  color: #fff;
  background: var(--accent);
}

.mini-btn {
  min-height: 30px;
  color: #fff;
  background: var(--danger);
}

.mini-btn.neutral {
  background: var(--accent);
}

.inspector-actions {
  display: flex;
  gap: 7px;
  align-items: center;
}

.status-box {
  padding: 12px;
  border-radius: 8px;
  background: #eef2f1;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.status-text {
  white-space: pre-wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 24, 32, 0.48);
}

.suggestion-dialog {
  width: min(520px, calc(100vw - 36px));
  max-height: min(620px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.confirm-dialog {
  width: min(420px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.confirm-head {
  padding: 18px 18px 10px;
}

.confirm-head h2 {
  margin: 0;
  font-size: 18px;
}

.confirm-body {
  padding: 0 18px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.confirm-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.confirm-foot .ghost-btn,
.confirm-foot .primary-btn {
  width: auto;
  min-width: 82px;
  margin: 0;
}

.primary-btn.danger {
  background: var(--danger);
}

.suggestion-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.suggestion-head h2 {
  margin: 0;
  font-size: 20px;
}

.suggestion-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.suggestion-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 14px 18px;
}

.suggestion-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(47, 99, 211, 0.28);
  border-radius: 8px;
  background: #f8fbff;
}

.suggestion-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 18px;
}

.suggestion-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.suggestion-item button {
  min-height: 36px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.suggestion-foot {
  display: flex;
  justify-content: flex-end;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
}

.suggestion-foot .ghost-btn {
  width: auto;
  min-width: 96px;
  margin: 0;
}

.pdf-compose-dialog {
  width: min(var(--pdf-compose-dialog-width, 980px), calc(100vw - 36px));
  height: min(780px, calc(100vh - 36px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pdf-compose-head,
.pdf-compose-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.pdf-compose-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.pdf-compose-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.pdf-compose-head p,
.pdf-compose-foot span,
.compose-name-field span,
.pdf-compose-preview-meta {
  color: var(--muted);
  font-size: 13px;
}

.pdf-compose-head p {
  margin: 4px 0 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
  font-weight: 800;
}

.pdf-compose-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
}

.pdf-compose-list-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--surface-3);
}

.compose-name-field {
  display: grid;
  gap: 6px;
}

.compose-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.compose-actions .ghost-btn,
.pdf-compose-foot .ghost-btn,
.pdf-compose-foot .primary-btn {
  width: auto;
  margin: 0;
}

.pdf-compose-page-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.pdf-compose-page {
  display: grid;
  grid-template-columns: 24px 18px 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 78px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.pdf-compose-page.active {
  border-color: var(--accent);
  background: #eef4ff;
}

.pdf-compose-page.excluded {
  opacity: 0.58;
}

.pdf-compose-page.dragging {
  outline: 2px solid rgba(47, 99, 211, 0.28);
}

.pdf-compose-drag {
  width: 24px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-2);
  cursor: grab;
  font-size: 18px;
  line-height: 1;
}

.pdf-compose-page input {
  width: 16px;
  min-height: 16px;
}

.pdf-compose-thumb {
  width: 58px;
  height: 62px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.pdf-compose-page-text {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.pdf-compose-page-text strong,
.pdf-compose-page-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-compose-page-text strong {
  font-size: 13px;
}

.pdf-compose-page-text span {
  color: var(--muted);
  font-size: 12px;
}

.pdf-compose-move {
  display: grid;
  grid-template-columns: 28px 28px;
  gap: 5px;
}

.pdf-compose-move button {
  min-height: 28px;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
}

.pdf-compose-preview-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  padding: 0;
  background: #eef1f5;
}

.pdf-compose-preview-meta {
  padding: 12px 0 8px;
}

.pdf-compose-preview-frame {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.pdf-compose-preview-frame img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  filter: drop-shadow(0 8px 26px rgba(29, 35, 43, 0.14));
}

.pdf-compose-preview-empty {
  color: var(--muted);
  font-size: 13px;
}

.pdf-compose-preview-frame img[src=""] {
  display: none;
}

.pdf-compose-foot > div {
  display: flex;
  gap: 8px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 58px 1fr;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.topbar strong {
  display: block;
  font-size: 15px;
}

.topbar span {
  color: var(--muted);
  font-size: 12px;
}

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

.topbar-icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #edf3ff;
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}

.topbar-icon-btn:hover:not(:disabled) {
  border-color: rgba(47, 99, 211, 0.38);
  background: #dbe7ff;
}

.topbar-add-btn {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.topbar-add-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.counter {
  min-width: 48px;
  text-align: center;
}

.counter span {
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
}

.counter small {
  color: var(--muted);
  display: block;
  margin-top: -2px;
}

.view-panel {
  display: none;
  min-height: 0;
  overflow: auto;
}

.view-panel.active {
  display: block;
}

#workbenchView.active {
  display: grid;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 24px;
}

.empty-card {
  display: grid;
  gap: 8px;
  padding: 26px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.empty-card:hover,
.empty-state.dragging .empty-card {
  border-color: rgba(47, 99, 211, 0.42);
  background: #f8fbff;
  box-shadow: 0 10px 28px rgba(47, 99, 211, 0.12);
}

.empty-card span {
  color: var(--muted);
  font-size: 13px;
}

.document-scroll {
  display: none;
  overflow: auto;
  padding: 22px;
}

.document-scroll.open {
  display: block;
}

.pages {
  display: grid;
  gap: 22px;
  justify-items: center;
  transform-origin: top center;
}

.page-shell {
  position: relative;
  width: min(100%, var(--page-width));
  max-width: var(--page-width);
  background: #fff;
  box-shadow: var(--shadow);
}

.page-image {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.mask-rect {
  fill: var(--mask);
  fill-opacity: 1;
  stroke: var(--mask-stroke);
  stroke-width: 1.4;
  cursor: move;
}

.mask-rect.selected {
  stroke: var(--selected);
  stroke-width: 2.2;
}

.draft-rect {
  fill: rgba(47, 99, 211, 0.12);
  stroke: var(--selected);
  stroke-width: 1.8;
  stroke-dasharray: 7 5;
}

.resize-handle {
  fill: #fff;
  stroke: var(--selected);
  stroke-width: 2;
}

.mask-toolbar {
  position: absolute;
  display: none;
  gap: 6px;
  transform: translate(-50%, calc(-100% - 8px));
  z-index: 5;
}

.mask-toolbar.show {
  display: flex;
}

.mask-toolbar button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  color: #fff;
  background: var(--danger);
  box-shadow: 0 6px 18px rgba(24, 34, 32, 0.18);
}

.page-label {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 4;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(24, 34, 32, 0.78);
  color: #fff;
  font-size: 12px;
}

.mask-list,
.data-list {
  display: grid;
  gap: 8px;
}

.mask-item,
.data-item {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  text-align: left;
}

.mask-item.selected,
.data-item.selected {
  border-color: var(--accent);
  background: #eef4ff;
}

.mask-item strong,
.data-item strong {
  font-size: 13px;
}

.mask-item span,
.data-item span,
.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.history-item {
  grid-template-columns: minmax(280px, 1.3fr) minmax(300px, 0.9fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 92px;
  padding: 12px 14px;
}

.history-info {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.history-title-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-title-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-status {
  flex: 0 0 auto;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  align-items: center;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.history-metrics span {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 0 16px;
  color: var(--text);
}

.history-metrics span + span {
  border-left: 1px solid var(--line);
}

.history-metrics strong {
  font-size: 18px;
  line-height: 1.1;
  color: var(--accent-strong);
}

.history-metrics small {
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.admin-content {
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0;
}

.section-head p {
  margin: 4px 0 0;
  font-size: 13px;
}

.toolbar-row,
.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-row {
  margin-bottom: 12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.profile-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 14px;
  max-width: 980px;
}

.panel-block {
  margin: 0;
  min-width: 0;
}

.panel-block.wide {
  grid-column: 1 / -1;
}

.compact .data-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.data-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.data-actions button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
}

.data-actions button.danger {
  background: var(--danger);
}

.data-actions button.secondary {
  background: var(--blue);
}

.copy-code-btn {
  min-height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  color: var(--accent-strong);
  background: #edf3ff;
  font-size: 12px;
  vertical-align: baseline;
}

.copy-code-btn:hover {
  background: #dbe7ff;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--accent-strong);
  background: #edf3ff;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.pending {
  color: var(--amber);
  background: #fbf1dc;
}

.status-pill.disabled,
.status-pill.rejected {
  color: var(--danger);
  background: #fbecea;
}

.profile-fields,
.profile-form {
  display: grid;
  gap: 10px;
}

.profile-field {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
}

.profile-field span,
.profile-form label {
  color: var(--muted);
  font-size: 13px;
}

.profile-field strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-form label {
  display: grid;
  gap: 6px;
}

.profile-form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
}

.profile-form-actions .primary-btn {
  width: auto;
  min-width: 110px;
}

.profile-form-actions span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: var(--surface-3);
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

td select {
  min-width: 120px;
}

.cost-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric strong {
  font-size: 22px;
  letter-spacing: 0;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 220px 286px minmax(0, 1fr);
  }

  .app-shell.nav-collapsed {
    grid-template-columns: 72px 286px minmax(0, 1fr);
  }

  .app-shell.admin-mode {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .app-shell.admin-mode.nav-collapsed {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .inspector {
    display: none;
  }

  .admin-grid,
  .profile-grid,
  .cost-grid {
    grid-template-columns: 1fr;
  }

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

  .history-metrics {
    grid-column: 1 / -1;
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding-top: 10px;
  }
}

@media (max-width: 860px) {
  .auth-screen {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 24px;
  }

  .auth-brand {
    margin-left: 0;
  }

  .auth-panel {
    justify-self: stretch;
    width: 100%;
    min-height: 0;
    padding: 24px;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .pdf-compose-dialog {
    height: calc(100vh - 16px);
    min-height: 0;
  }

  .pdf-compose-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 44vh) minmax(0, 1fr);
  }

  .pdf-compose-list-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .pdf-compose-page {
    grid-template-columns: 24px 18px 52px minmax(0, 1fr);
  }

  .pdf-compose-move {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .pdf-compose-head,
  .pdf-compose-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .pdf-compose-foot > div {
    width: 100%;
  }

  .pdf-compose-foot button {
    flex: 1;
  }

  .app-shell,
  .app-shell.admin-mode,
  .app-shell.nav-collapsed,
  .app-shell.admin-mode.nav-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .nav-sidebar {
    grid-template-rows: auto auto;
    gap: 10px;
    max-height: 220px;
    padding: 12px;
    overflow: auto;
  }

  .nav-brand {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(84px, 1fr));
    overflow-x: auto;
  }

  .app-shell.nav-collapsed .nav-title-block,
  .app-shell.nav-collapsed .account-box {
    display: grid;
  }

  .app-shell.nav-collapsed .nav-label {
    display: block;
  }

  .app-shell.nav-collapsed .nav-sidebar {
    padding: 12px;
  }

  .app-shell.nav-collapsed .collapse-nav-btn {
    position: static;
    transform: none;
    box-shadow: none;
  }

  .sidebar {
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    height: 52vh;
  }

  .document-scroll,
  .admin-content {
    padding: 12px;
  }

  .section-head,
  .form-row,
  .toolbar-row,
  .profile-form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-form-actions .primary-btn {
    width: 100%;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

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

  .history-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .history-metrics span {
    padding: 0 10px;
  }
}
